Description of problem: Daemons commonly provide a --pidfile option where the process identifier is written when the daemon starts. This can be used to prevent multiple instances of a daemon from being started accidentally and it is also used for sending signals such as SIGTERM or SIGUSR1 to the running daemon. Richard Jones <rjones> noticed that this feature was missing from qemu-storage-daemon but present in qemu-system-x86_64. While it is possible to perform daemon shutdown using the QMP socket, it is easier to use the pidfile in cases where the process wishing to initiate shutdown does not have the QMP socket open or does not want to implement QMP. Version-Release number of selected component (if applicable): QEMU 5.2 lacks qemu-storage-daemon --pidfile.
Another case for this is to ensure that the server has started listening on the socket (so note the server must socket/bind/listen before writing the pidfile). The idea is you can poll for creation of the pidfile and then immediately connect to the socket. The command I was running was: qemu-storage-daemon --blockdev raw,file.driver=file,file.filename=/tmp/nbdftEX2V,node-name=disk0 --nbd-server addr.type=unix,addr.path=/tmp/sock --export nbd,node-name=disk0,id=nbd0,name=/ but we found that /tmp/sock (created by q-s-d) is not connectable until some short window after it has been created on disk.
FWIW with Stefan's and Dan's help I was able to do synchronization-free socket passing to qemu-storage-daemon. It was definitely not obvious and could do with some documentation. https://gitlab.com/nbdkit/libnbd/-/commit/89113f484effb0e6c322314ba75c1cbe07a04543
(I mean race-free rather than synchronization-free)
(In reply to Richard W.M. Jones from comment #2) > FWIW with Stefan's and Dan's help I was able to do synchronization-free > socket passing to qemu-storage-daemon. It was definitely not obvious and > could do with some documentation. > > https://gitlab.com/nbdkit/libnbd/-/commit/ > 89113f484effb0e6c322314ba75c1cbe07a04543 Thank you! I have submitted a documentation patch based on your Python code: https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg00222.html
I have posted a patch: https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg00236.html
Passed test on Red Hat Enterprise Linux release 8.5 Beta (Ootpa) 4.18.0-305.1.el8.x86_64 qemu-kvm-common-6.0.0-16.module+el8.5.0+10848+2dccc46d.x86_64 Test steps: 1.Check help message: qemu-storage-daemon -h --pidfile <path> write process ID to a file after startup 2.Miss path parameter qemu-storage-daemon --pidfile qemu-storage-daemon: option '--pidfile' requires an argument 3.give full parameter qemu-storage-daemon --pidfile /tmp/x.pid 4.pgrep -f qemu-storage-daemon and compare the content of pidfile, it should be same $ pgrep -f qemu-storage-daemon 449363 $ cat /tmp/x.pid 449363
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (virt:av bug fix and enhancement update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2021:4684