From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=56264 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLdYP-0005sH-Qz for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:44:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLdY2-0005F4-3c for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:43:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8237) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLdY1-0005Eq-TC for qemu-devel@nongnu.org; Mon, 07 Jun 2010 10:43:30 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o57EhSYa020819 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Jun 2010 10:43:28 -0400 From: "Daniel P. Berrange" Date: Mon, 7 Jun 2010 15:42:27 +0100 Message-Id: <1275921752-29420-15-git-send-email-berrange@redhat.com> In-Reply-To: <1275921752-29420-1-git-send-email-berrange@redhat.com> References: <1275921752-29420-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH 14/19] Add a query-argv command to QMP List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Add a new QMP command called 'query-argv' to information about the command line arguments supported by the QEMU binary. This is intended to remove the need for apps to parse '-help' output. [ { "name": "help", }, { "name": "M", "parameters": [ { } ] }, ] NB, command line args which accept parameters have a non-zero length parameters list. The element of the list is currently empty though since the parameter names are not easily available in QEMU source in a format suitable for exposing as a stable ABI. Signed-off-by: Daniel P. Berrange --- monitor.c | 8 ++++++ monitor.h | 2 + vl.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 0 deletions(-) diff --git a/monitor.c b/monitor.c index d55b27b..1c5157d 100644 --- a/monitor.c +++ b/monitor.c @@ -2544,6 +2544,14 @@ static const mon_cmd_t info_cmds[] = { .mhandler.info_new = do_info_commands, }, { + .name = "argv", + .args_type = "", + .params = "", + .help = "list QEMU command line argv", + .user_print = monitor_user_noop, + .mhandler.info_new = do_info_argv, + }, + { .name = "network", .args_type = "", .params = "", diff --git a/monitor.h b/monitor.h index ea15469..46b7a0e 100644 --- a/monitor.h +++ b/monitor.h @@ -55,4 +55,6 @@ typedef void (MonitorCompletion)(void *opaque, QObject *ret_data); void monitor_set_error(Monitor *mon, QError *qerror); +void do_info_argv(Monitor *mon, QObject **data); + #endif /* !MONITOR_H */ diff --git a/vl.c b/vl.c index 8043fac..a76c673 100644 --- a/vl.c +++ b/vl.c @@ -1987,6 +1987,80 @@ static void version(void) printf("QEMU emulator version " QEMU_VERSION QEMU_PKGVERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n"); } + +/** + * do_info_argv(): + * + * Provide info about the command line arguments + * supported by the QEMU binary. The returned + * data is a QList with one QDict entry for each named + * argument. Each entry's QDict contains the following + * keys + * + * 'name': the command argument name (eg 'drive' for -drive arg) + * 'parameters': list of parameter values (if any) + * + * NB, the 'parameters' key is omitted completely if + * the argument has no associated value. + * + * XXXX details of the parameters are not yet filled in + * since this info is not easily available + * + * [ + * { + * "name": "help", + * "parameters": [ + * ] + * }, + * { + * "name": "M", + * "parameters": [ + * { + * } + * ] + * }, + * ] + */ +void do_info_argv(Monitor *mon, QObject **data) +{ + QList *args = qlist_new(); + struct { + const char *name; + int has_arg; + const char *help; + } options_help[] = { +#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ + { option, opt_arg }, +#define DEFHEADING(text) +#define HAS_ARG 1 +#include "qemu-options.h" +#undef DEF +#undef DEFHEADING +#undef HAS_ARG + { NULL, 0 }, + }; + int i; + + for (i = 0 ; options_help[i].name != NULL ; i++) { + QObject *opt; + + if (options_help[i].has_arg) { + /* XXX actually fill in the parameter details */ + opt = qobject_from_jsonf("{ 'name': %s, 'parameters': [] }", + options_help[i].name); + } else { + opt = qobject_from_jsonf("{ 'name': %s }", + options_help[i].name); + } + + + qlist_append_obj(args, opt); + } + + *data = QOBJECT(args); +} + + static void help(int exitcode) { const char *options_help = -- 1.6.6.1