From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: [PATCH 5/7] kvm tools: Improve 'kvm pause' parameters Date: Fri, 12 Aug 2011 18:20:58 +0300 Message-ID: <1313162460-14397-5-git-send-email-levinsasha928@gmail.com> References: <1313162460-14397-1-git-send-email-levinsasha928@gmail.com> Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, Sasha Levin To: penberg@kernel.org Return-path: Received: from mail-wy0-f174.google.com ([74.125.82.174]:60227 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751724Ab1HLPWS (ORCPT ); Fri, 12 Aug 2011 11:22:18 -0400 Received: by mail-wy0-f174.google.com with SMTP id 24so2218106wyg.19 for ; Fri, 12 Aug 2011 08:22:17 -0700 (PDT) In-Reply-To: <1313162460-14397-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: kvm pause now uses the git option parser to parse parameters. Added option to pause instance by PID and pause all instances. Improved usage message. Signed-off-by: Sasha Levin --- tools/kvm/builtin-pause.c | 48 +++++++++++++++++++++++++++++++------------- 1 files changed, 34 insertions(+), 14 deletions(-) diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c index 7a6a6c7..1c3ec44 100644 --- a/tools/kvm/builtin-pause.c +++ b/tools/kvm/builtin-pause.c @@ -1,22 +1,40 @@ -#include -#include -#include - #include #include #include #include #include +#include +#include +#include + +static bool all; +static u64 instance_pid; +static const char *instance_name; + static const char * const pause_usage[] = { - "kvm pause ", + "kvm pause [--all] [-n name] [-p pid]", NULL }; static const struct option pause_options[] = { + OPT_GROUP("General options:"), + OPT_BOOLEAN('a', "all", &all, "Pause all instances"), + OPT_STRING('n', "name", &instance_name, "name", "Instance name"), + OPT_U64('p', "pid", &instance_pid, "Instance pid"), OPT_END() }; +static void parse_pause_options(int argc, const char **argv) +{ + while (argc != 0) { + argc = parse_options(argc, argv, pause_options, pause_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + if (argc != 0) + kvm_pause_help(); + } +} + void kvm_pause_help(void) { usage_with_options(pause_usage, pause_options); @@ -29,18 +47,20 @@ static int do_pause(const char *name, int pid) int kvm_cmd_pause(int argc, const char **argv, const char *prefix) { - int pid; + parse_pause_options(argc, argv); - if (argc != 1) + if (all) + return kvm__enumerate_instances(do_pause); + + if (instance_name == NULL && + instance_pid == 0) kvm_pause_help(); - if (strcmp(argv[0], "all") == 0) { - return kvm__enumerate_instances(do_pause); - } + if (instance_name) + instance_pid = kvm__get_pid_by_instance(argv[0]); - pid = kvm__get_pid_by_instance(argv[0]); - if (pid < 0) - die("Failed locating instance name"); + if (instance_pid <= 0) + die("Failed locating instance"); - return kill(pid, SIGUSR2); + return kill(instance_pid, SIGUSR2); } -- 1.7.6