Received: from eggs.gnu.org ([2001:4830:134:3::10]:38274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bePuH-00041L-KK for qemu-devel@nongnu.org; Mon, 29 Aug 2016 12:59:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bePuD-0005vz-Fx for qemu-devel@nongnu.org; Mon, 29 Aug 2016 12:59:32 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46111 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bePuD-0005vr-Ap for qemu-devel@nongnu.org; Mon, 29 Aug 2016 12:59:29 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7TGxEPx034220 for ; Mon, 29 Aug 2016 12:59:28 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 253reggxb7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 29 Aug 2016 12:59:28 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 29 Aug 2016 17:59:26 +0100 From: Sascha Silbe In-Reply-To: <1472142645-7370-2-git-send-email-mreitz@redhat.com> References: <1472142645-7370-1-git-send-email-mreitz@redhat.com> <1472142645-7370-2-git-send-email-mreitz@redhat.com> Date: Mon, 29 Aug 2016 18:59:22 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-Id: <87h9a3ik9h.fsf@oc4731375738.ibm.com> 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: Max Reitz , qemu-block@nongnu.org Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi Dear Max, thanks for taking the time to fix the race condition! Max Reitz writes: > Using the --fork option, one can make qemu-nbd fork the worker process. > The original process will exit on error of the worker or once the worker > enters the main loop. > @@ -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; 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. It seems there are two things --verbose does (from a user point of view): 1. Print "NBD device %s is now connected to %s" and keep stderr open. Debug messages are always printed to stderr, but in non-verbose daemon mode they end up at /dev/null. 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). 2. Disable daemon mode. I might expect this for an option named --debug, but certainly not for --verbose... A clean way forward would be something like this: 1. Introduce --foreground / --daemon, --quiet 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). 3. At some point in the future (qemu 3.0?) we can stop having --verbose imply --foreground. I can give it a try if it's out of scope for your current task. Sascha --=20 Softwareentwicklung Sascha Silbe, Niederhofenstra=C3=9Fe 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641