From nobody Sun May 19 05:00:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557254416; cv=none; d=zoho.com; s=zohoarc; b=HrzzuIBS+QPinWFlYRpXfTAm0/KdTL9SLXTqStjuBozh7dufisiXDHyPpIOyP1QFU7IYu+aTw6kr3iYIm42N1akek7SO63nUHKIuRkcAEoOu5gP4I0dblYQMaFklVrSxjPiI9SPBbAObZjO2o+H6JINEwhxqpK4A1LTFCBEJYUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557254416; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=V7gqgmmGX0nlLCuxVmUAeRphTpzWTajbZtSJWbbAu/I=; b=COMidmwWaM1nXA1c0Y/ktsoLu4Gnd6RfudDiquL++bE3YUPwlnIasEE43GPLq+NRmsVwbfoksrd7Smc9uEnwlbT5xsovIDwTaCR8ZTaKhq3R0aUIJRIgu5IMGotzzEexcJ69qNhVLpKCjJupLjlXT0soPVkfn4U1ZOxYL00ynMA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557254416309415.3487397854926; Tue, 7 May 2019 11:40:16 -0700 (PDT) Received: from localhost ([127.0.0.1]:51331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO50Z-0002gO-Cm for importer@patchew.org; Tue, 07 May 2019 14:40:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO4wt-0007Su-Bx for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hO4ws-0002Ko-A6 for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33798) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hO4wp-0002EU-Tr; Tue, 07 May 2019 14:36:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 414DEC058CA8; Tue, 7 May 2019 18:36:15 +0000 (UTC) Received: from localhost (unknown [10.40.205.217]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CE25861781; Tue, 7 May 2019 18:36:14 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 7 May 2019 20:36:06 +0200 Message-Id: <20190507183610.9848-2-mreitz@redhat.com> In-Reply-To: <20190507183610.9848-1-mreitz@redhat.com> References: <20190507183610.9848-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 07 May 2019 18:36:15 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/5] qemu-nbd: Add --pid-file option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" --fork is a bit boring if there is no way to get the child's PID. This option helps. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qemu-nbd.c | 29 +++++++++++++++++++++++++++++ qemu-nbd.texi | 2 ++ 2 files changed, 31 insertions(+) diff --git a/qemu-nbd.c b/qemu-nbd.c index dca9e72cee..7e48154f44 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -59,6 +59,7 @@ #define QEMU_NBD_OPT_IMAGE_OPTS 262 #define QEMU_NBD_OPT_FORK 263 #define QEMU_NBD_OPT_TLSAUTHZ 264 +#define QEMU_NBD_OPT_PID_FILE 265 =20 #define MBR_SIZE 512 =20 @@ -111,6 +112,7 @@ static void usage(const char *name) " specify tracing options\n" " --fork fork off the server process and exit the pare= nt\n" " once the server is running\n" +" --pid-file=3DPATH store the server's process ID in the given = file\n" #if HAVE_NBD_DEVICE "\n" "Kernel NBD client support:\n" @@ -651,6 +653,7 @@ int main(int argc, char **argv) { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS }, { "trace", required_argument, NULL, 'T' }, { "fork", no_argument, NULL, QEMU_NBD_OPT_FORK }, + { "pid-file", required_argument, NULL, QEMU_NBD_OPT_PID_FILE }, { NULL, 0, NULL, 0 } }; int ch; @@ -677,6 +680,8 @@ int main(int argc, char **argv) bool list =3D false; int old_stderr =3D -1; unsigned socket_activation; + const char *pid_path =3D NULL; + FILE *pid_file; =20 /* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code. @@ -876,6 +881,9 @@ int main(int argc, char **argv) case 'L': list =3D true; break; + case QEMU_NBD_OPT_PID_FILE: + pid_path =3D optarg; + break; } } =20 @@ -1196,6 +1204,27 @@ int main(int argc, char **argv) =20 nbd_update_server_watch(); =20 + if (pid_path) { + pid_file =3D fopen(pid_path, "w"); + if (!pid_file) { + error_report("Failed to store PID in %s: %s", + pid_path, strerror(errno)); + exit(EXIT_FAILURE); + } + + ret =3D fprintf(pid_file, "%ld", (long)getpid()); + if (ret < 0) { + ret =3D -errno; + } + fclose(pid_file); + + if (ret < 0) { + error_report("Failed to store PID in %s: %s", + pid_path, strerror(-ret)); + exit(EXIT_FAILURE); + } + } + /* now when the initialization is (almost) complete, chdir("/") * to free any busy filesystems */ if (chdir("/") < 0) { diff --git a/qemu-nbd.texi b/qemu-nbd.texi index de342c76b8..7f55657722 100644 --- a/qemu-nbd.texi +++ b/qemu-nbd.texi @@ -117,6 +117,8 @@ option; or provide the credentials needed for connectin= g as a client in list mode. @item --fork Fork off the server process and exit the parent once the server is running. +@item --pid-file=3DPATH +Store the server's process ID in the given file. @item --tls-authz=3DID Specify the ID of a qauthz object previously created with the --object option. This will be used to authorize connecting users --=20 2.20.1 From nobody Sun May 19 05:00:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557254512; cv=none; d=zoho.com; s=zohoarc; b=WovgyxCUZZ7eqAF2pF/LvRgfitVGZ1RDG9enea/CJHS6KJ37XWN4Y2yaf7x4aP4i7SvYWwN1s3HX1KU4tm9UTYNOqsMax2NjDDu8KNiV92bzLzcMr716XPjL7q/hlzKpgybdaPqJe7mJOqrWmDsvpTKzS/5qDpEhhXepkAKexmU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557254512; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=93FCc/m6rDGeI19g9RJHGMvSvMtifmLYuTa7B3XacL0=; b=NnsX4jZ/YN39egVtvhqvUNxcbHZuAeaPpdxU3SmPe462mc2BeiFlJW+swQ0SVXtlA6UOQdvtkbjJU8bDBU+CaQSvW5g9GVXBHpXEIhy75mIPjzCp+kIbR2o5eCHdgUEunkSvXHRn1km4Xo42yuxS8BPR82h9w/SefSVxHRlZ+ps= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557254512498482.809223267766; Tue, 7 May 2019 11:41:52 -0700 (PDT) Received: from localhost ([127.0.0.1]:51380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO52D-000463-Jp for importer@patchew.org; Tue, 07 May 2019 14:41:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO4x3-0007uJ-8K for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hO4wu-0002OS-JT for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hO4ws-0002J1-Ba; Tue, 07 May 2019 14:36:18 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9599307D854; Tue, 7 May 2019 18:36:17 +0000 (UTC) Received: from localhost (unknown [10.40.205.217]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E6DB4123; Tue, 7 May 2019 18:36:17 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 7 May 2019 20:36:07 +0200 Message-Id: <20190507183610.9848-3-mreitz@redhat.com> In-Reply-To: <20190507183610.9848-1-mreitz@redhat.com> References: <20190507183610.9848-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 07 May 2019 18:36:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/5] iotests.py: Add qemu_nbd_early_pipe() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" qemu_nbd_pipe() currently unconditionally reads qemu-nbd's output. That is not ideal because qemu-nbd may keep stderr open after the parent process has exited. Currently, the only user of qemu_nbd_pipe() is 147, which discards the whole output if the parent process returned success and only evaluates it on error. Therefore, we can replace qemu_nbd_pipe() by qemu_nbd_early_pipe() that does the same: Discard the output on success, and return it on error. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/147 | 4 ++-- tests/qemu-iotests/iotests.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/147 b/tests/qemu-iotests/147 index 82513279b0..2d84fddb01 100755 --- a/tests/qemu-iotests/147 +++ b/tests/qemu-iotests/147 @@ -24,7 +24,7 @@ import socket import stat import time import iotests -from iotests import cachemode, imgfmt, qemu_img, qemu_nbd, qemu_nbd_pipe +from iotests import cachemode, imgfmt, qemu_img, qemu_nbd, qemu_nbd_early_= pipe =20 NBD_PORT_START =3D 32768 NBD_PORT_END =3D NBD_PORT_START + 1024 @@ -93,7 +93,7 @@ class QemuNBD(NBDBlockdevAddBase): pass =20 def _try_server_up(self, *args): - status, msg =3D qemu_nbd_pipe('-f', imgfmt, test_img, *args) + status, msg =3D qemu_nbd_early_pipe('-f', imgfmt, test_img, *args) if status =3D=3D 0: return True if 'Address already in use' in msg: diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index f811f69135..ce21d83182 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -204,9 +204,9 @@ def qemu_nbd(*args): '''Run qemu-nbd in daemon mode and return the parent's exit code''' return subprocess.call(qemu_nbd_args + ['--fork'] + list(args)) =20 -def qemu_nbd_pipe(*args): +def qemu_nbd_early_pipe(*args): '''Run qemu-nbd in daemon mode and return both the parent's exit code - and its output''' + and its output in case of an error''' subp =3D subprocess.Popen(qemu_nbd_args + ['--fork'] + list(args), stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess.STDOUT, @@ -216,7 +216,10 @@ def qemu_nbd_pipe(*args): sys.stderr.write('qemu-nbd received signal %i: %s\n' % (-exitcode, ' '.join(qemu_nbd_args + ['--fork'] + list(args)= ))) - return exitcode, subp.communicate()[0] + if exitcode =3D=3D 0: + return exitcode, '' + else: + return exitcode, subp.communicate()[0] =20 def compare_images(img1, img2, fmt1=3Dimgfmt, fmt2=3Dimgfmt): '''Return True if two image files are identical''' --=20 2.20.1 From nobody Sun May 19 05:00:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557254583; cv=none; d=zoho.com; s=zohoarc; b=QKtUdjNA1tRIdaa7vyE0BAFW8G4HiPD+wotKymOM6CWFBXfzlc/P9cdyAowHCv2l78o+Dujso1zmL/xj3qCkHTO/vbY9GscdF2W/WwcN2a0gBEl6qbK9J6EMg7hfftpPiE1qEn02jrZ6/D2HaYjcYHFBB0iTTGwWCEwh1q/8/AQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557254583; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GFFOM8oPVZ0ZrABj2uSBWjna/uz7zcXlAtVJthgSGT8=; b=UCN4csjeAsSlRG+4dRCLnp5/n4piMBhVKU+8/V7ZmCJKM3UB665fzHxJuWEFAso/qX+m6nzBeR3CCIEHRWZjsjTeaBM/Q9FnkC0zlLEzozWFarp9qVIDGJtql45MkGSslOK3klv7FqVsv9uiSR1tOVwvxgWzIPJx+gWnHp8vulY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557254583729582.2726288717414; Tue, 7 May 2019 11:43:03 -0700 (PDT) Received: from localhost ([127.0.0.1]:51390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO53J-00053O-Qb for importer@patchew.org; Tue, 07 May 2019 14:42:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO4xA-0008Sy-TX for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hO4x9-0002ff-1N for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36060) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hO4ww-0002Nx-Cf; Tue, 07 May 2019 14:36:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1594130992A3; Tue, 7 May 2019 18:36:20 +0000 (UTC) Received: from localhost (unknown [10.40.205.217]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9D67517178; Tue, 7 May 2019 18:36:19 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 7 May 2019 20:36:08 +0200 Message-Id: <20190507183610.9848-4-mreitz@redhat.com> In-Reply-To: <20190507183610.9848-1-mreitz@redhat.com> References: <20190507183610.9848-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 07 May 2019 18:36:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/5] qemu-nbd: Do not close stderr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We kept old_stderr specifically so we could keep emitting error message on stderr. However, qemu_daemon() closes stderr. Therefore, we need to dup() stderr to old_stderr before invoking qemu_daemon(). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- As I hinted at in the cover letter, I am not sure whether this is truly a bug or whether the current behavior is intentional. So if you disagree with me on this patch, you are welcome to suggest an alternative. I personally can see two: (1) Add a --log option for a file to store the server's messages in. Seems a bit cumbersome to me. (2) Add a --keep-stderr option, which specifically enables this behavior here. Without this option we keep the old behavior. --- qemu-nbd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 7e48154f44..3805324153 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -1015,10 +1015,11 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } else if (pid =3D=3D 0) { close(stderr_fd[0]); + + old_stderr =3D dup(STDERR_FILENO); ret =3D qemu_daemon(1, 0); =20 /* Temporarily redirect stderr to the parent's pipe... */ - old_stderr =3D dup(STDERR_FILENO); dup2(stderr_fd[1], STDERR_FILENO); if (ret < 0) { error_report("Failed to daemonize: %s", strerror(errno)); --=20 2.20.1 From nobody Sun May 19 05:00:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557254310; cv=none; d=zoho.com; s=zohoarc; b=nKQo77zBdovqt2Xus+u60EYQtu6JFg8PdhS9qHW76Q38IDamE84WYcLV6Oamt0bZ/RBvCJJkG6rgHSr6aWs+y3fzDk4Ivdbon+Gcd0dMXGKHQcMui475xcKPv9W1gW19ncXkuIwTwjhWHifRgLMB2XD+9VctzUFiv1jQ9lwxohM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557254310; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=eADPAHZ3tR7Sr8scKB7IoMTKn62CWx0iK1eN6dhw1p0=; b=m9YibeSBDG6po4AaQrvYdb1NmSqwIeEK1XIM6+lguxdBD04rsn/bCVzHvxPMYyZzMQ+s9be3ynzN5kCx0DFPN8lP4oPyqN8ZbRdK6knujTKZyhSXx3upOtzMgPaW2VnYS5qEJGVwIWxTHggnNCSV3JPHPvlDe2JORUH/WOrtX3o= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557254310208803.4231920637337; Tue, 7 May 2019 11:38:30 -0700 (PDT) Received: from localhost ([127.0.0.1]:51309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO4yr-0001IO-7u for importer@patchew.org; Tue, 07 May 2019 14:38:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47220) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO4xA-0008Sx-Tc for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hO4x9-0002fY-0m for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hO4x0-0002RM-1w; Tue, 07 May 2019 14:36:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D401301EA92; Tue, 7 May 2019 18:36:22 +0000 (UTC) Received: from localhost (unknown [10.40.205.217]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B7E5600D4; Tue, 7 May 2019 18:36:21 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 7 May 2019 20:36:09 +0200 Message-Id: <20190507183610.9848-5-mreitz@redhat.com> In-Reply-To: <20190507183610.9848-1-mreitz@redhat.com> References: <20190507183610.9848-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 07 May 2019 18:36:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/5] iotests: Use qemu-nbd's --pid-file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz --- tests/qemu-iotests/common.rc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 93f87389b6..217cf3874d 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -106,8 +106,8 @@ _qemu_io_wrapper() _qemu_nbd_wrapper() { ( - echo $BASHPID > "${QEMU_TEST_DIR}/qemu-nbd.pid" - exec "$QEMU_NBD_PROG" $QEMU_NBD_OPTIONS "$@" + exec "$QEMU_NBD_PROG" --pid-file=3D"${QEMU_TEST_DIR}/qemu-nbd.pid"= \ + $QEMU_NBD_OPTIONS "$@" ) } =20 --=20 2.20.1 From nobody Sun May 19 05:00:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557254665; cv=none; d=zoho.com; s=zohoarc; b=FgLwoiO89Qhh1SH8TV2o7uvgNvnclwxhl8Zi2k/hg79FXYRxpe4zHwOYStCxyhTuzWjwWG/6XYfd4k+Urr/Aor3niKLe/F3CqR3kyLu4APPZz0UVHrx/xgD+JmFydCX0pGPJsVNmdyrurloQi5LhwhdhXupXVxz/3S3eFlTomTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557254665; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+WkXWhKijDpPDaUrMRC1ItBfIZGKfZY/9XaBV5pJ3NM=; b=fxJ2fSDE+XAYSrB/lQKYgAqLySpPVCBIb3fudIbw19GqjijaKPLPUw4OpShH5bIBt3ObNnq/hVssRHKgxH5E/rqMYCloswAxXx9TYEYWleIcs0OLdkOhNemRABg966dG7C3bEFeglMDm7cLQm+31uoXhRWIssn0GiDr61tOq85A= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557254665185829.7011246720846; Tue, 7 May 2019 11:44:25 -0700 (PDT) Received: from localhost ([127.0.0.1]:51398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO54W-0005h3-0N for importer@patchew.org; Tue, 07 May 2019 14:44:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO4xI-0000Hy-2h for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hO4xG-0002tY-MZ for qemu-devel@nongnu.org; Tue, 07 May 2019 14:36:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44266) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hO4x9-0002VN-Ad; Tue, 07 May 2019 14:36:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 128C6369D2; Tue, 7 May 2019 18:36:26 +0000 (UTC) Received: from localhost (unknown [10.40.205.217]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B94F64026; Tue, 7 May 2019 18:36:25 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 7 May 2019 20:36:10 +0200 Message-Id: <20190507183610.9848-6-mreitz@redhat.com> In-Reply-To: <20190507183610.9848-1-mreitz@redhat.com> References: <20190507183610.9848-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 07 May 2019 18:36:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/5] iotests: Let 233 run concurrently X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" common.nbd's nbd_server_set_tcp_port() tries to find a free port, and then uses it for the whole test run. However, this is racey because even if the port was free at the beginning, there is no guarantee it will continue to be available. Therefore, 233 currently cannot reliably be run concurrently with other NBD TCP tests. This patch addresses the problem by dropping nbd_server_set_tcp_port(), and instead finding a new port every time nbd_server_start_tcp_socket() is invoked. For this, we run qemu-nbd with --fork and on error evaluate the output to see whether it contains "Address already in use". If so, we try the next port. On success, we still want to continually redirect the output from qemu-nbd to stderr. To achieve both, we redirect qemu-nbd's stderr to a FIFO that we then open in bash. If the parent process exits with status 0 (which means that the server has started successfully), we launch a background cat process that copies the FIFO to stderr. On failure, we read the whole content into a variable and then evaluate it. While at it, use --fork in nbd_server_start_unix_socket(), too. Doing so allows us to drop nbd_server_wait_for_*_socket(). Note that the reason common.nbd did not use --fork before is that qemu-nbd did not have --pid-file. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/233 | 1 - tests/qemu-iotests/common.nbd | 93 ++++++++++++++++------------------- 2 files changed, 42 insertions(+), 52 deletions(-) diff --git a/tests/qemu-iotests/233 b/tests/qemu-iotests/233 index b8b6c8cc4c..8682ea277c 100755 --- a/tests/qemu-iotests/233 +++ b/tests/qemu-iotests/233 @@ -50,7 +50,6 @@ _supported_proto file _supported_os Linux _require_command QEMU_NBD =20 -nbd_server_set_tcp_port tls_x509_init =20 echo diff --git a/tests/qemu-iotests/common.nbd b/tests/qemu-iotests/common.nbd index 25fc9ffaa4..e003478a57 100644 --- a/tests/qemu-iotests/common.nbd +++ b/tests/qemu-iotests/common.nbd @@ -22,6 +22,11 @@ nbd_unix_socket=3D"${TEST_DIR}/qemu-nbd.sock" nbd_tcp_addr=3D"127.0.0.1" nbd_pid_file=3D"${TEST_DIR}/qemu-nbd.pid" +nbd_stderr_fifo=3D"${TEST_DIR}/qemu-nbd.fifo" + +# If bash version is >=3D 4.1, this will be overwritten by a dynamically +# assigned file descriptor value. +nbd_fifo_fd=3D10 =20 nbd_server_stop() { @@ -34,76 +39,62 @@ nbd_server_stop() fi fi rm -f "$nbd_unix_socket" -} - -nbd_server_wait_for_unix_socket() -{ - pid=3D$1 - - for ((i =3D 0; i < 300; i++)) - do - if [ -r "$nbd_unix_socket" ]; then - return - fi - kill -s 0 $pid 2>/dev/null - if test $? !=3D 0 - then - echo "qemu-nbd unexpectedly quit" - exit 1 - fi - sleep 0.1 - done - echo "Failed in check of unix socket created by qemu-nbd" - exit 1 + rm -f "$nbd_stderr_fifo" } =20 nbd_server_start_unix_socket() { nbd_server_stop - $QEMU_NBD -v -t -k "$nbd_unix_socket" "$@" & - nbd_server_wait_for_unix_socket $! + $QEMU_NBD -v -t -k "$nbd_unix_socket" --fork "$@" } =20 -nbd_server_set_tcp_port() +nbd_server_start_tcp_socket() { - (ss --help) >/dev/null 2>&1 || _notrun "ss utility not found, skipping= test" + nbd_server_stop =20 + mkfifo "$nbd_stderr_fifo" for ((port =3D 10809; port <=3D 10909; port++)) do - if ! ss -tln | grep -sqE ":$port\b"; then + # Redirect stderr to FIFO, so we can later decide whether we + # want to read it or to redirect it to our stderr, depending + # on whether the command fails or not + $QEMU_NBD -v -t -b $nbd_tcp_addr -p $port --fork "$@" \ + 2> "$nbd_stderr_fifo" & + + # Taken from common.qemu + if [[ "${BASH_VERSINFO[0]}" -ge "5" || + ("${BASH_VERSINFO[0]}" -ge "4" && "${BASH_VERSINFO[1]}" -ge "1= ") ]] + then + exec {nbd_fifo_fd}<"$nbd_stderr_fifo" + else + let _nbd_fifo_fd++ + eval "exec ${_nbd_fifo_fd}<'$nbd_stderr_fifo'" + fi + wait $! + + if test $? =3D=3D 0 + then + # Success, redirect qemu-nbd's stderr to our stderr nbd_tcp_port=3D$port + (cat <&$nbd_fifo_fd >&2) & + eval "exec $nbd_fifo_fd>&-" return fi - done =20 - echo "Cannot find free TCP port for nbd in range 10809-10909" - exit 1 -} - -nbd_server_wait_for_tcp_socket() -{ - pid=3D$1 + # Failure, read the output + output=3D$(cat <&$nbd_fifo_fd) + eval "exec $nbd_fifo_fd>&-" =20 - for ((i =3D 0; i < 300; i++)) - do - if ss -tln | grep -sqE ":$nbd_tcp_port\b"; then - return - fi - kill -s 0 $pid 2>/dev/null - if test $? !=3D 0 + if ! echo "$output" | grep -q "Address already in use" then - echo "qemu-nbd unexpectedly quit" + # Unknown error, print it + echo "$output" >&2 + rm -f "$nbd_stderr_fifo" exit 1 fi - sleep 0.1 done - echo "Failed in check of TCP socket created by qemu-nbd" - exit 1 -} =20 -nbd_server_start_tcp_socket() -{ - nbd_server_stop - $QEMU_NBD -v -t -b $nbd_tcp_addr -p $nbd_tcp_port "$@" & - nbd_server_wait_for_tcp_socket $! + echo "Cannot find free TCP port for nbd in range 10809-10909" + rm -f "$nbd_stderr_fifo" + exit 1 } --=20 2.20.1