From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: Re: Extraneous nesting in QAPI schema
Date: Fri, 17 Jan 2020 07:47:42 -0600 [thread overview]
Message-ID: <aab70b86-8b0c-5058-c7f6-21ab3d352d46@redhat.com> (raw)
In-Reply-To: <87r214qk98.fsf@dusky.pond.sub.org>
On 12/16/19 10:59 AM, Markus Armbruster wrote:
> Extra nesting is merely another set of braces in QMP. It's bloody
> annoying in QAPIfied CLI using dotted keys syntax. Example:
>
> QMP command
>
> {"execute": "chardev-add",
<snipped, but concur>
> Let's start with trying to understand the sources of extra nesting.
>
> The obvious source of nesting is struct members of struct or union type.
> The example above has two: backend and backend.data.addr.
>
> This kind of nesting can sometimes be avoided by making the member
> (struct) type a base type of the containing type. Possible when we can
> arrange the base types into a single chain. In the example above, we'd
> make the implicit argument type of chardev-add explicit, then replace
> member 'backend': 'ChardevBackend' by 'base': 'ChardevBackend'.
>
> A more general solution would be adding "unboxed" members to the schema
> language. A member that is normally a JSON object on the wire would
> instead have its JSON object members "spliced in". Worth the trouble?
> Not sure.
It may also be possible to permit a discriminated union to be the branch
value of yet another discriminated union: as long as the set of member
names made visible by the inner union do not collide with any of the
visible members elsewhere in the outer union, this should be okay, and
give the same effect of being an unboxed member.
>
> Special case: &rest arguments. Example 1: object-add argument @props:
>
> {"execute": "object-add",
> "arguments": {
> "qom-type": "memory-backend-file",
> "id": "shmmem-shmem0",
> "props": {"mem-path": "/dev/shm/my_shmem0",
> "size":4194304,
> "share":true}}}
>
> Example 2:
>
> {"execute": "device_add",
> "arguments": {
> "driver": "virtio-scsi-pci",
> "bus": "pci.0",
> "id": "virtio_scsi_pci2",
> "addr": "0xb"}}
>
> object-add wraps the properties in an object. Device_add doesn't, but
> it needs to bypass the generated marshaller with 'gen': false. We could
> add support for &rest arguments to the schema language. Worth the
> trouble? Not sure.
>
> Another source is "simple" unions. Both backend and backend.data.addr
> are actually "simple" unions, giving rise to backend.data and
> backend.data.addr.data.
>
> We wouldn't use "simple" unions today. With "flat" unions, we'd avoid
> the .data.
>
> How widespread are "simple" unions today? Let's have a look. Five
> occur as command arguments:
>
> * ChardevBackend
>
> Used for command chardev-add and chardev-change argument @backend.
>
> * SocketAddressLegacy
>
> Used for command nbd-server-start argument @addr, and in command
> chardev-add and chardev-change argument @backend.
I really want to improve at least nbd-server-start to avoid the nesting
(it was a pain to use that much nesting while working on incremental
backup).
>
> * TransactionAction
>
> Used for command transaction argument @actions.
>
> * KeyValue
>
> Used for command send-key argument @keys, and in InputEvent (next
> item)
>
> * InputEvent
>
> Used for command input-send-event argument @events.
>
> Six commands: chardev-add, chardev-change, nbd-server-start,
> transaction, send-key, input-send-event. Could be worse.
>
> Flattening could be done in at least two ways. One, replace the nested
> commands by flat ones, deprecate. Two, make the existing commands
> accept both nested and flat, deprecate use of nested. Two is more
> difficult.
Agree that two is more difficult. For at least nbd-server-start, I'm
fine with replace-and-deprecate.
>
> Name clashes could prevent the flattening. I haven't checked for them.
>
> Three more "simple" unions appear to occur only in results:
>
> * ImageInfoSpecific
>
> Occurs in value of commands query-named-block-nodes and query-block.
>
> * MemoryDeviceInfo
>
> Occurs in value of command query-memory-devices.
>
> * TpmTypeOptions
>
> Occurs in value of command query-tpm.
>
> There, the only way to get rid of nesting is replace & deprecate.
>
> I'd love to eliminate "simple" unions from the schema language.
> Possible because any "simple" union can also be expressed as a flat
> union.
And less special code to maintain.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
prev parent reply other threads:[~2020-01-17 13:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-16 16:59 Extraneous nesting in QAPI schema Markus Armbruster
2020-01-16 17:56 ` Christophe de Dinechin
2020-01-17 13:47 ` Eric Blake [this message]
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=aab70b86-8b0c-5058-c7f6-21ab3d352d46@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).