From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, "Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v15 05/23] qapi: Use strict QMP input visitor in more places
Date: Thu, 28 Apr 2016 08:28:09 -0600 [thread overview]
Message-ID: <57221DF9.1010201@redhat.com> (raw)
In-Reply-To: <871t5popb4.fsf@dusky.pond.sub.org>
[-- Attachment #1: Type: text/plain, Size: 6669 bytes --]
On 04/28/2016 07:06 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
>
>> Rather than having two separate ways to create a QMP input
>> visitor, where the safer approach has the more verbose name,
>> it is better to consolidate things into a single function
>> where the caller must explicitly choose whether to be strict
>> or to ignore excess input. Use strict mode in more places of
>> internal code (such as when cloning a QAPI struct in
>> util/socket.c, where the QObject better not have excess
>> input since it was just generated by qmp-output), while
>> documenting in user-facing code a question of whether we
>> should change our policy about ignoring excess input.
>
> Which external interface is this?
QMP qom-set, via object_property_set_qobject()
>
>>
>> In the case of qmp_object_add(), we intentionally switch to a
>> strict visitor; this matches the fact that the code for
>> user_creatable_add_type() is shared by both qmp_object_add()
>> (QMP input visitor) and by user_creatable_add_opts() (QemuOpts
>> visitor); the latter is always strict, so our usage in the
>> former should also be strict, so that both visits will
>> equally diagnose any excess input in a nested dict. But in
>> practice, we don't really have any -object where the
>> properties are a nested dict, and excess input at the top
>> level is already caught earlier by object_property_set() on
>> an unknown key, whether from QemuOpts:
>>
>> $ ./x86_64-softmmu/qemu-system-x86_64 -nographic -nodefaults -qmp stdio -object secret,id=sec0,data=letmein,format=raw,foo=bar
>> qemu-system-x86_64: Property '.foo' not found
>
> Let's update the error message now that the error message regression is
> fixed. Can do on commit.
>
Thanks. And now you know why I reported the regression.
>>
>> or from QMP:
>>
>> $ ./x86_64-softmmu/qemu-system-x86_64 -nographic -nodefaults -qmp stdio
>> {"QMP": {"version": {"qemu": {"micro": 93, "minor": 5, "major": 2}, "package": ""}, "capabilities": []}}
>> {"execute":"qmp_capabilities"}
>> {"return": {}}
>> {"execute":"object-add","arguments":{"qom-type":"secret","id":"sec0","props":{"format":"raw","data":"letmein","a":1}}}
>> {"error": {"class": "GenericError", "desc": "Property '.a' not found"}}
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>
> Should we split this into a patch to change the interface, and one or
> more separate patches to switch to the strict visitor? Could result in
> clearer and more complete commit messages.
Could do.
>> +++ b/qom/qom-qobject.c
>> @@ -22,7 +22,8 @@ void object_property_set_qobject(Object *obj, QObject *value,
>> const char *name, Error **errp)
>> {
>> QmpInputVisitor *qiv;
>> - qiv = qmp_input_visitor_new(value);
>> + /* TODO: Should we reject, rather than ignore, excess input? */
>> + qiv = qmp_input_visitor_new(value, false);
>> object_property_set(obj, qmp_input_get_visitor(qiv), name, errp);
>>
>> qmp_input_visitor_cleanup(qiv);
>
> Stay lenient, but document this should perhaps switch to strict. The
> commit message hints at this one.
"hints at" and "explicitly mentions by name" are two different things, I
get your point that my commit message could have been better.
>> +++ b/replay/replay-input.c
>> @@ -37,7 +37,7 @@ static InputEvent *qapi_clone_InputEvent(InputEvent *src)
>> return NULL;
>> }
>>
>> - qiv = qmp_input_visitor_new(obj);
>> + qiv = qmp_input_visitor_new(obj, true);
>> iv = qmp_input_get_visitor(qiv);
>> visit_type_InputEvent(iv, NULL, &dst, &error_abort);
>> qmp_input_visitor_cleanup(qiv);
>
> Switch to strict. Not mentioned in commit message. Why is it a good
> idea?
Same category as util/qemu-sockets.c: when cloning, we shouldn't be
introducing any junk from the QObject just produced from the qmp-output
visitor. (Hmm, that also means that when cloning, we are now doing MORE
work to check for a "can't happen" condition - but it all goes away in a
later patch when I introduce a real cloning visitor that is more
efficient than a round-trip qmp-output => qmp-input double pass - so
maybe on that grounds, I don't need to convert this or the
qemu-sockets.c case)
>> +++ b/tests/test-qmp-commands.c
>> @@ -222,7 +222,7 @@ static void test_dealloc_partial(void)
>> ud2_dict = qdict_new();
>> qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text)));
>>
>> - qiv = qmp_input_visitor_new(QOBJECT(ud2_dict));
>> + qiv = qmp_input_visitor_new(QOBJECT(ud2_dict), true);
>> visit_type_UserDefTwo(qmp_input_get_visitor(qiv), NULL, &ud2, &err);
>> qmp_input_visitor_cleanup(qiv);
>> QDECREF(ud2_dict);
>
> Switch to strict. Not mentioned in commit message. Why is it a good
> idea?
Because it's a testsuite and still passes with stricter testing, thus
any future additions to the testsuite will exercise strict mode which is
what we want to use in more places.
>> +++ b/tests/test-qmp-input-visitor.c
>> @@ -51,7 +51,7 @@ static Visitor *visitor_input_test_init_internal(TestInputVisitorData *data,
>> data->obj = qobject_from_jsonv(json_string, ap);
>> g_assert(data->obj);
>>
>> - data->qiv = qmp_input_visitor_new(data->obj);
>> + data->qiv = qmp_input_visitor_new(data->obj, false);
>> g_assert(data->qiv);
>>
>> v = qmp_input_get_visitor(data->qiv);
>> diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
>
> Stay lenient (because we're testing it).
If we get rid of all lenient clients other than test-qmp-input-visitor,
then maybe lenient mode is worth nuking, and simplify our testsuite by
consolidating test-qmp-input-{visitor,strict}? But food for thought for
a later day.
>> +++ b/tests/test-visitor-serialization.c
>> @@ -1038,7 +1038,7 @@ static void qmp_deserialize(void **native_out, void *datap,
>> obj = qobject_from_json(qstring_get_str(output_json));
>>
>> QDECREF(output_json);
>> - d->qiv = qmp_input_visitor_new(obj);
>> + d->qiv = qmp_input_visitor_new(obj, true);
>> qobject_decref(obj_orig);
>> qobject_decref(obj);
>> visit(qmp_input_get_visitor(d->qiv), native_out, errp);
>
> Switch to strict. Not mentioned in commit message. Why is it a good
> idea?
Same argument as test-qmp-commands, and same flaw in the commit message
for not calling it out.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2016-04-28 14:28 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-28 0:01 [Qemu-devel] [PATCH v15 00/23] qapi visitor cleanups (post-introspection cleanups subset E) Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 01/23] qapi-visit: Add visitor.type classification Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 02/23] qapi: Guarantee NULL obj on input visitor callback error Eric Blake
2016-04-28 12:24 ` Markus Armbruster
2016-04-28 13:00 ` Eric Blake
2016-04-28 15:41 ` Eric Blake
2016-04-28 16:02 ` [Qemu-devel] [PATCH v15 02A/23] fixup! " Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 03/23] qmp: Drop dead command->type Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 04/23] qmp-input: Clean up stack handling Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 05/23] qapi: Use strict QMP input visitor in more places Eric Blake
2016-04-28 13:06 ` Markus Armbruster
2016-04-28 14:28 ` Eric Blake [this message]
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 06/23] qmp-input: Don't consume input when checking has_member Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 07/23] qapi-commands: Wrap argument visit in visit_start_struct Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 08/23] monitor: Let generated code validate arguments Eric Blake
2016-04-28 14:09 ` Markus Armbruster
2016-04-28 14:39 ` Marc-André Lureau
2016-04-28 18:00 ` Markus Armbruster
2016-04-28 18:58 ` Eric Blake
2016-04-28 14:47 ` Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 09/23] qom: Wrap prop visit in visit_start_struct Eric Blake
2016-04-28 14:46 ` Markus Armbruster
2016-04-28 15:14 ` Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 10/23] qmp-input: Require struct push to visit members of top dict Eric Blake
2016-04-28 15:00 ` Markus Armbruster
2016-04-28 15:04 ` Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 11/23] qmp-input: Refactor when list is advanced Eric Blake
2016-04-28 15:19 ` Markus Armbruster
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 12/23] qapi: Document visitor interfaces, add assertions Eric Blake
2016-04-28 16:34 ` Markus Armbruster
2016-04-28 19:02 ` Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 13/23] tests: Add check-qnull Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 14/23] qapi: Add visit_type_null() visitor Eric Blake
2016-04-28 16:40 ` Markus Armbruster
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 15/23] qmp: Support explicit null during visits Eric Blake
2016-04-28 16:50 ` Markus Armbruster
2016-04-28 19:07 ` Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 16/23] spapr_drc: Expose 'null' in qom-get when there is no fdt Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 17/23] qmp: Add qmp_output_visitor_reset() Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 18/23] qmp: Tighten output visitor rules Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 19/23] qapi: Split visit_end_struct() into pieces Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 20/23] tests/string-input-visitor: Add negative integer tests Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 21/23] qapi: Fix string input visitor handling of invalid list Eric Blake
2016-04-28 17:18 ` Markus Armbruster
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 22/23] qapi: Simplify semantics of visit_next_list() Eric Blake
2016-04-28 15:44 ` Eric Blake
2016-04-28 0:01 ` [Qemu-devel] [PATCH v15 23/23] qapi: Change visit_type_FOO() to no longer return partial objects Eric Blake
2016-04-28 17:42 ` Markus Armbruster
2016-04-28 18:03 ` [Qemu-devel] [PATCH v15 00/23] qapi visitor cleanups (post-introspection cleanups subset E) 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=57221DF9.1010201@redhat.com \
--to=eblake@redhat.com \
--cc=afaerber@suse.de \
--cc=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=mdroth@linux.vnet.ibm.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 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.