]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd
authorAsias He <asias.hejun@gmail.com>
Thu, 22 Dec 2011 02:10:43 +0000 (10:10 +0800)
committerPekka Enberg <penberg@kernel.org>
Thu, 22 Dec 2011 14:06:52 +0000 (16:06 +0200)
This can be used to get vm status information:

vm is running or paused.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-run.c
tools/kvm/include/kvm/kvm-ipc.h
tools/kvm/include/kvm/kvm.h
tools/kvm/powerpc/include/kvm/kvm-arch.h
tools/kvm/x86/include/kvm/kvm-arch.h

index a94fdbcebb7c040247f02c26070b3758f04753e4..80806a1ae0735bf8565c1d84c8eadf024828b346 100644 (file)
@@ -510,11 +510,13 @@ static void handle_pause(int fd, u32 type, u32 len, u8 *msg)
        if (WARN_ON(len))
                return;
 
-       if (type == KVM_IPC_RESUME && is_paused)
+       if (type == KVM_IPC_RESUME && is_paused) {
+               kvm->vm_state = KVM_VMSTATE_RUNNING;
                kvm__continue();
-       else if (type == KVM_IPC_PAUSE && !is_paused)
+       } else if (type == KVM_IPC_PAUSE && !is_paused) {
+               kvm->vm_state = KVM_VMSTATE_PAUSED;
                kvm__pause();
-       else {
+       else {
                WARN_ON(1);
                return;
        }
@@ -523,6 +525,17 @@ static void handle_pause(int fd, u32 type, u32 len, u8 *msg)
        pr_info("Guest %s\n", is_paused ? "paused" : "resumed");
 }
 
+static void handle_vmstate(int fd, u32 type, u32 len, u8 *msg)
+{
+       int r = 0;
+
+       if (type == KVM_IPC_VMSTATE)
+               r = write(fd, &kvm->vm_state, sizeof(kvm->vm_state));
+
+       if (r < 0)
+               pr_warning("Failed sending VMSTATE");
+}
+
 static void handle_debug(int fd, u32 type, u32 len, u8 *msg)
 {
        int i;
@@ -877,6 +890,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
        kvm_ipc__register_handler(KVM_IPC_PAUSE, handle_pause);
        kvm_ipc__register_handler(KVM_IPC_RESUME, handle_pause);
        kvm_ipc__register_handler(KVM_IPC_STOP, handle_stop);
+       kvm_ipc__register_handler(KVM_IPC_VMSTATE, handle_vmstate);
 
        nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
 
index 5916c40c21b86e58e0621d2943f7374ae4b7e093..aefffa4dd444c6fec46d8b8e42b3ff0c56e20287 100644 (file)
@@ -11,6 +11,7 @@ enum {
        KVM_IPC_RESUME  = 5,
        KVM_IPC_STOP    = 6,
        KVM_IPC_PID     = 7,
+       KVM_IPC_VMSTATE = 8,
 };
 
 int kvm_ipc__register_handler(u32 type, void (*cb)(int fd, u32 type, u32 len, u8 *msg));
index eabaf07e6df6cd0ad2a9c0e020bf8457e7c8adb4..d8ed73139256f5f48e3eaaae1354b25e4e9a4b01 100644 (file)
        .name = #ext,                   \
        .code = ext
 
+enum {
+       KVM_VMSTATE_RUNNING,
+       KVM_VMSTATE_PAUSED,
+};
+
 struct kvm_ext {
        const char *name;
        int code;
index 10aa2d9c2f92a9b0cb7a3aca045aba6308917f98..c4b493c1d4f14f7f8f0d699d980f83c21d992535 100644 (file)
@@ -65,6 +65,7 @@ struct kvm {
        unsigned long           initrd_gra;
        unsigned long           initrd_size;
        const char              *name;
+       int                     vm_state;
 };
 
 #endif /* KVM__KVM_ARCH_H */
index 1ce3d319704d5847df1d48799aeddfe59be8f675..244d36c5f75f44cbae8d4a29cad4fa53bdf130ea 100644 (file)
@@ -48,6 +48,8 @@ struct kvm {
        int                     nr_disks;
 
        const char              *name;
+
+       int                     vm_state;
 };
 
 static inline void *guest_flat_to_host(struct kvm *kvm, unsigned long offset); /* In kvm.h */