From patchwork Sun Aug 7 19:23:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1042732 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p77JPOFT001235 for ; Sun, 7 Aug 2011 19:25:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754679Ab1HGTYD (ORCPT ); Sun, 7 Aug 2011 15:24:03 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:50051 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754605Ab1HGTYB (ORCPT ); Sun, 7 Aug 2011 15:24:01 -0400 Received: by wyg24 with SMTP id 24so380962wyg.19 for ; Sun, 07 Aug 2011 12:24:00 -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=14RwFZqps2uLMFF85YZgdQkpvewIhAr2CnH8WH2NNnU=; b=mi+tk8iVIT6jR9mIkRf7JlOM0EB5ynBPTsD/ZhiXg5BbgGlQNR34h1ge6BE87Urypw kwjsDzdfKDbYsagkXwImytWhHJyeOkZaviFF3nBSyHqlkZXXk9yu7wkcrRobl/7IXdBC 3H1ApIME/v2j45EXz68cSn4sdIhW/KpVFxoPE= Received: by 10.216.137.40 with SMTP id x40mr2507698wei.20.1312745040058; Sun, 07 Aug 2011 12:24:00 -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 gb1sm3943339wbb.3.2011.08.07.12.23.57 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 07 Aug 2011 12:23:59 -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 resend] kvm tools: Split 'kvm pause' and add 'kvm resume' Date: Sun, 7 Aug 2011 22:23:06 +0300 Message-Id: <1312744986-6384-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 (demeter2.kernel.org [140.211.167.43]); Sun, 07 Aug 2011 19:25:25 +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 8d45ebf..672027d 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-stop.o OBJS += builtin-version.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 c8539cc..364b538 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -235,10 +235,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"); @@ -508,6 +510,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) signal(SIGUSR1, handle_sigusr1); signal(SIGUSR2, handle_sigusr2); signal(SIGKVMSTOP, handle_sigstop); + 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 fd809a8..6a49d0a 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 722b24b..4f12d11 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -21,6 +21,7 @@ #define SIGKVMADDMEM (SIGRTMIN + 2) #define SIGKVMDELMEM (SIGRTMIN + 3) #define SIGKVMSTOP (SIGRTMIN + 4) +#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 d85cb0a..63a2dbf 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" @@ -17,6 +18,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 },