From patchwork Fri Aug 12 15:20:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1061352 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 p7CFMGx5014408 for ; Fri, 12 Aug 2011 15:22:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751382Ab1HLPWO (ORCPT ); Fri, 12 Aug 2011 11:22:14 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:61789 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751253Ab1HLPWM (ORCPT ); Fri, 12 Aug 2011 11:22:12 -0400 Received: by mail-wy0-f174.google.com with SMTP id 24so2218022wyg.19 for ; Fri, 12 Aug 2011 08:22:11 -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:in-reply-to:references; bh=386KG8qQQ92FdJoD0XH1rZCglkcBEN+QowGkfWRTA+8=; b=CWoMZO/fqxwmTRxGKVIQ9wLbPosg9ooAOXuF6JrlhKP0vc6Zg8KtPhjmjt/XMD63Ho FTCeeAd+cV8VBmxKlW4ODqn8orV17dTFgGUBxJsikVyoSRrHr/i57RzO6EZm27zl7fo1 1iJZNtn0KW1Yg2I2w9zQvhkT55d1UdSZcQIsE= Received: by 10.227.13.77 with SMTP id b13mr970176wba.54.1313162531694; Fri, 12 Aug 2011 08:22:11 -0700 (PDT) Received: from localhost.localdomain (bzq-79-176-216-225.red.bezeqint.net [79.176.216.225]) by mx.google.com with ESMTPS id fe4sm2408878wbb.28.2011.08.12.08.22.09 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Aug 2011 08:22:11 -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 2/7] kvm tools: Connect existing command helpers to 'kvm help' Date: Fri, 12 Aug 2011 18:20:55 +0300 Message-Id: <1313162460-14397-2-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1313162460-14397-1-git-send-email-levinsasha928@gmail.com> References: <1313162460-14397-1-git-send-email-levinsasha928@gmail.com> 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]); Fri, 12 Aug 2011 15:22:19 +0000 (UTC) This patch connects usage helpers to 'kvm help' callbacks, allowing to see help about a command by doing 'kvm help [command]'. Signed-off-by: Sasha Levin --- tools/kvm/builtin-balloon.c | 7 ++++++- tools/kvm/builtin-debug.c | 7 ++++++- tools/kvm/builtin-list.c | 15 +++++++++++++++ tools/kvm/builtin-pause.c | 7 ++++++- tools/kvm/builtin-resume.c | 7 ++++++- tools/kvm/builtin-stop.c | 7 ++++++- tools/kvm/include/kvm/builtin-balloon.h | 1 + tools/kvm/include/kvm/builtin-debug.h | 1 + tools/kvm/include/kvm/builtin-list.h | 1 + tools/kvm/include/kvm/builtin-pause.h | 1 + tools/kvm/include/kvm/builtin-resume.h | 1 + tools/kvm/include/kvm/builtin-stop.h | 1 + tools/kvm/kvm-cmd.c | 22 +++++++++++----------- 13 files changed, 62 insertions(+), 16 deletions(-) diff --git a/tools/kvm/builtin-balloon.c b/tools/kvm/builtin-balloon.c index 907a56a..08795cd 100644 --- a/tools/kvm/builtin-balloon.c +++ b/tools/kvm/builtin-balloon.c @@ -17,6 +17,11 @@ static const struct option balloon_options[] = { OPT_END() }; +void kvm_balloon_help(void) +{ + usage_with_options(balloon_usage, balloon_options); +} + int kvm_cmd_balloon(int argc, const char **argv, const char *prefix) { int pid; @@ -24,7 +29,7 @@ int kvm_cmd_balloon(int argc, const char **argv, const char *prefix) int inflate = 0; if (argc != 3) - usage_with_options(balloon_usage, balloon_options); + kvm_balloon_help(); pid = kvm__get_pid_by_instance(argv[2]); if (pid < 0) diff --git a/tools/kvm/builtin-debug.c b/tools/kvm/builtin-debug.c index adb0b54..444ec51 100644 --- a/tools/kvm/builtin-debug.c +++ b/tools/kvm/builtin-debug.c @@ -17,6 +17,11 @@ static const struct option debug_options[] = { OPT_END() }; +void kvm_debug_help(void) +{ + usage_with_options(debug_usage, debug_options); +} + static int do_debug(const char *name, int pid) { return kill(pid, SIGQUIT); @@ -27,7 +32,7 @@ int kvm_cmd_debug(int argc, const char **argv, const char *prefix) int pid; if (argc != 1) - usage_with_options(debug_usage, debug_options); + kvm_debug_help(); if (strcmp(argv[0], "all") == 0) { return kvm__enumerate_instances(do_debug); diff --git a/tools/kvm/builtin-list.c b/tools/kvm/builtin-list.c index 34cc03b..fcf9bb0 100644 --- a/tools/kvm/builtin-list.c +++ b/tools/kvm/builtin-list.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -10,6 +11,20 @@ #define PROCESS_NAME "kvm" +static const char * const list_usage[] = { + "kvm list", + NULL +}; + +static const struct option list_options[] = { + OPT_END() +}; + +void kvm_list_help(void) +{ + usage_with_options(list_usage, list_options); +} + static int print_guest(const char *name, int pid) { char proc_name[PATH_MAX]; diff --git a/tools/kvm/builtin-pause.c b/tools/kvm/builtin-pause.c index 7ac793c..7a6a6c7 100644 --- a/tools/kvm/builtin-pause.c +++ b/tools/kvm/builtin-pause.c @@ -17,6 +17,11 @@ static const struct option pause_options[] = { OPT_END() }; +void kvm_pause_help(void) +{ + usage_with_options(pause_usage, pause_options); +} + static int do_pause(const char *name, int pid) { return kill(pid, SIGUSR2); @@ -27,7 +32,7 @@ int kvm_cmd_pause(int argc, const char **argv, const char *prefix) int pid; if (argc != 1) - usage_with_options(pause_usage, pause_options); + kvm_pause_help(); if (strcmp(argv[0], "all") == 0) { return kvm__enumerate_instances(do_pause); diff --git a/tools/kvm/builtin-resume.c b/tools/kvm/builtin-resume.c index 3b08d3f..b004f2d 100644 --- a/tools/kvm/builtin-resume.c +++ b/tools/kvm/builtin-resume.c @@ -17,6 +17,11 @@ static const struct option resume_options[] = { OPT_END() }; +void kvm_resume_help(void) +{ + usage_with_options(resume_usage, resume_options); +} + static int do_resume(const char *name, int pid) { return kill(pid, SIGKVMRESUME); @@ -27,7 +32,7 @@ int kvm_cmd_resume(int argc, const char **argv, const char *prefix) int pid; if (argc != 1) - usage_with_options(resume_usage, resume_options); + kvm_resume_help(); if (strcmp(argv[0], "all") == 0) { return kvm__enumerate_instances(do_resume); diff --git a/tools/kvm/builtin-stop.c b/tools/kvm/builtin-stop.c index efbf979..de31132 100644 --- a/tools/kvm/builtin-stop.c +++ b/tools/kvm/builtin-stop.c @@ -17,6 +17,11 @@ static const struct option stop_options[] = { OPT_END() }; +void kvm_stop_help(void) +{ + usage_with_options(stop_usage, stop_options); +} + static int do_stop(const char *name, int pid) { return kill(pid, SIGKVMSTOP); @@ -27,7 +32,7 @@ int kvm_cmd_stop(int argc, const char **argv, const char *prefix) int pid; if (argc != 1) - usage_with_options(stop_usage, stop_options); + kvm_stop_help(); if (strcmp(argv[0], "all") == 0) { return kvm__enumerate_instances(do_stop); diff --git a/tools/kvm/include/kvm/builtin-balloon.h b/tools/kvm/include/kvm/builtin-balloon.h index f5f92b9..85055eb 100644 --- a/tools/kvm/include/kvm/builtin-balloon.h +++ b/tools/kvm/include/kvm/builtin-balloon.h @@ -2,5 +2,6 @@ #define KVM__BALLOON_H int kvm_cmd_balloon(int argc, const char **argv, const char *prefix); +void kvm_balloon_help(void); #endif diff --git a/tools/kvm/include/kvm/builtin-debug.h b/tools/kvm/include/kvm/builtin-debug.h index 190cf31..3fc2469 100644 --- a/tools/kvm/include/kvm/builtin-debug.h +++ b/tools/kvm/include/kvm/builtin-debug.h @@ -2,5 +2,6 @@ #define KVM__DEBUG_H int kvm_cmd_debug(int argc, const char **argv, const char *prefix); +void kvm_debug_help(void); #endif diff --git a/tools/kvm/include/kvm/builtin-list.h b/tools/kvm/include/kvm/builtin-list.h index eba9cfd..04fca22 100644 --- a/tools/kvm/include/kvm/builtin-list.h +++ b/tools/kvm/include/kvm/builtin-list.h @@ -2,5 +2,6 @@ #define KVM__LIST_H int kvm_cmd_list(int argc, const char **argv, const char *prefix); +void kvm_list_help(void); #endif diff --git a/tools/kvm/include/kvm/builtin-pause.h b/tools/kvm/include/kvm/builtin-pause.h index 0f8e96b..540cc8e 100644 --- a/tools/kvm/include/kvm/builtin-pause.h +++ b/tools/kvm/include/kvm/builtin-pause.h @@ -2,5 +2,6 @@ #define KVM__PAUSE_H int kvm_cmd_pause(int argc, const char **argv, const char *prefix); +void kvm_pause_help(void); #endif diff --git a/tools/kvm/include/kvm/builtin-resume.h b/tools/kvm/include/kvm/builtin-resume.h index 4a64747..9e6e8d7 100644 --- a/tools/kvm/include/kvm/builtin-resume.h +++ b/tools/kvm/include/kvm/builtin-resume.h @@ -2,5 +2,6 @@ #define KVM__RESUME_H int kvm_cmd_resume(int argc, const char **argv, const char *prefix); +void kvm_resume_help(void); #endif diff --git a/tools/kvm/include/kvm/builtin-stop.h b/tools/kvm/include/kvm/builtin-stop.h index 317d34d..7570695 100644 --- a/tools/kvm/include/kvm/builtin-stop.h +++ b/tools/kvm/include/kvm/builtin-stop.h @@ -2,5 +2,6 @@ #define KVM__STOP_H int kvm_cmd_stop(int argc, const char **argv, const char *prefix); +void kvm_stop_help(void); #endif diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c index 3a90d6d..4e3ea22 100644 --- a/tools/kvm/kvm-cmd.c +++ b/tools/kvm/kvm-cmd.c @@ -18,17 +18,17 @@ #include "kvm/util.h" 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 }, - { "version", kvm_cmd_version, NULL, 0 }, - { "--version", kvm_cmd_version, NULL, 0 }, - { "stop", kvm_cmd_stop, NULL, 0 }, - { "help", kvm_cmd_help, NULL, 0 }, - { "run", kvm_cmd_run, kvm_run_help, 0 }, - { NULL, NULL, NULL, 0 }, + { "pause", kvm_cmd_pause, kvm_pause_help, 0 }, + { "resume", kvm_cmd_resume, kvm_resume_help, 0 }, + { "debug", kvm_cmd_debug, kvm_debug_help, 0 }, + { "balloon", kvm_cmd_balloon, kvm_balloon_help, 0 }, + { "list", kvm_cmd_list, kvm_list_help, 0 }, + { "version", kvm_cmd_version, NULL, 0 }, + { "--version", kvm_cmd_version, NULL, 0 }, + { "stop", kvm_cmd_stop, kvm_stop_help, 0 }, + { "help", kvm_cmd_help, NULL, 0 }, + { "run", kvm_cmd_run, kvm_run_help, 0 }, + { NULL, NULL, NULL, 0 }, }; /*