All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kővágó Zoltán" <dirty.ice.hu@gmail.com>
To: Eric Blake <eblake@redhat.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: Fri, 18 Sep 2015 00:01:41 +0200	[thread overview]
Message-ID: <55FB3845.2030704@gmail.com> (raw)
In-Reply-To: <55FB2F86.1040407@redhat.com>

2015-09-17 23:24 keltezéssel, Eric Blake írta:
> 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?

The current implementation in qemu only allows the shorthand version, in 
fact it doesn't even care about the name of the parent struct/union. 
Neither Main nor Sub has a field names 'data.c', so the data.c=1 version 
is currently invalid.  But the problem is, as you noted, it only works 
if each field name is unique in the whole visited type (excluding 
non-visited union branches).

> 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.

No, data.c was never valid.

> 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.

This is why exactly the flattening needs to be moved from OptsVisitor to 
somewhere else.  If the qapi structs are flattened, old options (-net, 
-numa) continue to work as before, while at allows -audiodev to specify 
in.frequency and out.frequency.  Of course, this isn't the only possible 
approach, but my previous attempt where I modified OptsVisitor instead 
to allow both shorthand and full paths were also problematic:

http://lists.nongnu.org/archive/html/qemu-devel/2015-06/msg04189.html

>
> 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.
>

  reply	other threads:[~2015-09-17 22:01 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
2015-09-17 22:01     ` Kővágó Zoltán [this message]
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=55FB3845.2030704@gmail.com \
    --to=dirty.ice.hu@gmail.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.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.