On 9/24/19 3:31 AM, Vladimir Sementsov-Ogievskiy wrote:
+def qemu_nbd_popen(*args):
+ '''Run qemu-nbd in daemon mode and return the parent's exit code'''
+ return subprocess.Popen(qemu_nbd_args + ['--persistent'] + list(args))
+
Should you also use a pid file here, and wait for the existence of the
pid file before returning (rather than hard-coding sleep(1))?
What do you mean / how to do it?
We want to wait until listening socket is prepared..
In shell:
qemu-nbd --pid-file=/path/to/file ...
while [ ! -e /path/to/file ]; do
sleep ... # fractional second, or exponential, or whatever...
done
# Now the listening socket is indeed prepared
You'd have to translate that idiom to python.
Or:
pre-open Unix socket at /path/to/socket
LISTEN_PID=... LISTEN_FDS=1 qemu-nbd ... 3<>/path/to/socket
Now the socket is pre-created and passed into qemu-nbd via systemd
socket activation, so you know the listening socket is ready without
having to do any loop at all. Here's a patch in libnbd where we just
switched from waiting for the port to appear (because the test predated
qemu-nbd pidfile support) to instead using socket activation, for reference:
https://github.com/libguestfs/libnbd/commit/352331d177
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org