From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=41337 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLdpC-00014m-4X for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:01:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLdp7-00009A-Qf for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:01:10 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:54992) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLdp7-00008v-OG for qemu-devel@nongnu.org; Mon, 07 Jun 2010 11:01:09 -0400 Received: by yxk8 with SMTP id 8so730279yxk.4 for ; Mon, 07 Jun 2010 08:01:09 -0700 (PDT) Message-ID: <4C0D09B0.7000305@codemonkey.ws> Date: Mon, 07 Jun 2010 10:01:04 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 14/19] Add a query-argv command to QMP References: <1275921752-29420-1-git-send-email-berrange@redhat.com> <1275921752-29420-15-git-send-email-berrange@redhat.com> In-Reply-To: <1275921752-29420-15-git-send-email-berrange@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org On 06/07/2010 09:42 AM, Daniel P. Berrange wrote: > 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. > This is just as bad as parsing -help output IMHO. The problem with something like this is that it discourages people from using proper APIs to get at capabilities information. Regards, Anthony Liguori > [ > { > "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 = >