qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Kevin Wolf" <kwolf@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Cc: "xiaoqiang zhao" <zxq_yx_007@163.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-devel@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: Our abstract UNIX domain socket support is a mess
Date: Thu, 29 Oct 2020 13:47:02 -0500	[thread overview]
Message-ID: <c52b8cd0-feea-a7ca-fe95-47112a4c36b1@redhat.com> (raw)
In-Reply-To: <20201029160744.GB6271@merkur.fritz.box>

On 10/29/20 11:07 AM, Kevin Wolf wrote:

>>>
>>> QEMU's interface is differently messy.
>>>
>>> Our equivalent to struct sockaddr_un is QAPI type UnixSocketAddress:
>>>
>>>     { 'struct': 'UnixSocketAddress',
>>>       'data': {
>>>         'path': 'str' }
>>>
>>> @path corresponds to sockaddr_un member sun_path.  sun_family = AF_UNIX
>>> and socklen_t sizeof(sockaddr_un) are implied.
>>>
>>> We didn't repurpose @path for abstract sockets like the Linux kernel did
>>> with sun_path.  Instead, we added a flag @abstract (default false).
>>> When it's on, we make a binary blob by prefixing @path with a 0 byte,
>>> and pad it with more 0 bytes.
>>>
>>> We added a second flag @tight (default true) to optionally cut the
>>> socklen_t to the end of the string (the terminating 0 byte is not
>>> included).
>>>

> Using magic characters in strings to distinguish different types of
> objects is always wrong in QAPI. If we interpreted leading '@' this way,
> you wouldn't be able to specify a relative filename starting with '@'
> any more.
> 
>> Or, just or by having  explicit flags "abstract" and "tight" to
>> control the behaviour.  The latter is what 'socat' does to allow
>> use of abstract sockets.
>>
>> For QEMU the former approach gives broad interoperabiltiy with
>> userspace applications, so made more sense than using magic "@".
> 
> Boolean flags to distinguish different types are better than parsing
> strings, but still not optimal. Documentation like "only matters for
> abstract sockets" is another hint that we're treating things the same
> that aren't the same.

But why two boolean flags for three sensible states (where it is unclear
if the fourth combination that makes no sense is silently accepted or
loudly rejected), instead of a single tri-state-valued enum?

> 
> The proper way to distinguish two different types is unions. So I think
> the ideal interface would be another SocketAddress variant that could
> then also use base64 instead of str to represent arbitrary blobs, like
> Markus suggested below.
> 
> Probably too late now.

Sadly, you are probably right that we are a bit late to be rethinking
what we expose, since 5.1 is released.

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



  reply	other threads:[~2020-10-29 18:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28 12:41 Our abstract UNIX domain socket support is a mess Markus Armbruster
2020-10-29 14:02 ` Daniel P. Berrangé
2020-10-29 16:07   ` Kevin Wolf
2020-10-29 18:47     ` Eric Blake [this message]
2020-10-30  9:16       ` Daniel P. Berrangé
2020-10-30 10:30     ` 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=c52b8cd0-feea-a7ca-fe95-47112a4c36b1@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zxq_yx_007@163.com \
    /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).