[tip:tools/kvm] kvm tools: Respect paused status in ./lkvm list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  ca5d93d681f3a0d6cef1194186f6a716461fff9c
Gitweb:     http://git.kernel.org/tip/ca5d93d681f3a0d6cef1194186f6a716461fff9c
Author:     Asias He <asias.hejun@xxxxxxxxx>
AuthorDate: Thu, 22 Dec 2011 10:10:44 +0800
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Thu, 22 Dec 2011 16:06:52 +0200

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@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/builtin-list.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/builtin-list.c b/tools/kvm/builtin-list.c
index ec1c067..e74b636 100644
--- a/tools/kvm/builtin-list.c
+++ b/tools/kvm/builtin-list.c
@@ -16,6 +16,11 @@ struct pid_cmd {
 	u32 len;
 };
 
+struct vmstate_cmd {
+	u32 type;
+	u32 len;
+};
+
 static bool run;
 static bool rootfs;
 
@@ -32,6 +37,7 @@ static const struct option list_options[] = {
 };
 
 #define KVM_INSTANCE_RUNNING	"running"
+#define KVM_INSTANCE_PAUSED	"paused"
 #define KVM_INSTANCE_SHUTOFF	"shut off"
 
 void kvm_list_help(void)
@@ -56,12 +62,34 @@ static pid_t get_pid(int sock)
 	return pid;
 }
 
+static int get_vmstate(int sock)
+{
+	struct vmstate_cmd cmd = {KVM_IPC_VMSTATE, 0};
+	int r;
+	int vmstate;
+
+	r = write(sock, &cmd, sizeof(cmd));
+	if (r < 0)
+		return r;
+
+	r = read(sock, &vmstate, sizeof(vmstate));
+	if (r < 0)
+		return r;
+
+	return vmstate;
+
+}
+
 static int print_guest(const char *name, int sock)
 {
 	char proc_name[PATH_MAX];
 	char *comm = NULL;
 	FILE *fd;
-	pid_t pid = get_pid(sock);
+	pid_t pid;
+	int vmstate;
+
+	pid = get_pid(sock);
+	vmstate = get_vmstate(sock);
 
 	sprintf(proc_name, "/proc/%d/stat", pid);
 	fd = fopen(proc_name, "r");
@@ -70,7 +98,10 @@ static int print_guest(const char *name, int sock)
 	if (fscanf(fd, "%*u (%as)", &comm) == 0)
 		goto cleanup;
 
-	printf("%5d %-20s %s\n", pid, name, KVM_INSTANCE_RUNNING);
+	if (vmstate == KVM_VMSTATE_PAUSED)
+		printf("%5d %-20s %s\n", pid, name, KVM_INSTANCE_PAUSED);
+	else
+		printf("%5d %-20s %s\n", pid, name, KVM_INSTANCE_RUNNING);
 
 	free(comm);
 
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux