From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: el13635@mail.ntua.gr, kwolf@redhat.com, berrange@redhat.com,
eblake@redhat.com, pbonzini@redhat.com, f4bug@amsat.org
Subject: [Qemu-devel] [PATCH v2 2/2] vl: Partial support for non-scalar properties with -object
Date: Fri, 11 Aug 2017 18:05:22 +0200 [thread overview]
Message-ID: <1502467522-32237-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1502467522-32237-1-git-send-email-armbru@redhat.com>
We've wanted -object to support non-scalar properties for a while.
Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based
authorization API". Review led to the conclusion that we need to
replace rather than add to QemuOpts. Initial work towards that goal
has been merged to provide -blockdev (commit 8746709), but there's
substantial work left, mostly due to an bewildering array of
compatibility problems.
Even if a full solution is still out of reach, we can have a partial
solution now: accept -object argument in JSON syntax. This should
unblock development work that needs non-scalar properties with
-object.
The implementation is similar to -blockdev, except we use the new
infrastructure only for the new JSON case, and stick to QemuOpts for
the existing KEY=VALUE,... case, to sidestep compatibility problems.
If we did this for more options, we'd have to factor out common code.
But for one option, this will do.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
qapi-schema.json | 14 +++++++++++---
vl.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/qapi-schema.json b/qapi-schema.json
index 802ea53..7ed1db1 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3618,15 +3618,23 @@
{ 'command': 'netdev_del', 'data': {'id': 'str'} }
##
-# @object-add:
+# @ObjectOptions:
#
-# Create a QOM object.
+# Options for creating an object.
#
# @qom-type: the class name for the object to be created
#
# @id: the name of the new object
#
# @props: a dictionary of properties to be passed to the backend
+##
+{ 'struct': 'ObjectOptions',
+ 'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} }
+
+##
+# @object-add:
+#
+# Create a QOM object.
#
# Returns: Nothing on success
# Error if @qom-type is not a valid class name
@@ -3642,7 +3650,7 @@
#
##
{ 'command': 'object-add',
- 'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} }
+ 'data': 'ObjectOptions' }
##
# @object-del:
diff --git a/vl.c b/vl.c
index 96c5da1..cd9ab74 100644
--- a/vl.c
+++ b/vl.c
@@ -2855,8 +2855,36 @@ static bool object_create_delayed(const char *type)
return !object_create_initial(type);
}
+typedef struct ObjectOptionsQueueEntry {
+ ObjectOptions *oo;
+ Location loc;
+ QSIMPLEQ_ENTRY(ObjectOptionsQueueEntry) entry;
+} ObjectOptionsQueueEntry;
+
+typedef QSIMPLEQ_HEAD(ObjectOptionsQueue, ObjectOptionsQueueEntry)
+ ObjectOptionsQueue;
+
+ObjectOptionsQueue oo_queue = QSIMPLEQ_HEAD_INITIALIZER(oo_queue);
+
+
static void object_create(bool (*type_predicate)(const char *))
{
+ ObjectOptionsQueueEntry *e, *next;
+
+ QSIMPLEQ_FOREACH_SAFE(e, &oo_queue, entry, next) {
+ if (!type_predicate(e->oo->qom_type)) {
+ continue;
+ }
+
+ loc_push_restore(&e->loc);
+ qmp_object_add(e->oo->qom_type, e->oo->id,
+ e->oo->has_props, e->oo->props, &error_fatal);
+ loc_pop(&e->loc);
+
+ QSIMPLEQ_REMOVE(&oo_queue, e, ObjectOptionsQueueEntry, entry);
+ qapi_free_ObjectOptions(e->oo);
+ }
+
if (qemu_opts_foreach(qemu_find_opts("object"),
user_creatable_add_opts_foreach,
type_predicate, NULL)) {
@@ -4079,6 +4107,29 @@ int main(int argc, char **argv, char **envp)
#endif
break;
case QEMU_OPTION_object:
+ /*
+ * TODO Use qobject_input_visitor_new_str() instead of
+ * QemuOpts, not in addition to. Not done now because
+ * keyval_parse() isn't wart-compatible with QemuOpts.
+ */
+ if (optarg[0] == '{') {
+ Visitor *v;
+ ObjectOptionsQueueEntry *e;
+
+ v = qobject_input_visitor_new_str(optarg, "qom-type",
+ &err);
+ if (!v) {
+ error_report_err(err);
+ exit(1);
+ }
+
+ e = g_new(ObjectOptionsQueueEntry, 1);
+ visit_type_ObjectOptions(v, NULL, &e->oo, &error_fatal);
+ visit_free(v);
+ loc_save(&e->loc);
+ QSIMPLEQ_INSERT_TAIL(&oo_queue, e, entry);
+ break;
+ }
opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
optarg, true);
if (!opts) {
--
2.7.5
next prev parent reply other threads:[~2017-08-11 16:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-11 16:05 [Qemu-devel] [PATCH v2 0/2] vl: Partial support for non-scalar properties with -object Markus Armbruster
2017-08-11 16:05 ` [Qemu-devel] [PATCH v2 1/2] vl: Factor object_create() out of main() Markus Armbruster
2017-08-11 16:05 ` Markus Armbruster [this message]
2017-08-11 17:47 ` [Qemu-devel] [PATCH v2 2/2] vl: Partial support for non-scalar properties with -object Eric Blake
2017-08-14 5:49 ` Markus Armbruster
2018-04-16 16:24 ` Daniel P. Berrangé
2018-05-28 9:30 ` Markus Armbruster
2017-08-14 9:44 ` Daniel P. Berrange
2017-08-14 11:24 ` Markus Armbruster
2018-04-16 16:29 ` Daniel P. Berrangé
2018-05-28 9:14 ` Markus Armbruster
2018-04-16 16:17 ` [Qemu-devel] [PATCH v2 0/2] " Daniel P. Berrangé
2018-05-28 9:31 ` Markus Armbruster
2018-06-08 17:11 ` Daniel P. Berrangé
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=1502467522-32237-3-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=el13635@mail.ntua.gr \
--cc=f4bug@amsat.org \
--cc=kwolf@redhat.com \
--cc=pbonzini@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).