qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>,
	"Daniel P. Berrange" <berrange@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>, QEMU <qemu-devel@nongnu.org>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v1 2/2] char: allow passing pre-opened socket file descriptor at startup
Date: Thu, 21 Dec 2017 08:18:23 -0600	[thread overview]
Message-ID: <f32eb5df-b573-2813-1f2b-ec999f0fadd0@redhat.com> (raw)
In-Reply-To: <CAJ+F1C+R_q3CzR3yK2112gj9d_nsH2m=ajb3V60fqPPcziJRpw@mail.gmail.com>

On 12/21/2017 07:48 AM, Marc-André Lureau wrote:

>>       ChardevSocket *sock;
>> +    int num = 0;
>> +
>> +    if (path) {
>> +        num++;
>> +    }
>> +    if (fd) {
>> +        num++;
>> +    }
>> +    if (fdset) {
>> +        num++;
>> +    }
>> +    if (host) {
>> +        num++;
>> +    }
>> +    if (num != 1) {
>> +        error_setg(errp,
>> +                   "Exactly one of 'path', 'fd', 'fdset' or 'host' required");
>> +        return;
>> +    }
>>
> 
> That could be shorter ;)

Here's one way:

if (!!path + !!fd + !!fdset ++ !!host) {
     error_setg...

>> +++ b/qapi/common.json
>> @@ -74,6 +74,17 @@
>>   { 'enum': 'OnOffSplit',
>>     'data': [ 'on', 'off', 'split' ] }
>>
>> +##
>> +# @Int:
>> +#
>> +# A fat type wrapping 'int', to be embedded in lists.
>> +#
>> +# Since: 2.12
>> +##
>> +{ 'struct': 'Int',
>> +  'data': {
>> +    'i': 'int' } }
>> +

The documentation is odd - you need this type because flat unions 
require a struct rather than a native type for each branch, and not 
because you are embedding 'int' in lists (that is, we support ['int'] 
just fine; the documentation for other fat types pre-dates when we 
supported lists of native types).

>>   ##
>>   # @String:
>>   #
>> diff --git a/qapi/sockets.json b/qapi/sockets.json
>> index ac022c6ad0..f3cac02166 100644
>> --- a/qapi/sockets.json
>> +++ b/qapi/sockets.json
>> @@ -112,7 +112,8 @@
>>       'inet': 'InetSocketAddress',
>>       'unix': 'UnixSocketAddress',
>>       'vsock': 'VsockSocketAddress',
>> -    'fd': 'String' } }
>> +    'fd': 'String',
>> +    'fdset': 'Int' } }

This is SocketAddressLegacy, which is an old-style union.  Do we really 
want to be expanding it at this point in time?  Old-style unions support:

'fd':'str',
'fdset':'int'

except that we already used the fat 'String', so using the fat 'Int' is 
done for consistency more than anything else, if we really do want it 
added to this type.

Missing documentation of when the new branch types were added.

>>
>>   ##
>>   # @SocketAddressType:
>> @@ -123,10 +124,16 @@
>>   #
>>   # @unix:  Unix domain socket
>>   #
>> +# @vsock: VSOCK socket
>> +#
>> +# @fd: socket file descriptor passed over monitor
>> +#
>> +# @fdset: socket file descriptor passed via CLI (since 2.12)
>> +#
>>   # Since: 2.9
>>   ##
>>   { 'enum': 'SocketAddressType',
>> -  'data': [ 'inet', 'unix', 'vsock', 'fd' ] }
>> +  'data': [ 'inet', 'unix', 'vsock', 'fd', 'fdset' ] }

Hmm, good catch on the missing vsock documentation (SocketAddressType 
was named SocketAddressFlatType back in 2.9, but 'vsock' did exist back 
then).

>>
>>   ##
>>   # @SocketAddress:
>> @@ -144,4 +151,5 @@
>>     'data': { 'inet': 'InetSocketAddress',
>>               'unix': 'UnixSocketAddress',
>>               'vsock': 'VsockSocketAddress',
>> -            'fd': 'String' } }
>> +            'fd': 'String',
>> +            'fdset': 'Int' } }

Again, missing documentation on when the branch was added.

But here, you are absolutely correct that we need the fat 'Int' here, as 
this is a flat union, which requires a struct for each branch (not 
native scalar types).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

  reply	other threads:[~2017-12-21 14:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 13:27 [Qemu-devel] [PATCH v1 0/2] Enable passing pre-opened chardev socket FDs Daniel P. Berrange
2017-12-21 13:27 ` [Qemu-devel] [PATCH v1 1/2] io: move fd_is_socket() into common sockets code Daniel P. Berrange
2017-12-21 13:49   ` Marc-André Lureau
2017-12-21 13:27 ` [Qemu-devel] [PATCH v1 2/2] char: allow passing pre-opened socket file descriptor at startup Daniel P. Berrange
2017-12-21 13:48   ` Marc-André Lureau
2017-12-21 14:18     ` Eric Blake [this message]
2017-12-21 14:20   ` Daniel P. Berrange
2017-12-21 16:49   ` Markus Armbruster
2017-12-21 16:53     ` Daniel P. Berrange
2017-12-21 19:05     ` Eric Blake

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=f32eb5df-b573-2813-1f2b-ec999f0fadd0@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=marcandre.lureau@gmail.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 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).