From: Peter Delevoryas <peter@pjd.dev>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: jsnow@redhat.com, crosa@redhat.com, bleal@redhat.com,
f4bug@amsat.org, wainersm@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 1/1] python/machine: Fix AF_UNIX path too long on macOS
Date: Thu, 21 Jul 2022 19:44:21 -0700 [thread overview]
Message-ID: <YtoPBYGmSNfeT1Ot@pdel-mbp> (raw)
In-Reply-To: <YtUgMTYSQjm9O+u4@redhat.com>
On Mon, Jul 18, 2022 at 09:56:17AM +0100, Daniel P. Berrangé wrote:
> On Sat, Jul 16, 2022 at 10:34:34AM -0700, Peter Delevoryas wrote:
> > On macOS, private $TMPDIR's are the default. These $TMPDIR's are
> > generated from a user's unix UID and UUID [1], which can create a
> > relatively long path:
> >
> > /var/folders/d7/rz20f6hd709c1ty8f6_6y_z40000gn/T/
> >
> > QEMU's avocado tests create a temporary directory prefixed by
> > "avo_qemu_sock_", and create QMP sockets within _that_ as well.
> > The QMP socket is unnecessarily long, because a temporary directory
> > is created for every QEMUMachine object.
> >
> > /avo_qemu_sock_uh3w_dgc/qemu-37331-10bacf110-monitor.sock
>
>
> Looking at this again, I realize my suggestion for dealing with the
> second part of the path was mistaken.
>
> The "qemu-37331-10bacf110-monitor.sock" part is combining two
> pieces.
>
> First the result of
>
> f"qemu-{os.getpid()}-{id(self):02x}"
>
> is
>
> qemu-37331-10bacf110
>
> and the code later than appends '-monitor.sock'
>
> So...
>
> >
> > The path limit for unix sockets on macOS is 104: [2]
> >
> > /*
> > * [XSI] Definitions for UNIX IPC domain.
> > */
> > struct sockaddr_un {
>
> > unsigned char sun_len; /* sockaddr len including null */
> > sa_family_t sun_family; /* [XSI] AF_UNIX */
> > char sun_path[104]; /* [XSI] path name (gag) */
> > };
> >
> > This results in avocado tests failing on macOS because the QMP unix
> > socket can't be created, because the path is too long:
> >
> > ERROR| Failed to establish connection: OSError: AF_UNIX path too long
> >
> > This change reduces the size of both paths, and removes the unique
> > identification information from the socket name, since it seems to be
> > unnecessary.
> >
> > This commit produces paths like the following:
> >
> > pdel@pdel-mbp:/var/folders/d7/rz20f6hd709c1ty8f6_6y_z40000gn/T
> > $ tree qemu*
> > qemu_oc7h7f3u
> > ├── qmp-console.sock
> > └── qmp-monitor.sock
> >
> > [1] https://apple.stackexchange.com/questions/353832/why-is-mac-osx-temp-directory-in-weird-path
> > [2] /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/sys/un.h
> >
> > Signed-off-by: Peter Delevoryas <peter@pjd.dev>
> > ---
> > python/qemu/machine/machine.py | 2 +-
> > tests/avocado/avocado_qemu/__init__.py | 2 +-
> > 2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/python/qemu/machine/machine.py b/python/qemu/machine/machine.py
> > index 37191f433b..b1823966b3 100644
> > --- a/python/qemu/machine/machine.py
> > +++ b/python/qemu/machine/machine.py
> > @@ -157,7 +157,7 @@ def __init__(self,
> > self._wrapper = wrapper
> > self._qmp_timer = qmp_timer
> >
> > - self._name = name or f"qemu-{os.getpid()}-{id(self):02x}"
> > + self._name = name or "qmp"
>
> ...my suggestion here was wrong.
>
> We don't need the os.getpid() unoiqueness because the tmpdir already
> ensures that is safe, but keeping 'id(self)' is a good idea, if the
> test case creates multiple machines concurrently. Bearing in mind we
> later append '-monitor.sock' we don't need 'qmp' in the self._name.
>
> So on reflection I think I should have suggested using:
>
> self._name = name or f"{id(self):02x}"
>
> And *in addition*, a few lines later change:
>
> self._monitor_address = os.path.join(
> self.sock_dir, f"{self._name}-monitor.sock"
> )
>
> To
>
> self._monitor_address = os.path.join(
> self.sock_dir, f"{self._name}.qmp"
> )
>
Finally getting back to this (sorry, been working on other stuff), and I noticed
the console socket is just below this:
self._console_address = os.path.join(
self.sock_dir, f"{self._name}-console.sock"
)
So I probably shouldn't do the "-monitor.sock" change right?
That's ok though, the other changes are sufficient to fix the problem. I'll give
you a chance to reply to this email, or else I'll just send a v3 that doesn't
include the -monitor.sock change.
Thanks,
Peter
>
>
> > diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py
> > index ed4853c805..43b8c8848c 100644
> > --- a/tests/avocado/avocado_qemu/__init__.py
> > +++ b/tests/avocado/avocado_qemu/__init__.py
> > @@ -296,7 +296,7 @@ def require_accelerator(self, accelerator):
> > "available" % accelerator)
> >
> > def _new_vm(self, name, *args):
> > - self._sd = tempfile.TemporaryDirectory(prefix="avo_qemu_sock_")
> > + self._sd = tempfile.TemporaryDirectory(prefix="qemu_")
>
> This bit is fine.
>
> > vm = QEMUMachine(self.qemu_bin, base_temp_dir=self.workdir,
> > sock_dir=self._sd.name, log_dir=self.logdir)
> > self.log.debug('QEMUMachine "%s" created', name)
>
> With regards,
> Daniel
> --
> |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o- https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
>
next prev parent reply other threads:[~2022-07-22 2:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-16 17:34 [PATCH v2 0/1] python/machine: Fix AF_UNIX path too long on macOS Peter Delevoryas
2022-07-16 17:34 ` [PATCH v2 1/1] " Peter Delevoryas
2022-07-18 8:56 ` Daniel P. Berrangé
2022-07-18 18:22 ` Peter Delevoryas
2022-07-22 2:44 ` Peter Delevoryas [this message]
2022-07-22 7:20 ` Daniel P. Berrangé
2022-07-22 18:06 ` Peter Delevoryas
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=YtoPBYGmSNfeT1Ot@pdel-mbp \
--to=peter@pjd.dev \
--cc=berrange@redhat.com \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=f4bug@amsat.org \
--cc=jsnow@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wainersm@redhat.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).