diff mbox

[17/19] Add a query-config command to QMP

Message ID 1275921752-29420-18-git-send-email-berrange@redhat.com
State New
Headers show

Commit Message

Daniel P. Berrangé June 7, 2010, 2:42 p.m. UTC
Add a new command to QMP called 'query-config' that provides
information about the allowed configuration file entries for
the binary.

The data format looks like

    [
        {
            "name": "drive",
            "properties": [
                {
                    "name": "bus",
                    "validate": {
                    },
                    "help": "bus number",
                    "type": "number"
                },
                {
                    "name": "unit",
                    "validate": {
                    },
                    "help": "unit number (i.e. lun for scsi)",
                    "type": "number"
                },
                {
                    "name": "if",
                    "validate": {
                        "values": [
                            "none",
                            "ide",
                            "scsi",
                            "floppy",
                            "pflash",
                            "mtd",
                            "sd",
                            "virtio",
                            "xen"
                        ]
                    },
                    "help": "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
                    "type": "enum"
                },
                {
          ..........
       }
   ]

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 monitor.c     |    8 ++++
 qemu-config.c |  127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 qemu-config.h |    2 +
 3 files changed, 136 insertions(+), 1 deletions(-)

Comments

Markus Armbruster June 26, 2010, 7:34 a.m. UTC | #1
"Daniel P. Berrange" <berrange@redhat.com> writes:

> Add a new command to QMP called 'query-config' that provides
> information about the allowed configuration file entries for
> the binary.

The config file is really just another syntax for the command-line
options using QemuOptsList.  Not sure we want to describe them entirely
separately.
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 19f42f3..39f8150 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2560,6 +2560,14 @@  static const mon_cmd_t info_cmds[] = {
         .mhandler.info_new = do_info_netdev,
     },
     {
+        .name       = "config",
+        .args_type  = "",
+        .params     = "",
+        .help       = "list valid config file parameters",
+        .user_print = monitor_user_noop,
+        .mhandler.info_new = do_info_config,
+    },
+    {
         .name       = "network",
         .args_type  = "",
         .params     = "",
diff --git a/qemu-config.c b/qemu-config.c
index 75cddc1..925bd04 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -5,6 +5,9 @@ 
 #include "sysemu.h"
 #include "hw/qdev.h"
 #include "block.h"
+#include "qjson.h"
+#include "qlist.h"
+
 
 QemuOptsList qemu_drive_opts = {
     .name = "drive",
@@ -97,7 +100,7 @@  QemuOptsList qemu_drive_opts = {
                     .to_string = bdrv_aio_to_string,
                     .to_string_list = bdrv_aio_to_string_list,
                     .from_string = bdrv_aio_from_string,
-                    .last = BDRV_CACHE_LAST
+                    .last = BDRV_AIO_LAST
                 },
             },
         },{
@@ -612,3 +615,125 @@  int qemu_read_config_file(const char *filename)
         return -EINVAL;
     }
 }
+
+
+/*
+ * do_info_config():
+ *
+ * Return information about allowed configuration file
+ * parameters and their data types.
+ *
+ * At the top level is a QList containing one QDict entry
+ * for each top level config group. The QDict contains
+ * keys for
+ *
+ *  'name': name of the config group
+ *  'properties': QList of a config properties
+ *
+ * Each entry in the properties QList is another QDict
+ * containing keys
+ *
+ *  'name': name of the config parameter
+ *  'help': a short help string (optional)
+ *  'type': data type of the parameter (string, bool, number, size, enum)
+ *  'validate': a QDict of data validation rules
+ *
+ * The 'validate' key is only used for options for type='enum' and
+ * in this case describes the valid strings for the enumeration
+ *
+ * Example snippet of data:
+ *
+ * [
+ *   {
+ *     "name": "drive",
+ *     "properties": [
+ *         {
+ *             "name": "bus",
+ *             "validate": {
+ *             },
+ *             "help": "bus number",
+ *             "type": "number"
+ *         },
+ *         {
+ *             "name": "unit",
+ *             "validate": {
+ *             },
+ *             "help": "unit number (i.e. lun for scsi)",
+ *             "type": "number"
+ *         },
+ *         {
+ *             "name": "if",
+ *             "validate": {
+ *                 "values": [
+ *                     "none",
+ *                     "ide",
+ *                     "scsi",
+ *                     "floppy",
+ *                     "pflash",
+ *                     "mtd",
+ *                     "sd",
+ *                     "virtio",
+ *                     "xen"
+ *                 ]
+ *             },
+ *             "help": "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
+ *             "type": "enum"
+ *         },
+ *      ]
+ *   }
+ *   ...
+ * ]
+ */
+void do_info_config(Monitor *mon, QObject **ret_data)
+{
+    QList *config = qlist_new();
+    int i, j, k;
+
+    for (i = 0 ; vm_config_groups[i] != NULL ; i++) {
+	QemuOptsList *grp = vm_config_groups[i];
+	QList *props = qlist_new();
+	QObject *entry;
+
+	for (j = 0 ; grp->desc[j].name != NULL ; j++) {
+	    QemuOptDesc *desc = &grp->desc[j];
+	    QObject *validate  = QOBJECT(qlist_new());
+	    QObject *prop;
+
+	    if (desc->type == QEMU_OPT_ENUM) {
+		QList *valid = qlist_new();
+
+		for (k = 0 ; k < desc->validate.optEnum.last ; k++) {
+		    fprintf(stderr, "name %s %d %d\n", grp->desc[j].name, k, desc->validate.optEnum.last);
+		    const char *str = (desc->validate.optEnum.to_string)(k);
+		    qlist_append_obj(valid, QOBJECT(qstring_from_str(str)));
+		}
+
+		validate = qobject_from_jsonf("{ 'values': %p }", valid);
+	    } else {
+		validate = qobject_from_jsonf("{}");
+	    }
+
+	    if (desc->help) {
+		prop = qobject_from_jsonf("{ 'name': %s, 'type': %s, 'help': %s, 'validate': %p }",
+					  desc->name,
+					  qemu_opt_type_to_string(desc->type),
+					  desc->help,
+					  validate);
+	    } else {
+		prop = qobject_from_jsonf("{ 'name': %s, 'type': %s, 'validate': %p }",
+					  desc->name,
+					  qemu_opt_type_to_string(desc->type),
+					  validate);
+	    }
+
+	    qlist_append_obj(props, prop);
+	}
+
+	entry = qobject_from_jsonf("{ 'name': %s, 'properties': %p }",
+				   grp->name, props);
+
+	qlist_append_obj(config, entry);
+    }
+
+    *ret_data = QOBJECT(config);
+}
diff --git a/qemu-config.h b/qemu-config.h
index dca69d4..b87e8fc 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -25,4 +25,6 @@  int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname);
 
 int qemu_read_config_file(const char *filename);
 
+void do_info_config(Monitor *mon, QObject **ret_data);
+
 #endif /* QEMU_CONFIG_H */