From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
"Max Reitz" <mreitz@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v14 15/21] qom: support non-scalar properties with -object
Date: Wed, 19 Oct 2016 18:54:45 +0200 [thread overview]
Message-ID: <877f945ley.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <1475246744-29302-16-git-send-email-berrange@redhat.com> (Daniel P. Berrange's message of "Fri, 30 Sep 2016 15:45:38 +0100")
"Daniel P. Berrange" <berrange@redhat.com> writes:
> The current -object command line 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 CLI now using
>
> $QEMU \
> -object 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 <berrange@redhat.com>
> ---
> qapi/qobject-input-visitor.c | 2 +-
> qom/object_interfaces.c | 37 ++++-
> tests/check-qom-proplist.c | 367 ++++++++++++++++++++++++++++++++++++++++++-
> 3 files changed, 397 insertions(+), 9 deletions(-)
>
> diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
> index 5a3872c..f1030d5 100644
> --- a/qapi/qobject-input-visitor.c
> +++ b/qapi/qobject-input-visitor.c
> @@ -204,7 +204,7 @@ static void qobject_input_start_struct(Visitor *v, const char *name, void **obj,
> *obj = NULL;
> }
>
> - if (!qobj && (qiv->struct_level < qiv->autocreate_struct_levels)) {
> + if (!qobj && (qiv->struct_level <= qiv->autocreate_struct_levels)) {
> /* Create a new dict that contains all the currently
> * unvisited items */
> if (tos) {
Uh, can you explain this hunk? The < comes from PATCH 10.
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index fdc406b..88a1e88 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -4,7 +4,8 @@
> #include "qemu/module.h"
> #include "qapi-visit.h"
> #include "qapi/qobject-output-visitor.h"
> -#include "qapi/opts-visitor.h"
> +#include "qapi/qobject-input-visitor.h"
> +#include "qemu/option.h"
>
> void user_creatable_complete(Object *obj, Error **errp)
> {
> @@ -63,12 +64,16 @@ Object *user_creatable_add(const QDict *qdict,
> if (local_err) {
> goto out_visit;
> }
> - visit_check_struct(v, &local_err);
> +
> + obj = user_creatable_add_type(type, id, pdict, v, &local_err);
> if (local_err) {
> goto out_visit;
> }
>
> - obj = user_creatable_add_type(type, id, pdict, v, &local_err);
> + visit_check_struct(v, &local_err);
> + if (local_err) {
> + goto out_visit;
> + }
>
> out_visit:
> visit_end_struct(v, NULL);
Can you explain why you swap the order of visit_check_struct() and
user_creatable_add_type()? It smells like a bug fix to me...
Odd: opts_check_struct() does nothing unless depth == 0. But depth is
at least 1 between opts_start_struct() and opts_end_struct(). Bug?
> @@ -114,7 +119,7 @@ Object *user_creatable_add_type(const char *type, const char *id,
>
> assert(qdict);
> obj = object_new(type);
> - visit_start_struct(v, NULL, NULL, 0, &local_err);
> + visit_start_struct(v, "props", NULL, 0, &local_err);
> if (local_err) {
> goto out;
> }
Why this hunk?
> @@ -158,14 +163,32 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
> {
> Visitor *v;
> QDict *pdict;
> + QObject *pobj;
> Object *obj = NULL;
>
> - v = opts_visitor_new(opts);
> - pdict = qemu_opts_to_qdict(opts, NULL, QEMU_OPTS_REPEAT_POLICY_LAST,
> + pdict = qemu_opts_to_qdict(opts, NULL,
> + QEMU_OPTS_REPEAT_POLICY_ALL,
> &error_abort);
>
> - obj = user_creatable_add(pdict, v, errp);
> + pobj = qdict_crumple(pdict, true, errp);
> + if (!pobj) {
> + goto cleanup;
> + }
> + /*
> + * 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.
I can't find a "numa" object in the object-add sense, only a NumaOptions
QAPI object created by -numa. Is that what you mean?
> + *
> + * 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.
We screwed up QMP object-add. device_add, netdev_add and object_add all
treat additional arguments as properties *except* for QMP object-add,
which has them wrapped in a JSON object instead.
Aside: if someone foolishly adds a property named "qom-type" or "id",
it'll work in QMP but not in HMP or -object.
The inconsistency complicates the code even before this patch:
* Core: user_creatable_add_type() takes properties in *two* forms: as a
visitor and as a qdict. It visits a struct with the members given by
the qdict's keys. That's its only use of the qdict.
* QMP: qmp_object_add() gets properties as a separate QDict. It creates
a QObject visitor for it, and passes it to user_creatable_add_type()
along with the QDict.
* -object: user_creatable_add_opts() gets the option argument as a
QemuOpts. It creates an options visitor for it *and* converts it to a
QDict, then passes both to user_creatable_add().
* user_creatable_add() visits a struct. It first visits the
non-property arguments "qom-type" and "id". It passes the visitor and
a shallow copy of the QDict with the non-property entries deleted to
user_creatable_add_type() to visit the remaining struct members.
* HMP: hmp_object_add() gets its arguments as a QDict. It converts it
to QemuOpts and creates an options visitor for it *boggle*. It passes
the visitor along with original QDict to user_creatable_add().
I still can't quite see what's requiring autocreate_structs. But I hope
we can get rid of it by cleaning up this mess a bit. Here's how I'd
try:
* Move visit_start_struct() and visit_end_struct() from
user_creatable_add_type() to its two callers qmp_object_add() and
user_creatable_add().
* Make user_creatable_add_type() ignore QDict keys "qom-type" and "id".
* QMP: any attempt to specify property "qom-type" or "id" now fails,
because visit_check_struct() flags them as unexpected.
* user_creatable_add(): ditch the silly QDict copying.
* hmp_object_add(): ditch the silly conversion to QemuOpts, and create a
QObject visitor instead.
> + */
> + v = qobject_input_visitor_new_autocast(pobj, true, 1, true);
> +
> + obj = user_creatable_add(qobject_to_qdict(pobj), v, errp);
> visit_free(v);
> + qobject_decref(pobj);
> + cleanup:
> QDECREF(pdict);
> return obj;
> }
[Skipping test updates for now...]
next prev parent reply other threads:[~2016-10-19 16:54 UTC|newest]
Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-30 14:45 [Qemu-devel] [PATCH v14 00/21] QAPI/QOM work for non-scalar object properties Daniel P. Berrange
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 01/21] option: make parse_option_bool/number non-static Daniel P. Berrange
2016-10-21 16:55 ` Markus Armbruster
2016-10-21 17:12 ` Eric Blake
2016-10-21 17:51 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 02/21] qdict: implement a qdict_crumple method for un-flattening a dict Daniel P. Berrange
2016-10-18 14:32 ` Markus Armbruster
2016-10-20 14:11 ` Daniel P. Berrange
2016-10-21 9:58 ` Markus Armbruster
2016-10-21 18:31 ` Max Reitz
2016-10-24 9:18 ` Markus Armbruster
2016-10-24 10:28 ` Daniel P. Berrange
2016-10-24 12:38 ` Markus Armbruster
2016-10-25 10:03 ` Markus Armbruster
2016-10-25 10:20 ` Daniel P. Berrange
2016-10-25 12:29 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 03/21] qapi: add trace events for visitor Daniel P. Berrange
2016-09-30 15:49 ` Eric Blake
2016-10-06 14:39 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2016-10-07 13:59 ` [Qemu-devel] " Markus Armbruster
2016-10-07 14:16 ` Daniel P. Berrange
2016-10-21 10:52 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 04/21] qapi: rename QmpInputVisitor to QObjectInputVisitor Daniel P. Berrange
2016-10-25 13:41 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 05/21] qapi: rename QmpOutputVisitor to QObjectOutputVisitor Daniel P. Berrange
2016-10-25 13:36 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 06/21] qapi: don't pass two copies of TestInputVisitorData to tests Daniel P. Berrange
2016-09-30 17:43 ` Eric Blake
2016-10-06 14:39 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 07/21] qapi: permit scalar type conversions in QObjectInputVisitor Daniel P. Berrange
2016-09-30 17:48 ` Eric Blake
2016-10-11 16:20 ` Markus Armbruster
2016-10-12 14:51 ` Markus Armbruster
2016-10-12 15:05 ` Markus Armbruster
2016-10-12 15:26 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 08/21] qapi: allow QObjectInputVisitor to be created with QemuOpts Daniel P. Berrange
2016-09-30 17:55 ` Eric Blake
2016-10-06 14:56 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2016-10-12 8:08 ` [Qemu-devel] " Markus Armbruster
2016-10-13 7:23 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 09/21] qapi: permit auto-creating single element lists Daniel P. Berrange
2016-09-30 17:59 ` Eric Blake
2016-10-12 9:18 ` Markus Armbruster
2016-10-20 14:23 ` Daniel P. Berrange
2016-10-21 11:58 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 10/21] qapi: permit auto-creating nested structs Daniel P. Berrange
2016-09-30 18:23 ` Eric Blake
2016-10-06 15:10 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2016-10-06 15:18 ` Daniel P. Berrange
2016-10-06 15:30 ` Kevin Wolf
2016-10-06 15:39 ` Daniel P. Berrange
2016-10-06 15:51 ` Kevin Wolf
2016-10-06 15:57 ` Daniel P. Berrange
2016-10-12 14:00 ` Markus Armbruster
2016-10-06 17:54 ` Eric Blake
2016-10-12 14:12 ` [Qemu-devel] " Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 11/21] qapi: add integer range support for QObjectInputVisitor Daniel P. Berrange
2016-09-30 19:45 ` Eric Blake
2016-10-12 15:50 ` Markus Armbruster
2016-10-12 16:03 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2016-10-12 18:14 ` Markus Armbruster
2016-10-20 14:28 ` [Qemu-devel] " Daniel P. Berrange
2016-10-21 10:58 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 12/21] option: allow qemu_opts_to_qdict to merge repeated options Daniel P. Berrange
2016-09-30 20:08 ` Eric Blake
2016-10-12 17:46 ` Markus Armbruster
2016-10-13 9:21 ` Markus Armbruster
2016-10-20 14:29 ` Daniel P. Berrange
2016-10-21 11:09 ` Markus Armbruster
2016-10-21 11:14 ` Daniel P. Berrange
2016-10-13 8:31 ` Markus Armbruster
2016-10-20 14:37 ` Daniel P. Berrange
2016-10-21 11:28 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 13/21] qdict: allow qdict_crumple to accept compound types as values Daniel P. Berrange
2016-10-13 12:35 ` Markus Armbruster
2016-10-13 14:46 ` Kevin Wolf
2016-10-17 14:50 ` Markus Armbruster
2016-10-17 15:43 ` Paolo Bonzini
2016-10-17 17:48 ` Markus Armbruster
2016-10-17 17:38 ` Eric Blake
2016-10-18 10:59 ` Markus Armbruster
2016-10-18 9:34 ` Kevin Wolf
2016-10-18 15:35 ` Markus Armbruster
2016-10-19 9:25 ` Kevin Wolf
2016-10-19 9:42 ` Daniel P. Berrange
2016-10-19 13:31 ` [Qemu-devel] [Qemu-block] " Eric Blake
2016-10-20 14:46 ` [Qemu-devel] " Daniel P. Berrange
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 14/21] qapi: allow repeated opts with qobject_input_visitor_new_opts Daniel P. Berrange
2016-10-18 17:13 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 15/21] qom: support non-scalar properties with -object Daniel P. Berrange
2016-10-19 16:54 ` Markus Armbruster [this message]
2017-07-10 19:30 ` Manos Pitsidianakis
2017-07-11 8:10 ` Markus Armbruster
2017-07-11 14:44 ` Markus Armbruster
2017-07-11 14:49 ` Daniel P. Berrange
2017-07-12 17:56 ` Manos Pitsidianakis
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 16/21] hmp: support non-scalar properties with object_add Daniel P. Berrange
2016-10-20 6:43 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 17/21] numa: convert to use QObjectInputVisitor for -numa Daniel P. Berrange
2016-10-20 6:57 ` Markus Armbruster
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 18/21] block: convert crypto driver to use QObjectInputVisitor Daniel P. Berrange
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 19/21] acpi: convert to QObjectInputVisitor for -acpi parsing Daniel P. Berrange
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 20/21] net: convert to QObjectInputVisitor for -net/-netdev parsing Daniel P. Berrange
2016-10-20 7:38 ` Markus Armbruster
2016-10-20 13:43 ` [Qemu-devel] [Qemu-block] " Eric Blake
2016-09-30 14:45 ` [Qemu-devel] [PATCH v14 21/21] qapi: delete unused OptsVisitor code Daniel P. Berrange
2016-09-30 15:45 ` [Qemu-devel] [PATCH v14 00/21] QAPI/QOM work for non-scalar object properties no-reply
2016-09-30 18:50 ` Eric Blake
2016-10-21 18:30 ` 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=877f945ley.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=afaerber@suse.de \
--cc=berrange@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.