[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 17/19] Add a query-config command to QMP
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PATCH 17/19] Add a query-config command to QMP |
Date: |
Mon, 7 Jun 2010 15:42:30 +0100 |
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 <address@hidden>
---
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
- [Qemu-devel] [PATCH 10/19] Add a query-machines command to QMP, (continued)
[Qemu-devel] [PATCH 13/19] Add a query-target command to QMP, Daniel P. Berrange, 2010/06/07
[Qemu-devel] [PATCH 15/19] Expand query-argv to include help string, Daniel P. Berrange, 2010/06/07
[Qemu-devel] [PATCH 18/19] Add option to turn on JSON pretty printing in monitor, Daniel P. Berrange, 2010/06/07
[Qemu-devel] [PATCH 17/19] Add a query-config command to QMP,
Daniel P. Berrange <=
[Qemu-devel] [PATCH 16/19] Add a query-netdev command to QMP, Daniel P. Berrange, 2010/06/07
[Qemu-devel] [PATCH 19/19] Add a -capabilities argument to allow easy query for static QEMU info, Daniel P. Berrange, 2010/06/07