[PATCH 2/6] kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd

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

 



This can be used to get vm status information:

vm is running or pasued.

Signed-off-by: Asias He <asias.hejun@xxxxxxxxx>
---
 tools/kvm/builtin-run.c                  |   20 +++++++++++++++++---
 tools/kvm/include/kvm/kvm-ipc.h          |    1 +
 tools/kvm/include/kvm/kvm.h              |    5 +++++
 tools/kvm/powerpc/include/kvm/kvm-arch.h |    1 +
 tools/kvm/x86/include/kvm/kvm-arch.h     |    2 ++
 5 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index a94fdbc..80806a1 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -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);
 
diff --git a/tools/kvm/include/kvm/kvm-ipc.h b/tools/kvm/include/kvm/kvm-ipc.h
index 5916c40..aefffa4 100644
--- a/tools/kvm/include/kvm/kvm-ipc.h
+++ b/tools/kvm/include/kvm/kvm-ipc.h
@@ -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));
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index a3ea1c9..2e28586 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -21,6 +21,11 @@
 	.name = #ext,			\
 	.code = ext
 
+enum {
+	KVM_VMSTATE_RUNNING,
+	KVM_VMSTATE_PAUSED,
+};
+
 struct kvm_ext {
 	const char *name;
 	int code;
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index 10aa2d9..c4b493c 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -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 */
diff --git a/tools/kvm/x86/include/kvm/kvm-arch.h b/tools/kvm/x86/include/kvm/kvm-arch.h
index 1ce3d31..244d36c 100644
--- a/tools/kvm/x86/include/kvm/kvm-arch.h
+++ b/tools/kvm/x86/include/kvm/kvm-arch.h
@@ -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 */
-- 
1.7.7.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux