kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Asias He <asias.hejun@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Sasha Levin <levinsasha928@gmail.com>,
	Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
	kvm@vger.kernel.org, Asias He <asias.hejun@gmail.com>
Subject: [PATCH 2/6] kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd
Date: Thu, 22 Dec 2011 10:10:43 +0800	[thread overview]
Message-ID: <1324519847-19897-2-git-send-email-asias.hejun@gmail.com> (raw)
In-Reply-To: <1324519847-19897-1-git-send-email-asias.hejun@gmail.com>

This can be used to get vm status information:

vm is running or pasued.

Signed-off-by: Asias He <asias.hejun@gmail.com>
---
 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


  reply	other threads:[~2011-12-22  2:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-22  2:10 [PATCH 1/6] kvm tools: Handle multiple IPC cmd at a time Asias He
2011-12-22  2:10 ` Asias He [this message]
2011-12-22  2:10 ` [PATCH 3/6] kvm tools: Respect paused status in ./lkvm list Asias He
2011-12-22  2:10 ` [PATCH 4/6] kvm tools: Improve 'lkvm {pause,resume}'s output Asias He
2011-12-22  2:10 ` [PATCH 5/6] kvm tools: Remove resume pause noise Asias He
2011-12-22  2:10 ` [PATCH 6/6] kvm tools: Use kvm_ipc__send to send IPC msg Asias He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324519847-19897-2-git-send-email-asias.hejun@gmail.com \
    --to=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).