Bug 1932785

Summary: [RFE] Add --pidfile option to qemu-storage-daemon
Product: Red Hat Enterprise Linux Advanced Virtualization Reporter: Stefan Hajnoczi <stefanha>
Component: qemu-kvmAssignee: Stefan Hajnoczi <stefanha>
qemu-kvm sub component: Storage QA Contact: qing.wang <qinwang>
Status: CLOSED ERRATA Docs Contact:
Severity: medium    
Priority: high CC: coli, ddepaula, jinzhao, juzhang, kwolf, rjones, virt-maint
Version: 8.2Keywords: FutureFeature, RFE, Triaged
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 8.4   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: qemu-kvm-6.0.0-16.module+el8.5.0+10848+2dccc46d Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-16 07:51:47 UTC Type: Feature Request
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1901323    
Bug Blocks:    

Description Stefan Hajnoczi 2021-02-25 09:19:06 UTC
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.

Comment 1 Richard W.M. Jones 2021-02-25 11:29:36 UTC
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.

Comment 2 Richard W.M. Jones 2021-02-25 16:29:08 UTC
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

Comment 3 Richard W.M. Jones 2021-02-25 16:30:27 UTC
(I mean race-free rather than synchronization-free)

Comment 6 Stefan Hajnoczi 2021-03-01 15:36:52 UTC
(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

Comment 7 Stefan Hajnoczi 2021-03-01 16:33:05 UTC
I have posted a patch:
https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg00236.html

Comment 14 qing.wang 2021-05-17 02:35:03 UTC
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

Comment 16 errata-xmlrpc 2021-11-16 07:51:47 UTC
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