qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 17/19] Add a query-config command to QMP
Date: Mon,  7 Jun 2010 15:42:30 +0100	[thread overview]
Message-ID: <1275921752-29420-18-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1275921752-29420-1-git-send-email-berrange@redhat.com>

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(-)

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 */
-- 
1.6.6.1

  parent reply	other threads:[~2010-06-07 14:44 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-07 14:42 [Qemu-devel] [PATCH 00/19] RFC: Reporting QEMU binary capabilities Daniel P. Berrange
2010-06-07 14:42 ` [Qemu-devel] [PATCH 01/19] Add support for JSON pretty printing Daniel P. Berrange
2010-06-09 19:51   ` Luiz Capitulino
2010-06-07 14:42 ` [Qemu-devel] [PATCH 02/19] Add support for compile time assertions Daniel P. Berrange
2010-06-07 15:35   ` [Qemu-devel] " Paolo Bonzini
2010-06-07 14:42 ` [Qemu-devel] [PATCH 03/19] Add enum handlers for easy & efficient string <-> int conversion Daniel P. Berrange
2010-06-09 19:52   ` Luiz Capitulino
2010-06-26  6:52   ` Markus Armbruster
2010-06-07 14:42 ` [Qemu-devel] [PATCH 04/19] Add support for a option parameter as an enum Daniel P. Berrange
2010-06-26  6:59   ` Markus Armbruster
2010-06-07 14:42 ` [Qemu-devel] [PATCH 05/19] Ensure that QEMU exits if drive_add parsing fails Daniel P. Berrange
2010-06-26  7:04   ` Markus Armbruster
2010-06-07 14:42 ` [Qemu-devel] [PATCH 06/19] Convert drive options to use enumeration data type Daniel P. Berrange
2010-06-09 19:52   ` Luiz Capitulino
2010-06-26  7:07   ` Markus Armbruster
2010-06-07 14:42 ` [Qemu-devel] [PATCH 07/19] Convert netdev client types to use an enumeration Daniel P. Berrange
2010-06-07 15:09   ` Anthony Liguori
2010-06-07 15:13     ` Daniel P. Berrange
2010-06-07 14:42 ` [Qemu-devel] [PATCH 08/19] Convert RTC to use enumerations for configuration parameters Daniel P. Berrange
2010-06-09 19:54   ` Luiz Capitulino
2010-06-07 14:42 ` [Qemu-devel] [PATCH 09/19] Change 'query-version' to output broken down version string Daniel P. Berrange
2010-06-07 15:11   ` Anthony Liguori
2010-06-09 20:04     ` Luiz Capitulino
2010-06-07 14:42 ` [Qemu-devel] [PATCH 10/19] Add a query-machines command to QMP Daniel P. Berrange
2010-06-07 15:13   ` Anthony Liguori
2010-06-07 16:44     ` Daniel P. Berrange
2010-06-07 17:07       ` Anthony Liguori
2010-06-07 17:14         ` Daniel P. Berrange
2010-06-09 20:06         ` Luiz Capitulino
2010-06-07 14:42 ` [Qemu-devel] [PATCH 11/19] Add a query-devices " Daniel P. Berrange
2010-06-07 15:14   ` Anthony Liguori
2010-06-07 16:03     ` Daniel P. Berrange
2010-06-26  7:12       ` Markus Armbruster
2010-06-07 14:42 ` [Qemu-devel] [PATCH 12/19] Add a query-cputypes " Daniel P. Berrange
2010-06-26  7:18   ` Markus Armbruster
2010-06-07 14:42 ` [Qemu-devel] [PATCH 13/19] Add a query-target " Daniel P. Berrange
2010-06-07 15:43   ` [Qemu-devel] " Paolo Bonzini
2010-06-07 14:42 ` [Qemu-devel] [PATCH 14/19] Add a query-argv " Daniel P. Berrange
2010-06-07 15:01   ` Anthony Liguori
2010-06-10 15:34     ` [Qemu-devel] " Paolo Bonzini
2010-06-26  7:30     ` [Qemu-devel] " Markus Armbruster
2010-06-07 14:42 ` [Qemu-devel] [PATCH 15/19] Expand query-argv to include help string Daniel P. Berrange
2010-06-07 14:42 ` [Qemu-devel] [PATCH 16/19] Add a query-netdev command to QMP Daniel P. Berrange
2010-06-07 15:15   ` Anthony Liguori
2010-06-26  7:32     ` Markus Armbruster
2010-06-07 19:13   ` Miguel Di Ciurcio Filho
2010-06-08  8:38     ` Daniel P. Berrange
2010-06-07 14:42 ` Daniel P. Berrange [this message]
2010-06-26  7:34   ` [Qemu-devel] [PATCH 17/19] Add a query-config " Markus Armbruster
2010-06-07 14:42 ` [Qemu-devel] [PATCH 18/19] Add option to turn on JSON pretty printing in monitor Daniel P. Berrange
2010-06-07 14:42 ` [Qemu-devel] [PATCH 19/19] Add a -capabilities argument to allow easy query for static QEMU info Daniel P. Berrange
2010-06-07 16:04   ` [Qemu-devel] " Paolo Bonzini
2010-06-07 16:09     ` Daniel P. Berrange
2010-06-07 16:04   ` [Qemu-devel] " Anthony Liguori
2010-06-07 14:58 ` [Qemu-devel] [PATCH 00/19] RFC: Reporting QEMU binary capabilities Anthony Liguori
2010-06-07 15:10   ` Daniel P. Berrange
2010-06-07 15:18     ` Anthony Liguori
2010-06-07 16:02   ` [Qemu-devel] " Paolo Bonzini
2010-06-07 16:03     ` Anthony Liguori
2010-06-07 16:07 ` [Qemu-devel] " Anthony Liguori
2010-06-09 20:25   ` Luiz Capitulino
2010-06-26  6:45 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1275921752-29420-18-git-send-email-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).