From: Eric Blake <eblake@redhat.com>
To: "Kővágó, Zoltán" <dirty.ice.hu@gmail.com>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH 7/7] qapi: support nested structs in OptsVisitor
Date: Thu, 17 Sep 2015 15:24:22 -0600 [thread overview]
Message-ID: <55FB2F86.1040407@redhat.com> (raw)
In-Reply-To: <828b3ad8c9f32d5938f39068328d0794cfd9abf4.1441627176.git.DirtY.iCE.hu@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4840 bytes --]
On 09/07/2015 06:14 AM, Kővágó, Zoltán wrote:
> The current OptsVisitor flattens the whole structure, if there are same
> named fields under different paths (like `in' and `out' in `Audiodev'),
> the current visitor can't cope with them (for example setting
> `frequency=44100' will set the in's frequency to 44100 and leave out's
> frequency unspecified).
>
> This patch fixes it, by always requiring a complete path in case of
> nested structs. Fields in the path are separated by dots, similar to C
> structs (without pointers), like `in.frequency' or `out.frequency'.
>
> You must provide a full path even in non-ambiguous cases. The qapi
> flattening commits hopefully ensures that this change doesn't create
> backward compatibility problems.
It's the "hopefully" that worries me.
If I understand correctly, prior to this series, we have several
instances of qapi simple unions, where a member is a substruct when
converting to QObject. Conceptually:
{ 'struct':'Sub', 'data':{ 'c':'int' } }
{ 'union':'Main', 'data':{ 'X':'Sub' } }
would accept the following QDict:
{ "type":"X", "data":{ "c":1 } }
and directly translating that to QemuOpts would be spelled:
-opt type=X,data.c=1
but we wanted shorthand:
-opt type=X,c=1
So, the "flattening" that opts-visitor does is what allows "c" instead
of "data.c" to refer to a nested member of a union. It worked as long
as 'c' appeared only once per visit of the overall qapi type (multiple
branches of the union may have 'c', but for a given union branch, 'c'
appears only once no matter what depth of substructs it is reached through).
Question: do we actually ALLOW the user to specify data.c, or do we ONLY
accept the shorthand?
This series then proceeds to teach opts-visitor how to handle flat
unions. Converting the above example to a flat union is done by:
{ 'enum':'Foo', 'data':['X'] }
{ 'struct':'Base', 'data':{ 'type':'Foo' } }
{ 'struct':'Sub', 'data':{ 'c':'int' } }
{ 'union':'Main', 'base':'Base', 'discriminator':'type',
'data':{ 'X':'Sub' } }
which now accepts the following QDict:
{ "type":"X", "c":1" }
(note the loss of the nested 'data' struct), and directly translating
that to QemuOpts would be spelled:
-opt type=X,c=1
which exactly matches the shorthand that we previously accepted. It
completely gets rid of the data.c longhand, but I don't know if we
accepted that in the first place.
So, the next question is whether we still need flattening. If we no
longer have any simple unions parsed by QemuOpts, then the flattening no
longer helps us. Furthermore, you have a case in audio where flattening
hurts; the QDict:
{ "in":{ "frequency":4400 }, "out":{ "frequency":4400 } }
has unambiguous paths 'in.frequency' and 'out.frequency', but the
shorthand 'frequency' could now match two separate places in the struct.
Now, let's look at what your testsuite changes say about this patch:
> @@ -271,6 +299,12 @@ main(int argc, char **argv)
> add_test("/visitor/opts/i64/range/2big/full", &expect_fail,
> "i64=-0x8000000000000000-0x7fffffffffffffff");
>
> + /* Test nested structs support */
> + add_test("/visitor/opts/nested/unqualified", &expect_fail, "nint=13");
You are saying that an unqualified member no longer resolves (that is,
when nesting is in place, we MUST spell it by the long name);
> + add_test("/visitor/opts/nested/both", &expect_both,
> + "sub0.nint=13,sub1.nint=17");
> + add_test("/visitor/opts/nested/sub0", &expect_sub0, "sub0.nint=13");
> + add_test("/visitor/opts/nested/sub1", &expect_sub1, "sub1.nint=13");
and that using qualified names gets at the nested struct members as
desired. Furthermore, if we truly have converted ALL qapi unions to
flat unions, and if qapi unions were the ONLY reason that we had
flattening in the first place, and if we did NOT accept longhand
'data.c=1' for the flattened shorthand of 'c=1' within a simple union
branch, then it looks like you are 100% backwards-compatible. But
that's quite a few things to verify. Also, I'm not sure if your visitor
approaches the change of no longer flattening things in the most
efficient manner (I still haven't studied the rest of the patch closely).
I'd like to defer reviewing this until the qapi patch queue is not quite
so long, but the premise behind it is appealing. However, I strongly
recommend that the commit message be improved to cover some of the
background that I spelled out here, as well as offering more proof than
just "hopefully", and an analysis of whether we are breaking any
longhand data.c=1 option spellings.
--
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:[~2015-09-17 21:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-07 12:08 [Qemu-devel] [PATCH 0/7] qapi-flattening and preparation of -audiodev option Kővágó, Zoltán
2015-09-07 12:08 ` [Qemu-devel] [PATCH 1/7] qapi: support implicit structs in OptsVisitor Kővágó, Zoltán
2015-09-17 20:30 ` Eric Blake
2015-09-18 12:26 ` Eric Blake
2015-09-07 12:08 ` [Qemu-devel] [PATCH 2/7] qapi: convert NumaOptions into a flat union Kővágó, Zoltán
2015-09-09 15:42 ` Eduardo Habkost
2015-09-07 12:08 ` [Qemu-devel] [PATCH 3/7] net: remove NetLegacy struct Kővágó, Zoltán
2015-09-15 14:54 ` Eric Blake
2015-09-07 12:14 ` [Qemu-devel] [PATCH 4/7] net: use Netdev instead of NetClientOptions in client init Kővágó, Zoltán
2015-09-09 15:46 ` Eric Blake
2015-09-07 12:14 ` [Qemu-devel] [PATCH 5/7] qapi: change Netdev into a flat union Kővágó, Zoltán
2015-09-17 20:41 ` Eric Blake
2015-09-07 12:14 ` [Qemu-devel] [PATCH 6/7] qapi: reorder NetdevBase and Netdev Kővágó, Zoltán
2015-09-17 20:42 ` Eric Blake
2015-09-07 12:14 ` [Qemu-devel] [PATCH 7/7] qapi: support nested structs in OptsVisitor Kővágó, Zoltán
2015-09-17 21:24 ` Eric Blake [this message]
2015-09-17 22:01 ` Kővágó Zoltán
2015-09-14 12:34 ` [Qemu-devel] [PATCH 0/7] qapi-flattening and preparation of -audiodev option 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=55FB2F86.1040407@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=dirty.ice.hu@gmail.com \
--cc=mdroth@linux.vnet.ibm.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.