[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v14 14/19] hmp: support non-scalar properties with o
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PATCH v14 14/19] hmp: support non-scalar properties with object_add |
Date: |
Tue, 27 Sep 2016 14:13:16 +0100 |
The current object_add HMP syntax only allows for
creation of objects with scalar properties, or a list
with a fixed scalar element type. Objects which have
properties that are represented as structs in the QAPI
schema cannot be created using -object.
This is a design limitation of the way the OptsVisitor
is written. It simply iterates over the QemuOpts values
as a flat list. The support for lists is enabled by
allowing the same key to be repeated in the opts string.
The QObjectInputVisitor now has functionality that allows
it to replace OptsVisitor, maintaining full backwards
compatibility for previous CLI syntax, while also allowing
use of new syntax for structs.
Thus -object can now support non-scalar properties,
for example the QMP object:
{
"execute": "object-add",
"arguments": {
"qom-type": "demo",
"id": "demo0",
"parameters": {
"foo": [
{ "bar": "one", "wizz": "1" },
{ "bar": "two", "wizz": "2" }
]
}
}
}
Would be creatable via the HMP now using
object_add demo,id=demo0,\
foo.0.bar=one,foo.0.wizz=1,\
foo.1.bar=two,foo.1.wizz=2
Notice that this syntax is intentionally compatible
with that currently used by block drivers. NB the
indentation seen here after line continuations should
not be used in reality, it is just for clarity in this
commit message.
Signed-off-by: Daniel P. Berrange <address@hidden>
---
hmp.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/hmp.c b/hmp.c
index ad33b44..da77d4c 100644
--- a/hmp.c
+++ b/hmp.c
@@ -25,7 +25,7 @@
#include "qemu/sockets.h"
#include "monitor/monitor.h"
#include "monitor/qdev.h"
-#include "qapi/opts-visitor.h"
+#include "qapi/qobject-input-visitor.h"
#include "qapi/qmp/qerror.h"
#include "qapi/string-output-visitor.h"
#include "qapi/util.h"
@@ -1695,21 +1695,30 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
void hmp_object_add(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
- QemuOpts *opts;
Visitor *v;
Object *obj = NULL;
+ QObject *pobj;
- opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
+ pobj = qdict_crumple(qdict, true, &err);
if (err) {
- hmp_handle_error(mon, &err);
- return;
+ goto cleanup;
}
- v = opts_visitor_new(opts);
- obj = user_creatable_add(qdict, v, &err);
+ /*
+ * We need autocreate_list=true + permit_int_ranges=true
+ * in order to maintain compat with OptsVisitor creation
+ * of the 'numa' object which had an int16List property.
+ *
+ * We need autocreate_structs=1, because at the CLI level
+ * we have the object type + properties in the same flat
+ * struct, even though at the QMP level they are nested.
+ */
+ v = qobject_input_visitor_new_autocast(pobj, true, 1, true);
+ obj = user_creatable_add(qobject_to_qdict(pobj), v, &err);
visit_free(v);
- qemu_opts_del(opts);
+ cleanup:
+ qobject_decref(pobj);
if (err) {
hmp_handle_error(mon, &err);
}
--
2.7.4
- [Qemu-devel] [PATCH v14 03/19] option: allow qemu_opts_to_qdict to merge repeated options, (continued)
- [Qemu-devel] [PATCH v14 03/19] option: allow qemu_opts_to_qdict to merge repeated options, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 04/19] qapi: add trace events for visitor, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 01/19] qdict: implement a qdict_crumple method for un-flattening a dict, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 07/19] qapi: don't pass two copies of TestInputVisitorData to tests, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 09/19] qapi: permit auto-creating single element lists, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 08/19] qapi: permit scalar type conversions in QObjectInputVisitor, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 05/19] qapi: rename QmpInputVisitor to QObjectInputVisitor, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 10/19] qapi: permit auto-creating nested structs, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 06/19] qapi: rename QmpOutputVisitor to QObjectOutputVisitor, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 11/19] qapi: add integer range support for QObjectInputVisitor, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 14/19] hmp: support non-scalar properties with object_add,
Daniel P. Berrange <=
- [Qemu-devel] [PATCH v14 13/19] qom: support non-scalar properties with -object, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 12/19] qapi: allow QObjectInputVisitor to be created with QemuOpts, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 16/19] block: convert crypto driver to use QObjectInputVisitor, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 17/19] acpi: convert to QObjectInputVisitor for -acpi parsing, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 15/19] numa: convert to use QObjectInputVisitor for -numa, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 18/19] net: convert to QObjectInputVisitor for -net/-netdev parsing, Daniel P. Berrange, 2016/09/27
- [Qemu-devel] [PATCH v14 19/19] qapi: delete unused OptsVisitor code, Daniel P. Berrange, 2016/09/27