From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, lvivier@redhat.com,
"Andreas Färber" <afaerber@suse.de>,
qemu-stable@nongnu.org,
"Eduardo Otubo" <eduardo.otubo@profitbricks.com>,
"David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 2/3] qom: Avoid unvisited 'id'/'qom-type' in user_creatable_add_opts
Date: Wed, 22 Mar 2017 07:42:24 +0100 [thread overview]
Message-ID: <87efxpersf.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20170322023820.10772-3-eblake@redhat.com> (Eric Blake's message of "Tue, 21 Mar 2017 21:38:19 -0500")
Eric Blake <eblake@redhat.com> writes:
> A regression in commit 15c2f669e caused us to silently ignore
> excess input to the QemuOpts visitor. Later, commit ea4641
> accidentally abused that situation, by removing "qom-type" and
> "id" from the corresponding QDict but leaving them defined in
> the QemuOpts, when using the pair of containers to create a
> user-defined object. Note that since we are already traversing
> two separate items (a QDict and a QemuOpts), we are already
> able to flag bogus arguments, as in:
>
> $ ./x86_64-softmmu/qemu-system-x86_64 -nodefaults -nographic -qmp stdio -object memory-backend-ram,id=mem1,size=4k,bogus=huh
> qemu-system-x86_64: -object memory-backend-ram,id=mem1,size=4k,bogus=huh: Property '.bogus' not found
>
> So the only real concern is that when we re-enable strict checking
> in the QemuOpts visitor, we do not want to start flagging the two
> leftover keys as unvisited. Rearrange the code to clean out the
> QemuOpts listing in advance, rather than removing items from the
> QDict. Since "qom-type" is usually an automatic implicit default,
> we don't have to restore it; but "id" has to be put back (requiring
> us to cast away a const).
This is a yet another example of how actual configuration can easily
diverge from the one in QemuOpts. Discussed recently in:
Subject: Re: [PATCH 0/2] add writeconfig command on monitor
Message-ID: <87k28qlca9.fsf@dusky.pond.sub.org>
https://lists.gnu.org/archive/html/qemu-devel/2017-02/msg03476.html
Not putting "qom-type" back here is okay. Putting it back would also be
okay. I guess what you prefer depends on your level of OCD.
> CC: qemu-stable@nongnu.org
> Signed-off-by: Eric Blake <eblake@redhat.com>
>
> ---
> v2: new patch
> ---
> qom/object_interfaces.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index 03a95c3..cc9a694 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -114,7 +114,7 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
> QDict *pdict;
> Object *obj;
> const char *id = qemu_opts_id(opts);
> - const char *type = qemu_opt_get(opts, "qom-type");
> + char *type = qemu_opt_get_del(opts, "qom-type");
>
> if (!type) {
> error_setg(errp, QERR_MISSING_PARAMETER, "qom-type");
> @@ -125,14 +125,15 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
> return NULL;
> }
>
> + qemu_opts_set_id(opts, NULL);
> pdict = qemu_opts_to_qdict(opts, NULL);
> - qdict_del(pdict, "qom-type");
> - qdict_del(pdict, "id");
>
> v = opts_visitor_new(opts);
> obj = user_creatable_add_type(type, id, pdict, v, errp);
> visit_free(v);
>
> + qemu_opts_set_id(opts, (char *) id);
> + g_free(type);
> QDECREF(pdict);
> return obj;
> }
Aside: I dislike how this converts QemuOpts to QDict so
user_creatable_add_type() can use the QDict to guide the visit.
Awkward, as so much code that uses QemuOpts in not entirely
straightforward ways.
next prev parent reply other threads:[~2017-03-22 6:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-22 2:38 [Qemu-devel] [PATCH v2 for-2.9 0/3] Fix QemuOpts regression on bogus keys Eric Blake
2017-03-22 2:38 ` [Qemu-devel] [PATCH v2 1/3] tests: Expose regression in QemuOpts visitor Eric Blake
2017-03-22 2:38 ` [Qemu-devel] [PATCH v2 2/3] qom: Avoid unvisited 'id'/'qom-type' in user_creatable_add_opts Eric Blake
2017-03-22 6:42 ` Markus Armbruster [this message]
2017-03-22 2:38 ` [Qemu-devel] [PATCH v2 3/3] qapi: Fix QemuOpts visitor regression on unvisited input Eric Blake
2017-03-22 6:47 ` Markus Armbruster
2017-03-22 13:13 ` Eric Blake
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=87efxpersf.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=afaerber@suse.de \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo.otubo@profitbricks.com \
--cc=lvivier@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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.