On 6/5/19 2:48 PM, Eric Blake wrote: > This also made me wonder if we should start a deprecation clock to > improve the nbd-server-start command to use SocketAddress instead of > SocketAddressLegacy. If we revive Max's work on implementing a default > branch for a union discriminator > (https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg01682.html), > we could have something like:
Re-reading that thread, I see that Markus was arguing for a slightly
different QAPI syntax than Max's proposal, basically:
>
> { 'enum': 'NbdSocketAddressHack',
> 'data': [ 'legacy', 'inet', 'unix' ] }
> { 'struct': 'NbdServerAddrLegacy',
> 'data': { 'addr', 'SocketAddressLegacy' } }
> { 'union': 'NbdServerAddr',
> 'base': { 'type': 'NbdSocketAddressHack',
> '*tls-creds': 'str',
> '*tls-authz': 'str' },
> 'discriminator': 'type',
> 'default-variant': 'legacy',
> 'data': { 'legacy': 'NbdServerAddrLegacy',
> 'inet', 'InetSocketAddress',
> 'unix', 'UnixSocketAddress' } }
> { 'command', 'nbd-server-start', 'data': 'NbdServerAddr' }
{ 'union': 'NbdServerAddr',
'base': { '*type': { 'type': 'NbdSocketAddressHack',
'default': 'legacy' },
'*tls-creds', 'str', '*tls-authz', 'str' },
'discriminator': 'type',
'data': { 'legacy': 'NbdServerAddrLegacy',
'inet', 'InetSocketAddress',
'unix', 'UnixSocketAddress' } }
>
> which should be backwards compatible with the existing:
>
> { "execute": "nbd-server-start", "arguments": {
> "tls-authz": "authz0",
> "addr": { "type": "inet", "data": {
> "host": "localhost", "port": "10809" } } } }
>
> by relying on the discriminator's default expansion to:
>
> { "execute": "nbd-server-start", "arguments": {
> "tls-authz": "authz0",
> "type": "legacy",
> "addr": { "type": "inet", "data": {
> "host": "localhost", "port": "10809" } } } }
But this part remains true - if a flat union has an optional
discriminator, then the discriminator must include a default value,
where omitting the discriminator then results in sane expansion, and
where a careful choice of discriminator default allows legacy syntax to
co-exist with new preferred syntax.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
