* [PATCH 1/6] kvm tools: Handle multiple IPC cmd at a time
@ 2011-12-22 2:10 Asias He
2011-12-22 2:10 ` [PATCH 2/6] kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd Asias He
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Asias He @ 2011-12-22 2:10 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Sasha Levin, Cyrill Gorcunov, Ingo Molnar, kvm, Asias He
This is useful when client submiting multiple IPC cmd in one socket
connection.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/kvm-ipc.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/tools/kvm/kvm-ipc.c b/tools/kvm/kvm-ipc.c
index 2036b91..dbe2363 100644
--- a/tools/kvm/kvm-ipc.c
+++ b/tools/kvm/kvm-ipc.c
@@ -102,7 +102,7 @@ static void kvm_ipc__close_conn(int fd)
close(fd);
}
-static void kvm_ipc__receive(int fd)
+static int kvm_ipc__receive(int fd)
{
struct kvm_ipc_head head;
u8 *msg = NULL;
@@ -122,8 +122,11 @@ static void kvm_ipc__receive(int fd)
kvm_ipc__handle(fd, head.type, head.len, msg);
+ return 0;
+
done:
free(msg);
+ return -1;
}
static void *kvm_ipc__thread(void *param)
@@ -140,10 +143,16 @@ static void *kvm_ipc__thread(void *param)
if (fd == stop_fd && event.events & EPOLLIN) {
break;
} else if (fd == server_fd) {
- int client;
+ int client, r;
client = kvm_ipc__new_conn(fd);
- kvm_ipc__receive(client);
+ /*
+ * Handle multiple IPC cmd at a time
+ */
+ do {
+ r = kvm_ipc__receive(client);
+ } while (r == 0);
+
} else if (event.events && (EPOLLERR | EPOLLRDHUP | EPOLLHUP)) {
kvm_ipc__close_conn(fd);
} else {
--
1.7.7.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/6] kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd
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
2011-12-22 2:10 ` [PATCH 3/6] kvm tools: Respect paused status in ./lkvm list Asias He
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Asias He @ 2011-12-22 2:10 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Sasha Levin, Cyrill Gorcunov, Ingo Molnar, kvm, Asias He
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/6] kvm tools: Respect paused status in ./lkvm list
2011-12-22 2:10 [PATCH 1/6] kvm tools: Handle multiple IPC cmd at a time Asias He
2011-12-22 2:10 ` [PATCH 2/6] kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd Asias He
@ 2011-12-22 2:10 ` Asias He
2011-12-22 2:10 ` [PATCH 4/6] kvm tools: Improve 'lkvm {pause,resume}'s output Asias He
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Asias He @ 2011-12-22 2:10 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Sasha Levin, Cyrill Gorcunov, Ingo Molnar, kvm, Asias He
'./lkvm list' does not give the correct vm status if the vm is pasued
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@gmail.com>
---
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);
--
1.7.7.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/6] kvm tools: Improve 'lkvm {pause,resume}'s output
2011-12-22 2:10 [PATCH 1/6] kvm tools: Handle multiple IPC cmd at a time Asias He
2011-12-22 2:10 ` [PATCH 2/6] kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd Asias He
2011-12-22 2:10 ` [PATCH 3/6] kvm tools: Respect paused status in ./lkvm list Asias He
@ 2011-12-22 2:10 ` 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
4 siblings, 0 replies; 6+ messages in thread
From: Asias He @ 2011-12-22 2:10 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Sasha Levin, Cyrill Gorcunov, Ingo Molnar, kvm, Asias He
lkvm {pause,resume} do not give any feedback to user who uses these
commands in the console where the command run.
This patch makes the command output in the command console instead of
guest console.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/builtin-pause.c | 10 +++++++++-
tools/kvm/builtin-resume.c | 10 +++++++++-
tools/kvm/builtin-run.c | 1 -
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c
index ee5a5b8..436963f 100644
--- a/tools/kvm/builtin-pause.c
+++ b/tools/kvm/builtin-pause.c
@@ -41,7 +41,15 @@ void kvm_pause_help(void)
static int do_pause(const char *name, int sock)
{
- return kvm_ipc__send(sock, KVM_IPC_PAUSE);
+ int r;
+
+ r = kvm_ipc__send(sock, KVM_IPC_PAUSE);
+ if (r)
+ return r;
+
+ printf("Guest %s paused\n", name);
+
+ return 0;
}
int kvm_cmd_pause(int argc, const char **argv, const char *prefix)
diff --git a/tools/kvm/builtin-resume.c b/tools/kvm/builtin-resume.c
index 9c47183..033a05b 100644
--- a/tools/kvm/builtin-resume.c
+++ b/tools/kvm/builtin-resume.c
@@ -41,7 +41,15 @@ void kvm_resume_help(void)
static int do_resume(const char *name, int sock)
{
- return kvm_ipc__send(sock, KVM_IPC_RESUME);
+ int r;
+
+ r = kvm_ipc__send(sock, KVM_IPC_RESUME);
+ if (r)
+ return r;
+
+ printf("Guest %s resumed\n", name);
+
+ return 0;
}
int kvm_cmd_resume(int argc, const char **argv, const char *prefix)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 80806a1..bf39cfb 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -522,7 +522,6 @@ static void handle_pause(int fd, u32 type, u32 len, u8 *msg)
}
is_paused = !is_paused;
- pr_info("Guest %s\n", is_paused ? "paused" : "resumed");
}
static void handle_vmstate(int fd, u32 type, u32 len, u8 *msg)
--
1.7.7.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/6] kvm tools: Remove resume pause noise.
2011-12-22 2:10 [PATCH 1/6] kvm tools: Handle multiple IPC cmd at a time Asias He
` (2 preceding siblings ...)
2011-12-22 2:10 ` [PATCH 4/6] kvm tools: Improve 'lkvm {pause,resume}'s output Asias He
@ 2011-12-22 2:10 ` Asias He
2011-12-22 2:10 ` [PATCH 6/6] kvm tools: Use kvm_ipc__send to send IPC msg Asias He
4 siblings, 0 replies; 6+ messages in thread
From: Asias He @ 2011-12-22 2:10 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Sasha Levin, Cyrill Gorcunov, Ingo Molnar, kvm, Asias He
Remove this annoying message if user resumes or pauses a guest whcih
is already resumed or paused.
Warning: (builtin-run.c) handle_pause:520: failed condition: 1
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/builtin-run.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index bf39cfb..4691e1b 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -517,7 +517,6 @@ static void handle_pause(int fd, u32 type, u32 len, u8 *msg)
kvm->vm_state = KVM_VMSTATE_PAUSED;
kvm__pause();
} else {
- WARN_ON(1);
return;
}
--
1.7.7.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 6/6] kvm tools: Use kvm_ipc__send to send IPC msg
2011-12-22 2:10 [PATCH 1/6] kvm tools: Handle multiple IPC cmd at a time Asias He
` (3 preceding siblings ...)
2011-12-22 2:10 ` [PATCH 5/6] kvm tools: Remove resume pause noise Asias He
@ 2011-12-22 2:10 ` Asias He
4 siblings, 0 replies; 6+ messages in thread
From: Asias He @ 2011-12-22 2:10 UTC (permalink / raw)
To: Pekka Enberg; +Cc: Sasha Levin, Cyrill Gorcunov, Ingo Molnar, kvm, Asias He
No need to send IPC msg using bare write() any more.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/builtin-list.c | 20 ++++----------------
1 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/tools/kvm/builtin-list.c b/tools/kvm/builtin-list.c
index e74b636..eb0ac6c 100644
--- a/tools/kvm/builtin-list.c
+++ b/tools/kvm/builtin-list.c
@@ -11,16 +11,6 @@
#include <signal.h>
#include <fcntl.h>
-struct pid_cmd {
- u32 type;
- u32 len;
-};
-
-struct vmstate_cmd {
- u32 type;
- u32 len;
-};
-
static bool run;
static bool rootfs;
@@ -47,11 +37,10 @@ void kvm_list_help(void)
static pid_t get_pid(int sock)
{
- struct pid_cmd cmd = {KVM_IPC_PID, 0};
- int r;
pid_t pid;
+ int r;
- r = write(sock, &cmd, sizeof(cmd));
+ r = kvm_ipc__send(sock, KVM_IPC_PID);
if (r < 0)
return r;
@@ -64,11 +53,10 @@ static pid_t get_pid(int sock)
static int get_vmstate(int sock)
{
- struct vmstate_cmd cmd = {KVM_IPC_VMSTATE, 0};
- int r;
int vmstate;
+ int r;
- r = write(sock, &cmd, sizeof(cmd));
+ r = kvm_ipc__send(sock, KVM_IPC_VMSTATE);
if (r < 0)
return r;
--
1.7.7.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-12-22 2:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-22 2:10 [PATCH 1/6] kvm tools: Handle multiple IPC cmd at a time Asias He
2011-12-22 2:10 ` [PATCH 2/6] kvm tools: Introduce KVM_IPC_VMSTATE IPC cmd Asias He
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
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).