04.10.2019 21:05, Eric Blake wrote:
> 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.

Don't see, how it is better than what I've done in 04.. But I can resend with 
this.
At least, the fact that socket is initialized before creating pid file is 
undocumented..

> 
> 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
> 

Hmm, I'm afraid I need more help in it, I don't know socket activation and 
googling for some time didn't help.
How to pre-open the socket? How to set LISTEN_PID? Looking at the code I see 
that activation path failed if
LISTEN_PID != getpid().. So I need to know qemu-nbd pid before starting it? o_O

-- 
Best regards,
Vladimir

Reply via email to