20 Commits

Author SHA1 Message Date
Michael Ellerman 0cf9e1f442 kvm tools: Return error status in lkvm list
Currently list always returns 0, even if there was an error. Instead
have it accumulate any errors and return that.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:54 +01:00
Lai Jiangshan 49dca54d8a kvm tools: Don't remove any file which is not created by itself
It is user's or other program's reponsibility, not the current program.
Just try best to let the user know what happen.
Also make print_guest() keep the same behavior as do_debug()
do_pause() ...etc. when it failed.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Lai Jiangshan 08ffc82ad5 kvm tools: Check the state before pause/resume
Let the user know what happened

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Lai Jiangshan 0a56c4242d kvm tools: Remove unused code for print_guest()
comm is unused ==> fscanf() is unused ==> fd is unused
==> proc_name is unused.

so all this code can be removed.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Asias He 0579e1d7d9 kvm tools: Use kvm_ipc__send to send IPC msg
No need to send IPC msg using bare write() any more.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Asias He 5bf27f057f kvm tools: Respect paused status in ./lkvm list
'./lkvm list' does not give the correct vm status if the vm is paused
currently.

This patch fixes this by using KVM_IPC_VMSTATE IPC cmd to query the vm
status.

Suppose the guest is paused by ./lkvm pause:

Before:

asias@hj$ ./lkvm list
   PID NAME                 STATE
------------------------------------
 3036 guest-3036           running
      default              shut off

After:

asias@hj$ ./lkvm list
   PID NAME                 STATE
------------------------------------
 3036 guest-3036           paused
      default              shut off

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Wanlong Gao 8d2ff5da21 kvm tools: change the binary name from kvm to lkvm for commands' usage
Commands' usage : Change the binary name from *kvm* to *lkvm*,
since commit ad3efb18 has done it.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Lai Jiangshan 3cbe80e8a1 kvm-tools: fix wrong "./lkvm list -i"
because the program name is changed, "./lkvm list -i" can't work now.
This fix just remove the test:
1) this test is not reliable.
2) the target process can respond for "get_pid()", it must be
   kvm-tool. (at least it is more reliable)

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Lai Jiangshan da08dcdb09 kvm-tools: remove unneed sprintf("%s")
it makes no sense.

Acked-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:50 +01:00
Osier Yang 78c684b105 kvm tools: Beautify kvm list output
With the patch, output of "kvm list" will be:

% ./kvm list
   PID NAME                 STATE
------------------------------------
 5270 test                 running
      test                 shut off
      default              shut off

"not running" is changed into "shut off", as it might
be other states which are "not running" in future? such
as "paused".

Signed-off-by: Osier Yang <jyang@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Pekka Enberg 84e1040433 kvm tools: Improve "kvm list" default output
This patch changes 'kvm list' default output to look as follows:

  [penberg@tux kvm]$ ./kvm list
    PID GUEST
   8156 guest-8156
        default (not running)
        test-box (not running)

Acked-by: Cyrill Gorcunov <gorcunov@gmail.com>
Acked-by: Sasha Levin <levinsasha928@gmail.com>
Cc: Asias He <asias.hejun@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 4b1addaeed kvm tools: Switch to using UNIX sockets instead of signals
This patch changes the IPC method to use UNIX sockets instead of
signals.

This allows for more flexibility in moving data between processes, for example
it would allow avoid printing output in the terminal of the guest.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Pekka Enberg 9667701c38 kvm tools: Use kvm__get_dir() helper function
This patch adds a kvm__get_dir() helper function that replaces open-coded uses
of HOME_DIR and KVM_PID_FILE_PATH.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 076e946ec2 kvm tools: Add option to list rootfs in 'kvm list'
Previously we would only list running instances, now that we create
rootfs instances it's appropriate to add a method to list them as
well.

Suggested-by: Ingo Molnar <mingo@elte.hu>
Acked-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:48 +01:00
Sasha Levin 0725673ad3 kvm tools: Connect existing command helpers to 'kvm help'
This patch connects usage helpers to 'kvm help' callbacks, allowing
to see help about a command by doing 'kvm help [command]'.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:47 +01:00
Pekka Enberg 8a09361d6a kvm tools: Improve 'kvm list' output
This patch improves 'kvm list' output to look more like 'ps':

  $ ./kvm list
    PID GUEST
   2820 guest-2820

Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:47 +01:00
Liming Wang 886af5f228 kvm tools: convert callback to int and deal with the return value
callback function maybe fail, so we should deal with the return value.

Signed-off-by: Liming Wang <walimisdev@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Sasha Levin ebc49f06b0 kvm tools: Change method of retrieving process name
This patch changes './kvm list' to retrieve process name from
'/proc/<pid>/stat' instead of '/proc/<pid>/comm' as it appears the latter
does not exist by default on several systems.

Reported-by: Pradeep Kumar Surisetty <psuriset@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Sasha Levin 1a0ef25162 kvm tools: Fix leaked descriptors
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00
Sasha Levin 2a24f96d64 kvm tools: Rename command source files
Rename kvm-[command] into builtin-[command] to prevent
clashes with non-command files such as kvm-cpu.h

Suggested-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
2015-06-01 16:39:46 +01:00