From patchwork Sat Aug 6 14:48:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1041682 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p76EnhnA031905 for ; Sat, 6 Aug 2011 14:49:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752262Ab1HFOtk (ORCPT ); Sat, 6 Aug 2011 10:49:40 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:43487 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751073Ab1HFOtk (ORCPT ); Sat, 6 Aug 2011 10:49:40 -0400 Received: by wyf22 with SMTP id 22so1786148wyf.19 for ; Sat, 06 Aug 2011 07:49:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=OayKe92WwT55oeEWK3UqvK6+IsDztRAqV2lYT7gjBLw=; b=U5OnnP28ShedaBwKTCwM/mD8finieF2VaRLApFUSPSSlk9wLA4EOVCbR085QI3HcZU rSvWRwUoRfwUrxiqiILbbWtQtCKF9SKY2aF3PUDXug8aW5hbKOnFOxg/LWXNhEXLBqUd RLbf5/r+8smU0tPAz8ND+o3Uq8RzFcRb6PLlA= Received: by 10.216.68.200 with SMTP id l50mr2725998wed.106.1312642178573; Sat, 06 Aug 2011 07:49:38 -0700 (PDT) Received: from localhost.localdomain (bzq-79-176-218-143.red.bezeqint.net [79.176.218.143]) by mx.google.com with ESMTPS id x14sm1382561weq.24.2011.08.06.07.49.36 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 06 Aug 2011 07:49:38 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, Sasha Levin Subject: [PATCH] kvm tools: Split 'kvm pause' and add 'kvm resume' Date: Sat, 6 Aug 2011 17:48:42 +0300 Message-Id: <1312642122-22512-1-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 06 Aug 2011 14:51:31 +0000 (UTC) This patch seperates 'kvm pause' into 'kvm pause' and 'kvm resume', 'kvm pause' no longer acts as a switch between running and paused state but instead just switches the instance into paused and reume is handled by the new 'kvm resume'. Signed-off-by: Sasha Levin --- tools/kvm/Documentation/kvm-pause.txt | 4 ++-- tools/kvm/Documentation/kvm-resume.txt | 16 ++++++++++++++++ tools/kvm/Makefile | 1 + tools/kvm/builtin-pause.c | 2 +- tools/kvm/builtin-resume.c | 32 ++++++++++++++++++++++++++++++++ tools/kvm/builtin-run.c | 7 +++++-- tools/kvm/command-list.txt | 1 + tools/kvm/include/kvm/builtin-resume.h | 6 ++++++ tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/kvm-cmd.c | 2 ++ 10 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 tools/kvm/Documentation/kvm-resume.txt create mode 100644 tools/kvm/builtin-resume.c create mode 100644 tools/kvm/include/kvm/builtin-resume.h diff --git a/tools/kvm/Documentation/kvm-pause.txt b/tools/kvm/Documentation/kvm-pause.txt index 773824f..770bcfe 100644 --- a/tools/kvm/Documentation/kvm-pause.txt +++ b/tools/kvm/Documentation/kvm-pause.txt @@ -3,7 +3,7 @@ kvm-pause(1) NAME ---- -kvm-pause - Pause/resume the virtual machine +kvm-pause - Pause the virtual machine SYNOPSIS -------- @@ -12,5 +12,5 @@ SYNOPSIS DESCRIPTION ----------- -The command pauses and resumes a virtual machine. +The command pauses a virtual machine. For a list of running instances see 'kvm list'. diff --git a/tools/kvm/Documentation/kvm-resume.txt b/tools/kvm/Documentation/kvm-resume.txt new file mode 100644 index 0000000..918648e --- /dev/null +++ b/tools/kvm/Documentation/kvm-resume.txt @@ -0,0 +1,16 @@ +kvm-resume(1) +================ + +NAME +---- +kvm-resume - Resume the virtual machine + +SYNOPSIS +-------- +[verse] +'kvm resume [instance]' + +DESCRIPTION +----------- +The command resumes a virtual machine. +For a list of running instances see 'kvm list'. diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 21d6189..0a218d7 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -25,6 +25,7 @@ OBJS += builtin-debug.o OBJS += builtin-help.o OBJS += builtin-list.o OBJS += builtin-pause.o +OBJS += builtin-resume.o OBJS += builtin-run.o OBJS += builtin-version.o OBJS += cpuid.o diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c index 0c0010d..827b3b4 100644 --- a/tools/kvm/builtin-pause.c +++ b/tools/kvm/builtin-pause.c @@ -17,7 +17,7 @@ int kvm_cmd_pause(int argc, const char **argv, const char *prefix) int pid; if (argc != 1) - die("Usage: kvm debug [instance name]\n"); + die("Usage: kvm pause [instance name]\n"); if (strcmp(argv[0], "all") == 0) { kvm__enumerate_instances(do_pause); diff --git a/tools/kvm/builtin-resume.c b/tools/kvm/builtin-resume.c new file mode 100644 index 0000000..4a85918 --- /dev/null +++ b/tools/kvm/builtin-resume.c @@ -0,0 +1,32 @@ +#include +#include +#include + +#include +#include +#include +#include + +static void do_resume(const char *name, int pid) +{ + kill(pid, SIGKVMRESUME); +} + +int kvm_cmd_resume(int argc, const char **argv, const char *prefix) +{ + int pid; + + if (argc != 1) + die("Usage: kvm resume [instance name]\n"); + + if (strcmp(argv[0], "all") == 0) { + kvm__enumerate_instances(do_resume); + return 0; + } + + pid = kvm__get_pid_by_instance(argv[0]); + if (pid < 0) + die("Failed locating instance name"); + + return kill(pid, SIGKVMRESUME); +} diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 2e04265..3a6551a 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -222,10 +222,12 @@ static int is_paused; static void handle_sigusr2(int sig) { - if (is_paused) + if (sig == SIGKVMRESUME && is_paused) kvm__continue(); - else + else if (sig == SIGUSR2 && !is_paused) kvm__pause(); + else + return; is_paused = !is_paused; pr_info("Guest %s\n", is_paused ? "paused" : "resumed"); @@ -489,6 +491,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) signal(SIGQUIT, handle_sigquit); signal(SIGUSR1, handle_sigusr1); signal(SIGUSR2, handle_sigusr2); + signal(SIGKVMRESUME, handle_sigusr2); nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN); diff --git a/tools/kvm/command-list.txt b/tools/kvm/command-list.txt index 037a8ea..e7ed012 100644 --- a/tools/kvm/command-list.txt +++ b/tools/kvm/command-list.txt @@ -4,6 +4,7 @@ # kvm-run mainporcelain common kvm-pause common +kvm-resume common kvm-version common kvm-list common kvm-debug common diff --git a/tools/kvm/include/kvm/builtin-resume.h b/tools/kvm/include/kvm/builtin-resume.h new file mode 100644 index 0000000..4a64747 --- /dev/null +++ b/tools/kvm/include/kvm/builtin-resume.h @@ -0,0 +1,6 @@ +#ifndef KVM__RESUME_H +#define KVM__RESUME_H + +int kvm_cmd_resume(int argc, const char **argv, const char *prefix); + +#endif diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 5f3cbbf..1cb727b 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -20,6 +20,7 @@ #define SIGKVMPAUSE (SIGRTMIN + 1) #define SIGKVMADDMEM (SIGRTMIN + 2) #define SIGKVMDELMEM (SIGRTMIN + 3) +#define SIGKVMRESUME (SIGRTMIN + 5) struct kvm { int sys_fd; /* For system ioctls(), i.e. /dev/kvm */ diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c index a954a61..12eb3fb 100644 --- a/tools/kvm/kvm-cmd.c +++ b/tools/kvm/kvm-cmd.c @@ -7,6 +7,7 @@ /* user defined header files */ #include "kvm/builtin-debug.h" #include "kvm/builtin-pause.h" +#include "kvm/builtin-resume.h" #include "kvm/builtin-balloon.h" #include "kvm/builtin-list.h" #include "kvm/builtin-version.h" @@ -16,6 +17,7 @@ struct cmd_struct kvm_commands[] = { { "pause", kvm_cmd_pause, NULL, 0 }, + { "resume", kvm_cmd_resume, NULL, 0 }, { "debug", kvm_cmd_debug, NULL, 0 }, { "balloon", kvm_cmd_balloon, NULL, 0 }, { "list", kvm_cmd_list, NULL, 0 },