From: Lai Jiangshan Date: Tue, 20 Dec 2011 09:08:56 +0000 (+0800) Subject: kvm tools: carefully send and handle pause/resume ipc X-Git-Tag: next-20120402~5^2~84 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=a286377ac7a44c9f24f1cfb42b356045e92e20f5;p=karo-tx-linux.git kvm tools: carefully send and handle pause/resume ipc Remove struct pause_cmd/resume_cmd and use kvm_ipc__send(). Signed-off-by: Lai Jiangshan Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c index eb89ff7e9abb..ee5a5b844a78 100644 --- a/tools/kvm/builtin-pause.c +++ b/tools/kvm/builtin-pause.c @@ -9,11 +9,6 @@ #include #include -struct pause_cmd { - u32 type; - u32 len; -}; - static bool all; static const char *instance_name; @@ -46,14 +41,7 @@ void kvm_pause_help(void) static int do_pause(const char *name, int sock) { - struct pause_cmd cmd = {KVM_IPC_PAUSE, 0}; - int r; - - r = write(sock, &cmd, sizeof(cmd)); - if (r < 0) - return r; - - return 0; + return kvm_ipc__send(sock, KVM_IPC_PAUSE); } 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 33ccc2bae890..9c47183c33c6 100644 --- a/tools/kvm/builtin-resume.c +++ b/tools/kvm/builtin-resume.c @@ -9,11 +9,6 @@ #include #include -struct resume_cmd { - u32 type; - u32 len; -}; - static bool all; static const char *instance_name; @@ -46,14 +41,7 @@ void kvm_resume_help(void) static int do_resume(const char *name, int sock) { - struct resume_cmd cmd = {KVM_IPC_RESUME, 0}; - int r; - - r = write(sock, &cmd, sizeof(cmd)); - if (r < 0) - return r; - - return 0; + return kvm_ipc__send(sock, KVM_IPC_RESUME); } 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 3e287706bb90..a94fdbcebb7c 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -507,12 +507,17 @@ static int is_paused; static void handle_pause(int fd, u32 type, u32 len, u8 *msg) { + if (WARN_ON(len)) + return; + if (type == KVM_IPC_RESUME && is_paused) kvm__continue(); else if (type == KVM_IPC_PAUSE && !is_paused) kvm__pause(); - else + else { + WARN_ON(1); return; + } is_paused = !is_paused; pr_info("Guest %s\n", is_paused ? "paused" : "resumed");