Received: from eggs.gnu.org ([2001:4830:134:3::10]:40913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnSDn-0000l9-1s for qemu-devel@nongnu.org; Fri, 23 Sep 2016 11:17:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnSDl-0004Oa-0p for qemu-devel@nongnu.org; Fri, 23 Sep 2016 11:17:01 -0400 References: <1472142645-7370-1-git-send-email-mreitz@redhat.com> <1472142645-7370-2-git-send-email-mreitz@redhat.com> <87h9a3ik9h.fsf@oc4731375738.ibm.com> From: Max Reitz Message-ID: Date: Fri, 23 Sep 2016 17:16:49 +0200 MIME-Version: 1.0 In-Reply-To: <87h9a3ik9h.fsf@oc4731375738.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="diPj5J06gOSsAc6rwGOBneCIGaRTuwfBL" Subject: Re: [Qemu-devel] [PATCH v3 1/3] qemu-nbd: Add --fork option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sascha Silbe , qemu-block@nongnu.org Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --diPj5J06gOSsAc6rwGOBneCIGaRTuwfBL From: Max Reitz To: Sascha Silbe , qemu-block@nongnu.org Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi Message-ID: Subject: Re: [PATCH v3 1/3] qemu-nbd: Add --fork option References: <1472142645-7370-1-git-send-email-mreitz@redhat.com> <1472142645-7370-2-git-send-email-mreitz@redhat.com> <87h9a3ik9h.fsf@oc4731375738.ibm.com> In-Reply-To: <87h9a3ik9h.fsf@oc4731375738.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 29.08.2016 18:59, Sascha Silbe wrote: > Dear Max, >=20 >=20 > thanks for taking the time to fix the race condition! >=20 >=20 > Max Reitz writes: >=20 >> Using the --fork option, one can make qemu-nbd fork the worker process= =2E >> The original process will exit on error of the worker or once the work= er >> enters the main loop. >=20 >> @@ -773,7 +780,7 @@ int main(int argc, char **argv) >> return 0; >> } >> >> - if (device && !verbose) { >> + if ((device && !verbose) || fork_process) { >> int stderr_fd[2]; >> pid_t pid; >> int ret; >=20 > Looking at the surrounding (unchanged) code I see that qemu-nbd already= > implemented a daemon mode. It's just that it's completely undocumented > and hinges on both the --device and the --verbose option. Yuck. >=20 > It seems there are two things --verbose does (from a user point of > view): >=20 > 1. Print "NBD device %s is now connected to %s" and keep stderr open. >=20 > Debug messages are always printed to stderr, but in non-verbose > daemon mode they end up at /dev/null. >=20 > This is more or less what one usually expects from an option named > --verbose. Except that it only affects daemon mode and messages are > always printed (but end up at /dev/null). >=20 > 2. Disable daemon mode. >=20 > I might expect this for an option named --debug, but certainly not > for --verbose... Does it? There is explicit daemon mode until this patch. While it is actually implemented, it is only used implicitly when you want to connect to the kernel's NBD interface (which is what the --connect option is for (whose argument is kept in the @device variable)). This patch introduces a way to generally make use of the "daemon" mode; and when you use the respective option (--fork), then it will work regardless of whether you have specified --verbose or not. The only thing --verbose does is disable the implicit daemon mode when using --connect, and that seems reasonable to me. > A clean way forward would be something like this: >=20 > 1. Introduce --foreground / --daemon, --quiet >=20 > Default to daemon mode with silent output if --connect is given, > foreground mode with visible output otherwise. Set non-daemon mode > with visible output if --verbose is given. Let --foreground / > --daemon / --quiet any default or implicit value. Document that > --verbose implicitly enables daemon mode for compatibility with > previous versions and that future versions may stop doing so > (i.e. users should use either --verbose --foreground or --verbose > --daemon). Note that we haven't even documented that --connect implicitly puts qemu-nbd in a daemon mode. > 3. At some point in the future (qemu 3.0?) we can stop having --verbose= > imply --foreground. While in my opinion --verbose actually is a debugging option, I don't think the behavior of --connect when used together with --verbose really affects this patch series. > I can give it a try if it's out of scope for your current task. I certainly won't stop you. ;-) Max --diPj5J06gOSsAc6rwGOBneCIGaRTuwfBL Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEvBAEBCAAZBQJX5UdhEhxtcmVpdHpAcmVkaGF0LmNvbQAKCRD0B9sAYdXPQKRm B/0RkeCaSXLLZn+xpND1vdOi5un0sX8NK0/pbj1djcQyPirOAO3rbEKFABHTlMV6 Ht8gfQReDjr88ATbH3kdtkOBGLCS1TJ4vBVSxi+alLjETMo/D0qz5bh6r7t4L0Hq bFRXwgxLk38/Wmk82pAMYOXOO/2a2/gg1G+eESjPxrjIw9VlkcktCVJLPMEbPEeu r4c/K5cSQTqV7awbapz74XqnLULcRB0y5Cfw0FHSqlhP93ekm3+j4ZhTGn6MvdSY Nxa0l2f0eEmyf7cRV7uGuj8r3gnalTKENBJMyd5suqwsCAipPhGa0cgrGPcXklfn h6Gys/4sUts5m4WmoSdaO2o5 =2vW2 -----END PGP SIGNATURE----- --diPj5J06gOSsAc6rwGOBneCIGaRTuwfBL--