]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Check the state before pause/resume
authorLai Jiangshan <laijs@cn.fujitsu.com>
Tue, 27 Dec 2011 07:36:37 +0000 (15:36 +0800)
committerPekka Enberg <penberg@kernel.org>
Tue, 3 Jan 2012 17:07:01 +0000 (19:07 +0200)
Let the user know what happened

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-list.c
tools/kvm/builtin-pause.c
tools/kvm/builtin-resume.c
tools/kvm/include/kvm/builtin-list.h

index dbd6d98f329056c3445403376e488ca203fa7d2d..885543f440cec94b69fbeea2858a7390a9223b5a 100644 (file)
@@ -51,7 +51,7 @@ static pid_t get_pid(int sock)
        return pid;
 }
 
-static int get_vmstate(int sock)
+int get_vmstate(int sock)
 {
        int vmstate;
        int r;
index 436963f3e87b2f1535aa7e01dc2697609b40bf6a..c08595a304d1fce46f97866bb8829e4ad69e6b6b 100644 (file)
@@ -1,6 +1,7 @@
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
 #include <kvm/builtin-pause.h>
+#include <kvm/builtin-list.h>
 #include <kvm/kvm.h>
 #include <kvm/parse-options.h>
 #include <kvm/kvm-ipc.h>
@@ -42,6 +43,15 @@ void kvm_pause_help(void)
 static int do_pause(const char *name, int sock)
 {
        int r;
+       int vmstate;
+
+       vmstate = get_vmstate(sock);
+       if (vmstate < 0)
+               return vmstate;
+       if (vmstate == KVM_VMSTATE_PAUSED) {
+               printf("Guest %s is already paused.\n", name);
+               return 0;
+       }
 
        r = kvm_ipc__send(sock, KVM_IPC_PAUSE);
        if (r)
index 033a05b7d0a38cd68bcd5274a980d3fce82ee5dc..0e954b405ee8137ec65384aca732cf54b8afa60b 100644 (file)
@@ -1,6 +1,7 @@
 #include <kvm/util.h>
 #include <kvm/kvm-cmd.h>
 #include <kvm/builtin-resume.h>
+#include <kvm/builtin-list.h>
 #include <kvm/kvm.h>
 #include <kvm/parse-options.h>
 #include <kvm/kvm-ipc.h>
@@ -42,6 +43,15 @@ void kvm_resume_help(void)
 static int do_resume(const char *name, int sock)
 {
        int r;
+       int vmstate;
+
+       vmstate = get_vmstate(sock);
+       if (vmstate < 0)
+               return vmstate;
+       if (vmstate == KVM_VMSTATE_RUNNING) {
+               printf("Guest %s is still running.\n", name);
+               return 0;
+       }
 
        r = kvm_ipc__send(sock, KVM_IPC_RESUME);
        if (r)
index 7b697f69ee243b4a9ddcfacf478d1841514eb7ad..47029caa25e6457b25ff814e5a8cbff45fad804c 100644 (file)
@@ -5,5 +5,6 @@
 
 int kvm_cmd_list(int argc, const char **argv, const char *prefix);
 void kvm_list_help(void) NORETURN;
+int get_vmstate(int sock);
 
 #endif