From nobody Thu Nov 28 08:38:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1692907600; cv=none; d=zohomail.com; s=zohoarc; b=CZbPbDK8uOUVOfQb/CfmZ2er/CvqIQMWUsvNlcKczpPK63ZiaFO+oYUhK7zTv5sSZNy9KOD9kzLRzMVZKu1sBMTI0n98ak+hDMri87vYg8FnLXQaOVI6yITT6zaw/FHy7130TVkbYKTrUPkZFVT9BxhqXyzZWGFyV3MgcE1XfeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692907600; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=hKdYcMBLaw9Xkva3LmFa4Q04TOPMi1MovMMjYwWutXg=; b=RWrdV6UZs/IdlCuDS1R4X4nJ0ZmZNnYEqaiOVVstl5RwMZTr+7ABSQXdcdeqc++bYsRrKqq5dDK1Ey8sr1pvuf4uJvwSAWcseX4zYalB82ZAhkVUpb0kueGGr2RY6zZh9y0W6TY0IkUITylQ1kTQqqZOZvwv4iIDRhPOBPdwpsc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1692907600852246.2925669849676; Thu, 24 Aug 2023 13:06:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZGaM-0000MW-MP; Thu, 24 Aug 2023 16:05:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZGaJ-0000Lo-76 for qemu-devel@nongnu.org; Thu, 24 Aug 2023 16:05:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZGaG-0007hm-1D for qemu-devel@nongnu.org; Thu, 24 Aug 2023 16:05:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-282-n1Ds5zsaMbi9j5hidQpSug-1; Thu, 24 Aug 2023 16:05:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B45258015AA; Thu, 24 Aug 2023 20:05:23 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id D33B91121319; Thu, 24 Aug 2023 20:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692907534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hKdYcMBLaw9Xkva3LmFa4Q04TOPMi1MovMMjYwWutXg=; b=B9j6oYc5HbI4hEyWaUBj2wLRGjW0u4pF/S6mWWgOV37LqyzuRtQXD/oKNgemeBrQfdzat8 w15kBx1p3jQihg95UMVyEwGaoKz6wbS3tfuZqpG8de7CbG65s1iYfkspttg4S2VIAtQi6Q qPrHPpOkuTxscOGjWM0dRGp9ce2V0Xw= X-MC-Unique: n1Ds5zsaMbi9j5hidQpSug-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Kevin Wolf , "Denis V . Lunev" , qemu-stable@nongnu.org, Vladimir Sementsov-Ogievskiy , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PATCH] qemu-nbd: Restore "qemu-nbd -v --fork" output Date: Thu, 24 Aug 2023 15:03:12 -0500 Message-ID: <20230824200311.636589-2-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692907602447100002 Content-Type: text/plain; charset="utf-8" Closing stderr earlier is good for daemonized qemu-nbd under ssh earlier, but breaks the case where -v is being used to track what is happening in the server, as in iotest 233. When we know we are verbose, we do NOT want qemu_daemon to close stderr. For management purposes, we still need to temporarily override the daemon child's stderr with the pipe to the parent until after the pid file is created; but since qemu_daemon would normally set stdout to /dev/null had we not been verbose, we can use stdout as a place to stash our original stderr. Thus, whether normal or vebose, when the management handoff is complete, copying stdout back to stderr does the right thing for the rest of the life of the daemon child. Note that while the error messages expected by iotest 233 are now restored, the change in file descriptors means they now show up earlier in the testsuite output. Reported-by: Kevin Wolf CC: Denis V. Lunev CC: qemu-stable@nongnu.org Fixes: 5c56dd27a2 ("qemu-nbd: fix regression with qemu-nbd --fork run over = ssh") Signed-off-by: Eric Blake --- qemu-nbd.c | 21 ++++++++++++++++++++- tests/qemu-iotests/233.out | 20 ++++++++++---------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index aaccaa33184..a105094fb17 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -944,9 +944,24 @@ int main(int argc, char **argv) close(stderr_fd[0]); - ret =3D qemu_daemon(1, 0); + ret =3D qemu_daemon(1, verbose); saved_errno =3D errno; /* dup2 will overwrite error below */ + if (verbose) { + /* We want stdin at /dev/null when qemu_daemon didn't do i= t */ + stdin =3D freopen("/dev/null", "r", stdin); + if (stdin =3D=3D NULL) { + error_report("Failed to redirect stdin: %s", + strerror(errno)); + exit(EXIT_FAILURE); + } + /* To keep the parent's stderr alive, copy it to stdout */ + if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { + error_report("Failed to redirect stdout: %s", + strerror(errno)); + exit(EXIT_FAILURE); + } + } /* Temporarily redirect stderr to the parent's pipe... */ if (dup2(stderr_fd[1], STDERR_FILENO) < 0) { char str[256]; @@ -1180,6 +1195,10 @@ int main(int argc, char **argv) } if (fork_process) { + /* + * See above. If verbose is false, stdout is /dev/null (thanks + * to qemu_daemon); otherwise, stdout is the parent's stderr. + */ if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { error_report("Could not set stderr to /dev/null: %s", strerror(errno)); diff --git a/tests/qemu-iotests/233.out b/tests/qemu-iotests/233.out index 237c82767ea..b09a197020a 100644 --- a/tests/qemu-iotests/233.out +++ b/tests/qemu-iotests/233.out @@ -41,8 +41,10 @@ exports available: 1 min block: 1 =3D=3D check TLS fail over TCP with mismatched hostname =3D=3D +qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort qemu-img: Could not open 'driver=3Dnbd,host=3Dlocalhost,port=3DPORT,tls-cr= eds=3Dtls0': Certificate does not match the hostname localhost qemu-nbd: Certificate does not match the hostname localhost +qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort =3D=3D check TLS works over TCP with mismatched hostname and override =3D= =3D image: nbd://localhost:PORT @@ -55,7 +57,9 @@ exports available: 1 min block: 1 =3D=3D check TLS with different CA fails =3D=3D +qemu-nbd: option negotiation failed: Verify failed: No certificate was fou= nd. qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3DPORT,tls-cr= eds=3Dtls0': The certificate hasn't got a known issuer +qemu-nbd: option negotiation failed: Verify failed: No certificate was fou= nd. qemu-nbd: The certificate hasn't got a known issuer =3D=3D perform I/O over TLS =3D=3D @@ -67,11 +71,15 @@ read 1048576/1048576 bytes at offset 1048576 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =3D=3D check TLS with authorization =3D=3D +qemu-nbd: option negotiation failed: TLS x509 authz check for C=3DSouth Pa= cific,L=3DR'lyeh,O=3DCthulhu Dark Lord Enterprises client1,CN=3Dlocalhost i= s denied qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3DPORT,tls-cr= eds=3Dtls0': Failed to read option reply: Cannot read from TLS channel: Sof= tware caused connection abort +qemu-nbd: option negotiation failed: TLS x509 authz check for C=3DSouth Pa= cific,L=3DR'lyeh,O=3DCthulhu Dark Lord Enterprises client3,CN=3Dlocalhost i= s denied qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3DPORT,tls-cr= eds=3Dtls0': Failed to read option reply: Cannot read from TLS channel: Sof= tware caused connection abort =3D=3D check TLS fail over UNIX with no hostname =3D=3D +qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort qemu-img: Could not open 'driver=3Dnbd,path=3DSOCK_DIR/qemu-nbd.sock,tls-c= reds=3Dtls0': No hostname for certificate validation +qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort qemu-nbd: No hostname for certificate validation =3D=3D check TLS works over UNIX with hostname override =3D=3D @@ -95,18 +103,10 @@ exports available: 1 min block: 1 =3D=3D check TLS fails over UNIX with mismatch PSK =3D=3D +qemu-nbd: option negotiation failed: TLS handshake failed: An illegal para= meter has been received. qemu-img: Could not open 'driver=3Dnbd,path=3DSOCK_DIR/qemu-nbd.sock,tls-c= reds=3Dtls0': TLS handshake failed: The TLS connection was non-properly ter= minated. +qemu-nbd: option negotiation failed: TLS handshake failed: An illegal para= meter has been received. qemu-nbd: TLS handshake failed: The TLS connection was non-properly termin= ated. =3D=3D final server log =3D=3D -qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort -qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort -qemu-nbd: option negotiation failed: Verify failed: No certificate was fou= nd. -qemu-nbd: option negotiation failed: Verify failed: No certificate was fou= nd. -qemu-nbd: option negotiation failed: TLS x509 authz check for DISTINGUISHE= D-NAME is denied -qemu-nbd: option negotiation failed: TLS x509 authz check for DISTINGUISHE= D-NAME is denied -qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort -qemu-nbd: option negotiation failed: Failed to read opts magic: Cannot rea= d from TLS channel: Software caused connection abort -qemu-nbd: option negotiation failed: TLS handshake failed: An illegal para= meter has been received. -qemu-nbd: option negotiation failed: TLS handshake failed: An illegal para= meter has been received. *** done --=20 2.41.0