qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 14/19] Add a query-argv command to QMP


From: Daniel P. Berrange
Subject: [Qemu-devel] [PATCH 14/19] Add a query-argv command to QMP
Date: Mon, 7 Jun 2010 15:42:27 +0100

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]