From nobody Thu Nov 28 07:59:32 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=1694137039; cv=none; d=zohomail.com; s=zohoarc; b=lVkUE9KsmsqDvlEtvoQMXGJsvdK2fwD4PooVM8n0paVt2ef98Hxj4mDTUWXhA/uxfNjZ6msamIazjvoXa6fL1GlhkdD1cuKjVvHk0D2Q81j/yfupRjejOVxG3P9aYQsqci78VlPQxg47OpjU+cqJxBvMfI/EXUDE3dBha+9JMjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137039; h=Content-Type: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; bh=C0HCJYBvdpwPjNr/rSSyANOLnacS+MwnaDPetGq22G4=; b=V3hp/BtnAPo4qenPlY/+pktZpy+aRnnGqP4kBzXL74e3vPtRocll38gbozkRqWs7/bKQhB9yXqlif2Hh81SLOhuJJcbSM9TvH0vKTdG0dBSWCh5MhG083qgpQzaklWGpBRgi7v8iX1NeoI6d5e6AOqWNLbVIQg2fJlombUbTRy8= 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 1694137039526357.9876509776558; Thu, 7 Sep 2023 18:37:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQPx-0008QK-1r; Thu, 07 Sep 2023 21:36:17 -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 1qeQPv-0008Pm-Ek for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:15 -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 1qeQPs-0007sR-0O for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:15 -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-54-hwBfzrkOOYKtF8yUJ-QlHg-1; Thu, 07 Sep 2023 21:36:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F814101CA82; Fri, 8 Sep 2023 01:36:07 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB75740C2070; Fri, 8 Sep 2023 01:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136970; 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: in-reply-to:in-reply-to:references:references; bh=C0HCJYBvdpwPjNr/rSSyANOLnacS+MwnaDPetGq22G4=; b=ZLxlMbTfDTsfDbaZEC4C+v+/tt8bqQYuhYsirIwu7C3FLo7EyGFSsWYeSapxvRInyHpf6I /Thk9WVG6G3t9qbyD4RFhGvP9+WnUQPEK1g1azxEdAmUSrgE69VUR48FGSeB/bphR7QlTD 0rNiKTMQOIW12J99okEQ8OkDCCVam3I= X-MC-Unique: hwBfzrkOOYKtF8yUJ-QlHg-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Andrey Drobyshev , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Block layer core) Subject: [PULL 01/13] qemu-iotests/197: use more generic commands for formats other than qcow2 Date: Thu, 7 Sep 2023 20:35:37 -0500 Message-ID: <20230908013535.990731-16-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1694137040994100010 Content-Type: text/plain; charset="utf-8" From: Andrey Drobyshev In the previous commit e2f938265e0 ("tests/qemu-iotests/197: add testcase for CoR with subclusters") we've introduced a new testcase for copy-on-read with subclusters. Test 197 always forces qcow2 as the top image, but allows backing image to be in any format. That last test case didn't meet these requirements, so let's fix it by using more generic "qemu-io -c map" command. Signed-off-by: Andrey Drobyshev Message-ID: <20230907220718.983430-1-andrey.drobyshev@virtuozzo.com> Tested-by: Eric Blake Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- tests/qemu-iotests/197 | 8 ++++---- tests/qemu-iotests/197.out | 18 ++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/qemu-iotests/197 b/tests/qemu-iotests/197 index f07a9da136a..8ad2bdb035e 100755 --- a/tests/qemu-iotests/197 +++ b/tests/qemu-iotests/197 @@ -136,18 +136,18 @@ IMGPROTO=3Dfile IMGFMT=3Dqcow2 TEST_IMG_FILE=3D"$TEST= _WRAP" \ $QEMU_IO -c "write -P 0xaa 0 64k" "$TEST_IMG" | _filter_qemu_io # Allocate individual subclusters in the top image, and not the whole clus= ter -$QEMU_IO -c "write -P 0xbb 28K 2K" -c "write -P 0xcc 34K 2K" "$TEST_WRAP" \ +$QEMU_IO -f qcow2 -c "write -P 0xbb 28K 2K" -c "write -P 0xcc 34K 2K" "$TE= ST_WRAP" \ | _filter_qemu_io # Only 2 subclusters should be allocated in the top image at this point -$QEMU_IMG map "$TEST_WRAP" | _filter_qemu_img_map +$QEMU_IO -f qcow2 -c map "$TEST_WRAP" # Actual copy-on-read operation -$QEMU_IO -C -c "read -P 0xaa 30K 4K" "$TEST_WRAP" | _filter_qemu_io +$QEMU_IO -f qcow2 -C -c "read -P 0xaa 30K 4K" "$TEST_WRAP" | _filter_qemu_= io # And here we should have 4 subclusters allocated right in the middle of t= he # top image. Make sure the whole cluster remains unallocated -$QEMU_IMG map "$TEST_WRAP" | _filter_qemu_img_map +$QEMU_IO -f qcow2 -c map "$TEST_WRAP" _check_test_img diff --git a/tests/qemu-iotests/197.out b/tests/qemu-iotests/197.out index 8f34a30afea..86c57b51d30 100644 --- a/tests/qemu-iotests/197.out +++ b/tests/qemu-iotests/197.out @@ -42,17 +42,15 @@ wrote 2048/2048 bytes at offset 28672 2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 2048/2048 bytes at offset 34816 2 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -Offset Length File -0 0x7000 TEST_DIR/t.IMGFMT -0x7000 0x800 TEST_DIR/t.wrap.IMGFMT -0x7800 0x1000 TEST_DIR/t.IMGFMT -0x8800 0x800 TEST_DIR/t.wrap.IMGFMT -0x9000 0x7000 TEST_DIR/t.IMGFMT +28 KiB (0x7000) bytes not allocated at offset 0 bytes (0x0) +2 KiB (0x800) bytes allocated at offset 28 KiB (0x7000) +4 KiB (0x1000) bytes not allocated at offset 30 KiB (0x7800) +2 KiB (0x800) bytes allocated at offset 34 KiB (0x8800) +28 KiB (0x7000) bytes not allocated at offset 36 KiB (0x9000) read 4096/4096 bytes at offset 30720 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -Offset Length File -0 0x7000 TEST_DIR/t.IMGFMT -0x7000 0x2000 TEST_DIR/t.wrap.IMGFMT -0x9000 0x7000 TEST_DIR/t.IMGFMT +28 KiB (0x7000) bytes not allocated at offset 0 bytes (0x0) +8 KiB (0x2000) bytes allocated at offset 28 KiB (0x7000) +28 KiB (0x7000) bytes not allocated at offset 36 KiB (0x9000) No errors were found on the image. *** done --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137038; cv=none; d=zohomail.com; s=zohoarc; b=eE6bohyan2Z3Iwb2r1iodV3kabIWpeyz2+sr08u+CCweB9LTH0SHYhMNAdH6A1WDgt5wBHeEOCuTTG9UfsRTzfPgIsdjDIBPbsOZWGGubnUd3/zg6nAe88csjH41KWKloONUYrQAwVDRrufe/bIKiuwMWp1oZE/SH80AClBjsnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137038; h=Content-Type: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; bh=DRV578KzQi2bfJ0mlQnroELkcGRUQ+AZukcRhklKJ4o=; b=nJD4nXwOp+ief/RgNiM7K8ASfWVxuP/7rRR8sAd6WBqveuSusaeBkUUOv6NRoYLJHpjxzGWj7G+NB2NzWn7FjFyqPoTM5ntz61+R8OWQwzWdlpVNUI2lnCRbib67AD16z2XdTsETBhPaRHIqGqhFR4loHIap5KluWxMKKUNQm2A= 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 1694137038444821.6765215636186; Thu, 7 Sep 2023 18:37:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQPw-0008QJ-QE; Thu, 07 Sep 2023 21:36:16 -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 1qeQPv-0008Pr-JY for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQPt-0007sV-2Z for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:15 -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-221-nDA0AfeUPUK_wXn-Acll9w-1; Thu, 07 Sep 2023 21:36:09 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48B39816529; Fri, 8 Sep 2023 01:36:09 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7038440C2070; Fri, 8 Sep 2023 01:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136972; 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: in-reply-to:in-reply-to:references:references; bh=DRV578KzQi2bfJ0mlQnroELkcGRUQ+AZukcRhklKJ4o=; b=cNN2rnhyqn60ibUDOeRU9w27Ux10OP2CYhBSh36XCJXeAcDYsti6f1dAr+vco25rx4pVQt uZMcKG4n0pw+f3tVjstAl77Wj61ctYNqVIwxM3bBIqE7OHqO+XXatigpnsRPb02U1Wq78g D/EdW6rwUEZBsaG7oHUFCiGj+0Ghugw= X-MC-Unique: nDA0AfeUPUK_wXn-Acll9w-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Fabiano Rosas , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 02/13] nbd: drop unused nbd_receive_negotiate() aio_context argument Date: Thu, 7 Sep 2023 20:35:38 -0500 Message-ID: <20230908013535.990731-17-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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: 1694137039292100001 From: Stefan Hajnoczi aio_context is always NULL, so drop it. Suggested-by: Fabiano Rosas Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-ID: <20230830224802.493686-2-stefanha@redhat.com> Signed-off-by: Eric Blake --- include/block/nbd.h | 3 +-- nbd/client-connection.c | 3 +-- nbd/client.c | 5 ++--- qemu-nbd.c | 4 ++-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 4428bcffbb9..f672b76173b 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -324,8 +324,7 @@ typedef struct NBDExportInfo { char **contexts; } NBDExportInfo; -int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc, - QCryptoTLSCreds *tlscreds, +int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp); void nbd_free_export_list(NBDExportInfo *info, int count); diff --git a/nbd/client-connection.c b/nbd/client-connection.c index 3d14296c042..aafb3d0fb43 100644 --- a/nbd/client-connection.c +++ b/nbd/client-connection.c @@ -146,8 +146,7 @@ static int nbd_connect(QIOChannelSocket *sioc, SocketAd= dress *addr, return 0; } - ret =3D nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc), tlscreds, - tlshostname, + ret =3D nbd_receive_negotiate(QIO_CHANNEL(sioc), tlscreds, tlshostname, outioc, info, errp); if (ret < 0) { /* diff --git a/nbd/client.c b/nbd/client.c index 479208d5d9d..16ec10c8a91 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1014,8 +1014,7 @@ static int nbd_negotiate_finish_oldstyle(QIOChannel *= ioc, NBDExportInfo *info, * Returns: negative errno: failure talking to server * 0: server is connected */ -int nbd_receive_negotiate(AioContext *aio_context, QIOChannel *ioc, - QCryptoTLSCreds *tlscreds, +int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, Error **errp) { @@ -1027,7 +1026,7 @@ int nbd_receive_negotiate(AioContext *aio_context, QI= OChannel *ioc, assert(info->name && strlen(info->name) <=3D NBD_MAX_STRING_SIZE); trace_nbd_receive_negotiate_name(info->name); - result =3D nbd_start_negotiate(aio_context, ioc, tlscreds, hostname, o= utioc, + result =3D nbd_start_negotiate(NULL, ioc, tlscreds, hostname, outioc, info->structured_reply, &zeroes, errp); if (result < 0) { return result; diff --git a/qemu-nbd.c b/qemu-nbd.c index aaccaa33184..b47459f781d 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -295,8 +295,8 @@ static void *nbd_client_thread(void *arg) goto out; } - if (nbd_receive_negotiate(NULL, QIO_CHANNEL(sioc), - NULL, NULL, NULL, &info, &local_error) < 0) { + if (nbd_receive_negotiate(QIO_CHANNEL(sioc), NULL, NULL, NULL, + &info, &local_error) < 0) { if (local_error) { error_report_err(local_error); } --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137074; cv=none; d=zohomail.com; s=zohoarc; b=UOizisMjNoCTtFfM1R19QUBfaGB5OvjnD90Fxsd4Nls3VDOxVo8elbEZIyCOU1x0an50BNNB7HlV+iJb6FWDIsI98BSO35YJRw1PqWyRWydE5nyoTKfWHAzrTtaBVmasHBMBNQ/B/HoupWBn2G632jgaqScSbxO0MVw4Znbzrns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137074; h=Content-Type: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; bh=y4/luUrhIOXb/0AEEz5lSG0rtRG28lh7/LGt0/Rofa4=; b=UYlrHhl65Om/BD8ZVUZTWdc7PE6ReZB4hsMjY7zVtl/58nsC4V96AjbHS/1pKM0HM5/MZkUCKYM4OD1d4JvK1npM+oZX0Q6LiwlsD5OakQLHlOankuou7W9OgE6KqFpjfft1hjcWIkTnbiu3m/LQUC0xcz7ExFS8i6KwoYyNZXA= 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 1694137074071255.39699065053628; Thu, 7 Sep 2023 18:37:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ1-0008RV-IY; Thu, 07 Sep 2023 21:36:21 -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 1qeQPz-0008R6-P5 for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:19 -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 1qeQPx-0007tC-JC for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:19 -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-46-lqOxdrUNMtaUXG0c7xlmDA-1; Thu, 07 Sep 2023 21:36:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1061C101CA84; Fri, 8 Sep 2023 01:36:11 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73A2B40C2070; Fri, 8 Sep 2023 01:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136976; 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: in-reply-to:in-reply-to:references:references; bh=y4/luUrhIOXb/0AEEz5lSG0rtRG28lh7/LGt0/Rofa4=; b=LrRtMEGdtBL9dbCUoiuWTxbWG7OWLpV+uuky2blK5XmgPijNehEJaBnSsP5C3hD/YYxzYd Qt1flMhCWWXPZRN/lP9yN1xm/GcfDthqpbYhHMjqTh3di6hbT47NPLGObuKMXMzvVXu+8j 9hdVGoGMJWZtzLGkRYAdrTTrPKqi5Gg= X-MC-Unique: lqOxdrUNMtaUXG0c7xlmDA-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Fabiano Rosas , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 03/13] nbd: drop unused nbd_start_negotiate() aio_context argument Date: Thu, 7 Sep 2023 20:35:39 -0500 Message-ID: <20230908013535.990731-18-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_H3=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: 1694137075078100003 From: Stefan Hajnoczi aio_context is always NULL, so drop it. Suggested-by: Fabiano Rosas Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-ID: <20230830224802.493686-3-stefanha@redhat.com> Signed-off-by: Eric Blake --- nbd/client.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 16ec10c8a91..bd7e2001366 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -877,8 +877,7 @@ static int nbd_list_meta_contexts(QIOChannel *ioc, * Returns: negative errno: failure talking to server * non-negative: enum NBDMode describing server abilities */ -static int nbd_start_negotiate(AioContext *aio_context, QIOChannel *ioc, - QCryptoTLSCreds *tlscreds, +static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, bool structured_reply, bool *zeroes, Error **errp) @@ -946,10 +945,6 @@ static int nbd_start_negotiate(AioContext *aio_context= , QIOChannel *ioc, return -EINVAL; } ioc =3D *outioc; - if (aio_context) { - qio_channel_set_blocking(ioc, false, NULL); - qio_channel_attach_aio_context(ioc, aio_context); - } } else { error_setg(errp, "Server does not support STARTTLS"); return -EINVAL; @@ -1026,7 +1021,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLS= Creds *tlscreds, assert(info->name && strlen(info->name) <=3D NBD_MAX_STRING_SIZE); trace_nbd_receive_negotiate_name(info->name); - result =3D nbd_start_negotiate(NULL, ioc, tlscreds, hostname, outioc, + result =3D nbd_start_negotiate(ioc, tlscreds, hostname, outioc, info->structured_reply, &zeroes, errp); if (result < 0) { return result; @@ -1149,7 +1144,7 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, QIOChannel *sioc =3D NULL; *info =3D NULL; - result =3D nbd_start_negotiate(NULL, ioc, tlscreds, hostname, &sioc, t= rue, + result =3D nbd_start_negotiate(ioc, tlscreds, hostname, &sioc, true, NULL, errp); if (tlscreds && sioc) { ioc =3D sioc; --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137056; cv=none; d=zohomail.com; s=zohoarc; b=O4ZLtKPKHwDKe5vQ5q/yM9nWGBI1m20oLrV7MC4pdzZDyBSk7jDS3ISkOpOxot65dQ+lPHDOyZ9S6ix3NjPL2z+NrWylu6Q1jxPnFwbosg+bp4HxNEuTi5qaQwZQB8kBLEey6P1bpoGBdCEBImHtK4soRchWdclVVWE2EShkydE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137056; h=Content-Type: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; bh=h81esWg0ORmCPFztf/1p+Z2W1LI8v1JzfQWGinC7MR4=; b=S41RoRuhViGcvFxhcgQ32xyiQFSC9qvXa/1AGepwxKJFKz0g1IG1QHqTs7L0TQ9+a8+oy4HSbqDY4DY/nKQ5IR5sj/cKi7qSLdqkvOol7jz1whraPdnRYGJUE/FomndrgK+yJRI+pYZEo2NYbQt0kWiN2S7nXHKU2Kcak2LzBRg= 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 1694137056460789.3383428181764; Thu, 7 Sep 2023 18:37:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQPy-0008Qo-Vy; Thu, 07 Sep 2023 21:36:19 -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 1qeQPx-0008QZ-9v for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:17 -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 1qeQPu-0007sr-A7 for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:17 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-152-kjh7oR6TOLmmqaCVcsTuQg-1; Thu, 07 Sep 2023 21:36:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9485F1C07834 for ; Fri, 8 Sep 2023 01:36:11 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A24740C2070; Fri, 8 Sep 2023 01:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136973; 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: in-reply-to:in-reply-to:references:references; bh=h81esWg0ORmCPFztf/1p+Z2W1LI8v1JzfQWGinC7MR4=; b=AJG5bApGGzrZSpL41qxiWpbHGVu8qY/b6YGYCyPkvtJhcrdA9UV1NCEwkQeYXEGSkY36JC WohFy6Fkxm1/LJvyNzZmGIfbcrIE0jQ3PDhPiFqB/RFMfo0O3RjCV4XnGcQNOp4NDhMe3C /npUGZpuoEgQs2jGbXk28HfiQri/br0= X-MC-Unique: kjh7oR6TOLmmqaCVcsTuQg-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 04/13] io: check there are no qio_channel_yield() coroutines during ->finalize() Date: Thu, 7 Sep 2023 20:35:40 -0500 Message-ID: <20230908013535.990731-19-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_H3=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: 1694137056858100002 From: Stefan Hajnoczi Callers must clean up their coroutines before calling object_unref(OBJECT(ioc)) to prevent an fd handler leak. Add an assertion to check this. This patch is preparation for the fd handler changes that follow. Signed-off-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Eric Blake Message-ID: <20230830224802.493686-4-stefanha@redhat.com> Signed-off-by: Eric Blake --- io/channel.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/io/channel.c b/io/channel.c index 72f0066af55..c415f3fc885 100644 --- a/io/channel.c +++ b/io/channel.c @@ -653,6 +653,10 @@ static void qio_channel_finalize(Object *obj) { QIOChannel *ioc =3D QIO_CHANNEL(obj); + /* Must not have coroutines in qio_channel_yield() */ + assert(!ioc->read_coroutine); + assert(!ioc->write_coroutine); + g_free(ioc->name); #ifdef _WIN32 --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137076; cv=none; d=zohomail.com; s=zohoarc; b=U//4lnTKVYiYANZaMfuFSkQocZD9lvJk2xQ0xySvtMPOxdrAbbZ7wfa5dvUHspqbyiwGREdMTyDuR2z1Xy42VT5leRa/QVldAmb0SmSw380282412J50r2nIP5ufnmN7//D0fOS2KsVg30fYKKCZSjDfUYG/calitx3ccznLOIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137076; h=Content-Type: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; bh=0A2MuW3pirpCG4J9HgyBSN3Er/f0vcZE1s1N9HBaamc=; b=mktIdSOYjSenPcjSDgC3GvY+/zVZwfoJB7ooDV5lYv/6rexIUlHyFXqRnp1Vyk7AbKp8ycz6it6ZzL1ZBDfS+3+lu3d3Mb3O6cs6sCYqAov/LEswRCsu2OeRxglgNlL1kP1uL6oBuvE3HPhK7bQ6HD3LhhODkyRkpgB6TA8sY8Q= 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 1694137076419164.07242663974728; Thu, 7 Sep 2023 18:37:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ4-0008TN-Mi; Thu, 07 Sep 2023 21:36:24 -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 1qeQQ3-0008Sb-EW for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQPz-0007tU-6W for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:23 -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-351-JIrkddLAP0aVkg8jzO8e2w-1; Thu, 07 Sep 2023 21:36:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 26C3A8007CE; Fri, 8 Sep 2023 01:36:14 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id F26E340C2070; Fri, 8 Sep 2023 01:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136978; 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: in-reply-to:in-reply-to:references:references; bh=0A2MuW3pirpCG4J9HgyBSN3Er/f0vcZE1s1N9HBaamc=; b=Z1m1Lk++3sCmbw7qXIFSPGxXEq6ROs/7v2digIWSX7Q4BOJYUedvcMh0AD8o9buRh0JL8Q ztudc+H0Vs8kFx7MwD1dRumtwIEnb9qlfxxFKqi4rZa4myn64nhdu0lgS0ReJr0Gnic1Qo 0qSLgcFDg++W7/igbWRr+VhVO4zF+XY= X-MC-Unique: JIrkddLAP0aVkg8jzO8e2w-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , Coiby Xu , Juan Quintela , Peter Xu , Leonardo Bras , Paolo Bonzini , Fam Zheng , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 05/13] io: follow coroutine AioContext in qio_channel_yield() Date: Thu, 7 Sep 2023 20:35:41 -0500 Message-ID: <20230908013535.990731-20-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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: 1694137077147100002 From: Stefan Hajnoczi The ongoing QEMU multi-queue block layer effort makes it possible for multi= ple threads to process I/O in parallel. The nbd block driver is not compatible = with the multi-queue block layer yet because QIOChannel cannot be used easily fr= om coroutines running in multiple threads. This series changes the QIOChannel = API to make that possible. In the current API, calling qio_channel_attach_aio_context() sets the AioContext where qio_channel_yield() installs an fd handler prior to yieldi= ng: qio_channel_attach_aio_context(ioc, my_ctx); ... qio_channel_yield(ioc); // my_ctx is used here ... qio_channel_detach_aio_context(ioc); This API design has limitations: reading and writing must be done in the sa= me AioContext and moving between AioContexts involves a cumbersome sequence of= API calls that is not suitable for doing on a per-request basis. There is no fundamental reason why a QIOChannel needs to run within the same AioContext every time qio_channel_yield() is called. QIOChannel only uses the AioContext while inside qio_channel_yield(). The rest of the time, QIOChannel is independent of any AioContext. In the new API, qio_channel_yield() queries the AioContext from the current coroutine using qemu_coroutine_get_aio_context(). There is no need to explicitly attach/detach AioContexts anymore and qio_channel_attach_aio_context() and qio_channel_detach_aio_context() are g= one. One coroutine can read from the QIOChannel while another coroutine writes f= rom a different AioContext. This API change allows the nbd block driver to use QIOChannel from any thre= ad. It's important to keep in mind that the block driver already synchronizes QIOChannel access and ensures that two coroutines never read simultaneously= or write simultaneously. This patch updates all users of qio_channel_attach_aio_context() to the new API. Most conversions are simple, but vhost-user-server requires a new qemu_coroutine_yield() call to quiesce the vu_client_trip() coroutine when not attached to any AioContext. While the API is has become simpler, there is one wart: QIOChannel has a special case for the iohandler AioContext (used for handlers that must not = run in nested event loops). I didn't find an elegant way preserve that behavior= , so I added a new API called qio_channel_set_follow_coroutine_ctx(ioc, true|fal= se) for opting in to the new AioContext model. By default QIOChannel uses the iohandler AioHandler. Code that formerly called qio_channel_attach_aio_context() now calls qio_channel_set_follow_coroutine_ctx(ioc, true) once after the QIOChannel is created. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Acked-by: Daniel P. Berrang=C3=A9 Message-ID: <20230830224802.493686-5-stefanha@redhat.com> [eblake: also fix migration/rdma.c] Signed-off-by: Eric Blake --- include/io/channel-util.h | 23 ++++++ include/io/channel.h | 69 ++++++++---------- include/qemu/vhost-user-server.h | 1 + block/nbd.c | 11 +-- io/channel-command.c | 10 ++- io/channel-file.c | 9 ++- io/channel-null.c | 3 +- io/channel-socket.c | 9 ++- io/channel-tls.c | 6 +- io/channel-util.c | 24 +++++++ io/channel.c | 120 ++++++++++++++++++++++--------- migration/channel-block.c | 3 +- migration/rdma.c | 25 +++---- nbd/server.c | 14 +--- scsi/qemu-pr-helper.c | 4 +- util/vhost-user-server.c | 27 +++++-- 16 files changed, 229 insertions(+), 129 deletions(-) diff --git a/include/io/channel-util.h b/include/io/channel-util.h index a5d720d9a04..fa18a3756d8 100644 --- a/include/io/channel-util.h +++ b/include/io/channel-util.h @@ -49,4 +49,27 @@ QIOChannel *qio_channel_new_fd(int fd, Error **errp); +/** + * qio_channel_util_set_aio_fd_handler: + * @read_fd: the file descriptor for the read handler + * @read_ctx: the AioContext for the read handler + * @io_read: the read handler + * @write_fd: the file descriptor for the write handler + * @write_ctx: the AioContext for the write handler + * @io_write: the write handler + * @opaque: the opaque argument to the read and write handler + * + * Set the read and write handlers when @read_ctx and @write_ctx are non-N= ULL, + * respectively. To leave a handler in its current state, pass a NULL + * AioContext. To clear a handler, pass a non-NULL AioContext and a NULL + * handler. + */ +void qio_channel_util_set_aio_fd_handler(int read_fd, + AioContext *read_ctx, + IOHandler *io_read, + int write_fd, + AioContext *write_ctx, + IOHandler *io_write, + void *opaque); + #endif /* QIO_CHANNEL_UTIL_H */ diff --git a/include/io/channel.h b/include/io/channel.h index 229bf36910f..5f9dbaab65b 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -81,9 +81,11 @@ struct QIOChannel { Object parent; unsigned int features; /* bitmask of QIOChannelFeatures */ char *name; - AioContext *ctx; + AioContext *read_ctx; Coroutine *read_coroutine; + AioContext *write_ctx; Coroutine *write_coroutine; + bool follow_coroutine_ctx; #ifdef _WIN32 HANDLE event; /* For use with GSource on Win32 */ #endif @@ -140,8 +142,9 @@ struct QIOChannelClass { int whence, Error **errp); void (*io_set_aio_fd_handler)(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque); int (*io_flush)(QIOChannel *ioc, @@ -498,6 +501,21 @@ int qio_channel_set_blocking(QIOChannel *ioc, bool enabled, Error **errp); +/** + * qio_channel_set_follow_coroutine_ctx: + * @ioc: the channel object + * @enabled: whether or not to follow the coroutine's AioContext + * + * If @enabled is true, calls to qio_channel_yield() use the current + * coroutine's AioContext. Usually this is desirable. + * + * If @enabled is false, calls to qio_channel_yield() use the global iohan= dler + * AioContext. This is may be used by coroutines that run in the main loop= and + * do not wish to respond to I/O during nested event loops. This is the + * default for compatibility with code that is not aware of AioContexts. + */ +void qio_channel_set_follow_coroutine_ctx(QIOChannel *ioc, bool enabled); + /** * qio_channel_close: * @ioc: the channel object @@ -703,41 +721,6 @@ GSource *qio_channel_add_watch_source(QIOChannel *ioc, GDestroyNotify notify, GMainContext *context); -/** - * qio_channel_attach_aio_context: - * @ioc: the channel object - * @ctx: the #AioContext to set the handlers on - * - * Request that qio_channel_yield() sets I/O handlers on - * the given #AioContext. If @ctx is %NULL, qio_channel_yield() - * uses QEMU's main thread event loop. - * - * You can move a #QIOChannel from one #AioContext to another even if - * I/O handlers are set for a coroutine. However, #QIOChannel provides - * no synchronization between the calls to qio_channel_yield() and - * qio_channel_attach_aio_context(). - * - * Therefore you should first call qio_channel_detach_aio_context() - * to ensure that the coroutine is not entered concurrently. Then, - * while the coroutine has yielded, call qio_channel_attach_aio_context(), - * and then aio_co_schedule() to place the coroutine on the new - * #AioContext. The calls to qio_channel_detach_aio_context() - * and qio_channel_attach_aio_context() should be protected with - * aio_context_acquire() and aio_context_release(). - */ -void qio_channel_attach_aio_context(QIOChannel *ioc, - AioContext *ctx); - -/** - * qio_channel_detach_aio_context: - * @ioc: the channel object - * - * Disable any I/O handlers set by qio_channel_yield(). With the - * help of aio_co_schedule(), this allows moving a coroutine that was - * paused by qio_channel_yield() to another context. - */ -void qio_channel_detach_aio_context(QIOChannel *ioc); - /** * qio_channel_yield: * @ioc: the channel object @@ -785,8 +768,9 @@ void qio_channel_wait(QIOChannel *ioc, /** * qio_channel_set_aio_fd_handler: * @ioc: the channel object - * @ctx: the AioContext to set the handlers on + * @read_ctx: the AioContext to set the read handler on or NULL * @io_read: the read handler + * @write_ctx: the AioContext to set the write handler on or NULL * @io_write: the write handler * @opaque: the opaque value passed to the handler * @@ -794,10 +778,17 @@ void qio_channel_wait(QIOChannel *ioc, * be used by channel implementations to forward the handlers * to another channel (e.g. from #QIOChannelTLS to the * underlying socket). + * + * When @read_ctx is NULL, don't touch the read handler. When @write_ctx is + * NULL, don't touch the write handler. Note that setting the read handler + * clears the write handler, and vice versa, if they share the same AioCon= text. + * Therefore the caller must pass both handlers together when sharing the = same + * AioContext. */ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque); diff --git a/include/qemu/vhost-user-server.h b/include/qemu/vhost-user-ser= ver.h index b1c1cda8862..64ad7010157 100644 --- a/include/qemu/vhost-user-server.h +++ b/include/qemu/vhost-user-server.h @@ -43,6 +43,7 @@ typedef struct { unsigned int in_flight; /* atomic */ /* Protected by ctx lock */ + bool in_qio_channel_yield; bool wait_idle; VuDev vu_dev; QIOChannel *ioc; /* The I/O channel with the client */ diff --git a/block/nbd.c b/block/nbd.c index 5322e66166c..cc48580df70 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -352,7 +352,7 @@ int coroutine_fn nbd_co_do_establish_connection(BlockDr= iverState *bs, } qio_channel_set_blocking(s->ioc, false, NULL); - qio_channel_attach_aio_context(s->ioc, bdrv_get_aio_context(bs)); + qio_channel_set_follow_coroutine_ctx(s->ioc, true); /* successfully connected */ WITH_QEMU_LOCK_GUARD(&s->requests_lock) { @@ -397,7 +397,6 @@ static void coroutine_fn GRAPH_RDLOCK nbd_reconnect_att= empt(BDRVNBDState *s) /* Finalize previous connection if any */ if (s->ioc) { - qio_channel_detach_aio_context(s->ioc); yank_unregister_function(BLOCKDEV_YANK_INSTANCE(s->bs->node_name), nbd_yank, s->bs); object_unref(OBJECT(s->ioc)); @@ -2089,10 +2088,6 @@ static void nbd_attach_aio_context(BlockDriverState = *bs, * the reconnect_delay_timer cannot be active here. */ assert(!s->reconnect_delay_timer); - - if (s->ioc) { - qio_channel_attach_aio_context(s->ioc, new_context); - } } static void nbd_detach_aio_context(BlockDriverState *bs) @@ -2101,10 +2096,6 @@ static void nbd_detach_aio_context(BlockDriverState = *bs) assert(!s->open_timer); assert(!s->reconnect_delay_timer); - - if (s->ioc) { - qio_channel_detach_aio_context(s->ioc); - } } static BlockDriver bdrv_nbd =3D { diff --git a/io/channel-command.c b/io/channel-command.c index 7ed726c8025..6d5f64e146d 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "io/channel-command.h" +#include "io/channel-util.h" #include "io/channel-watch.h" #include "qapi/error.h" #include "qemu/module.h" @@ -331,14 +332,17 @@ static int qio_channel_command_close(QIOChannel *ioc, static void qio_channel_command_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); - aio_set_fd_handler(ctx, cioc->readfd, io_read, NULL, NULL, NULL, opaqu= e); - aio_set_fd_handler(ctx, cioc->writefd, NULL, io_write, NULL, NULL, opa= que); + + qio_channel_util_set_aio_fd_handler(cioc->readfd, read_ctx, io_read, + cioc->writefd, write_ctx, io_write, + opaque); } diff --git a/io/channel-file.c b/io/channel-file.c index 8b5821f4526..4a12c618860 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "io/channel-file.h" +#include "io/channel-util.h" #include "io/channel-watch.h" #include "qapi/error.h" #include "qemu/module.h" @@ -192,13 +193,17 @@ static int qio_channel_file_close(QIOChannel *ioc, static void qio_channel_file_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); - aio_set_fd_handler(ctx, fioc->fd, io_read, io_write, NULL, NULL, opaqu= e); + + qio_channel_util_set_aio_fd_handler(fioc->fd, read_ctx, io_read, + fioc->fd, write_ctx, io_write, + opaque); } static GSource *qio_channel_file_create_watch(QIOChannel *ioc, diff --git a/io/channel-null.c b/io/channel-null.c index 4fafdb770da..ef995863483 100644 --- a/io/channel-null.c +++ b/io/channel-null.c @@ -128,8 +128,9 @@ qio_channel_null_close(QIOChannel *ioc, static void qio_channel_null_set_aio_fd_handler(QIOChannel *ioc G_GNUC_UNUSED, - AioContext *ctx G_GNUC_UNUSED, + AioContext *read_ctx G_GNUC_UNUSED, IOHandler *io_read G_GNUC_UNUSED, + AioContext *write_ctx G_GNUC_UNUSED, IOHandler *io_write G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { diff --git a/io/channel-socket.c b/io/channel-socket.c index d99945ebec4..02ffb51e995 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -22,6 +22,7 @@ #include "qapi/qapi-visit-sockets.h" #include "qemu/module.h" #include "io/channel-socket.h" +#include "io/channel-util.h" #include "io/channel-watch.h" #include "trace.h" #include "qapi/clone-visitor.h" @@ -893,13 +894,17 @@ qio_channel_socket_shutdown(QIOChannel *ioc, } static void qio_channel_socket_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); - aio_set_fd_handler(ctx, sioc->fd, io_read, io_write, NULL, NULL, opaqu= e); + + qio_channel_util_set_aio_fd_handler(sioc->fd, read_ctx, io_read, + sioc->fd, write_ctx, io_write, + opaque); } static GSource *qio_channel_socket_create_watch(QIOChannel *ioc, diff --git a/io/channel-tls.c b/io/channel-tls.c index 847d5297c33..58fe1aceeea 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -388,14 +388,16 @@ static int qio_channel_tls_close(QIOChannel *ioc, } static void qio_channel_tls_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(ioc); - qio_channel_set_aio_fd_handler(tioc->master, ctx, io_read, io_write, o= paque); + qio_channel_set_aio_fd_handler(tioc->master, read_ctx, io_read, + write_ctx, io_write, opaque); } typedef struct QIOChannelTLSSource QIOChannelTLSSource; diff --git a/io/channel-util.c b/io/channel-util.c index 848a7a43d67..4b340d46d76 100644 --- a/io/channel-util.c +++ b/io/channel-util.c @@ -36,3 +36,27 @@ QIOChannel *qio_channel_new_fd(int fd, } return ioc; } + + +void qio_channel_util_set_aio_fd_handler(int read_fd, + AioContext *read_ctx, + IOHandler *io_read, + int write_fd, + AioContext *write_ctx, + IOHandler *io_write, + void *opaque) +{ + if (read_fd =3D=3D write_fd && read_ctx =3D=3D write_ctx) { + aio_set_fd_handler(read_ctx, read_fd, io_read, io_write, + NULL, NULL, opaque); + } else { + if (read_ctx) { + aio_set_fd_handler(read_ctx, read_fd, io_read, NULL, + NULL, NULL, opaque); + } + if (write_ctx) { + aio_set_fd_handler(write_ctx, write_fd, NULL, io_write, + NULL, NULL, opaque); + } + } +} diff --git a/io/channel.c b/io/channel.c index c415f3fc885..86c5834510f 100644 --- a/io/channel.c +++ b/io/channel.c @@ -365,6 +365,12 @@ int qio_channel_set_blocking(QIOChannel *ioc, } +void qio_channel_set_follow_coroutine_ctx(QIOChannel *ioc, bool enabled) +{ + ioc->follow_coroutine_ctx =3D enabled; +} + + int qio_channel_close(QIOChannel *ioc, Error **errp) { @@ -388,14 +394,16 @@ GSource *qio_channel_create_watch(QIOChannel *ioc, void qio_channel_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); - klass->io_set_aio_fd_handler(ioc, ctx, io_read, io_write, opaque); + klass->io_set_aio_fd_handler(ioc, read_ctx, io_read, write_ctx, io_wri= te, + opaque); } guint qio_channel_add_watch_full(QIOChannel *ioc, @@ -542,56 +550,101 @@ static void qio_channel_restart_write(void *opaque) aio_co_wake(co); } -static void qio_channel_set_aio_fd_handlers(QIOChannel *ioc) +static void coroutine_fn +qio_channel_set_fd_handlers(QIOChannel *ioc, GIOCondition condition) { - IOHandler *rd_handler =3D NULL, *wr_handler =3D NULL; + AioContext *ctx =3D ioc->follow_coroutine_ctx ? + qemu_coroutine_get_aio_context(qemu_coroutine_self()) : + iohandler_get_aio_context(); + AioContext *read_ctx =3D NULL; + IOHandler *io_read =3D NULL; + AioContext *write_ctx =3D NULL; + IOHandler *io_write =3D NULL; + + if (condition =3D=3D G_IO_IN) { + ioc->read_coroutine =3D qemu_coroutine_self(); + ioc->read_ctx =3D ctx; + read_ctx =3D ctx; + io_read =3D qio_channel_restart_read; + + /* + * Thread safety: if the other coroutine is set and its AioContext + * matches ours, then there is mutual exclusion between read and w= rite + * because they share a single thread and it's safe to set both re= ad + * and write fd handlers here. If the AioContext does not match ou= rs, + * then both threads may run in parallel but there is no shared st= ate + * to worry about. + */ + if (ioc->write_coroutine && ioc->write_ctx =3D=3D ctx) { + write_ctx =3D ctx; + io_write =3D qio_channel_restart_write; + } + } else if (condition =3D=3D G_IO_OUT) { + ioc->write_coroutine =3D qemu_coroutine_self(); + ioc->write_ctx =3D ctx; + write_ctx =3D ctx; + io_write =3D qio_channel_restart_write; + if (ioc->read_coroutine && ioc->read_ctx =3D=3D ctx) { + read_ctx =3D ctx; + io_read =3D qio_channel_restart_read; + } + } else { + abort(); + } + + qio_channel_set_aio_fd_handler(ioc, read_ctx, io_read, + write_ctx, io_write, ioc); +} + +static void coroutine_fn +qio_channel_clear_fd_handlers(QIOChannel *ioc, GIOCondition condition) +{ + AioContext *read_ctx =3D NULL; + IOHandler *io_read =3D NULL; + AioContext *write_ctx =3D NULL; + IOHandler *io_write =3D NULL; AioContext *ctx; - if (ioc->read_coroutine) { - rd_handler =3D qio_channel_restart_read; + if (condition =3D=3D G_IO_IN) { + ctx =3D ioc->read_ctx; + read_ctx =3D ctx; + io_read =3D NULL; + if (ioc->write_coroutine && ioc->write_ctx =3D=3D ctx) { + write_ctx =3D ctx; + io_write =3D qio_channel_restart_write; + } + } else if (condition =3D=3D G_IO_OUT) { + ctx =3D ioc->write_ctx; + write_ctx =3D ctx; + io_write =3D NULL; + if (ioc->read_coroutine && ioc->read_ctx =3D=3D ctx) { + read_ctx =3D ctx; + io_read =3D qio_channel_restart_read; + } + } else { + abort(); } - if (ioc->write_coroutine) { - wr_handler =3D qio_channel_restart_write; - } - - ctx =3D ioc->ctx ? ioc->ctx : iohandler_get_aio_context(); - qio_channel_set_aio_fd_handler(ioc, ctx, rd_handler, wr_handler, ioc); -} - -void qio_channel_attach_aio_context(QIOChannel *ioc, - AioContext *ctx) -{ - assert(!ioc->read_coroutine); - assert(!ioc->write_coroutine); - ioc->ctx =3D ctx; -} -void qio_channel_detach_aio_context(QIOChannel *ioc) -{ - ioc->read_coroutine =3D NULL; - ioc->write_coroutine =3D NULL; - qio_channel_set_aio_fd_handlers(ioc); - ioc->ctx =3D NULL; + qio_channel_set_aio_fd_handler(ioc, read_ctx, io_read, + write_ctx, io_write, ioc); } void coroutine_fn qio_channel_yield(QIOChannel *ioc, GIOCondition condition) { - AioContext *ioc_ctx =3D ioc->ctx ?: qemu_get_aio_context(); + AioContext *ioc_ctx; assert(qemu_in_coroutine()); - assert(in_aio_context_home_thread(ioc_ctx)); + ioc_ctx =3D qemu_coroutine_get_aio_context(qemu_coroutine_self()); if (condition =3D=3D G_IO_IN) { assert(!ioc->read_coroutine); - ioc->read_coroutine =3D qemu_coroutine_self(); } else if (condition =3D=3D G_IO_OUT) { assert(!ioc->write_coroutine); - ioc->write_coroutine =3D qemu_coroutine_self(); } else { abort(); } - qio_channel_set_aio_fd_handlers(ioc); + qio_channel_set_fd_handlers(ioc, condition); qemu_coroutine_yield(); assert(in_aio_context_home_thread(ioc_ctx)); @@ -599,11 +652,10 @@ void coroutine_fn qio_channel_yield(QIOChannel *ioc, * through the aio_fd_handlers. */ if (condition =3D=3D G_IO_IN) { assert(ioc->read_coroutine =3D=3D NULL); - qio_channel_set_aio_fd_handlers(ioc); } else if (condition =3D=3D G_IO_OUT) { assert(ioc->write_coroutine =3D=3D NULL); - qio_channel_set_aio_fd_handlers(ioc); } + qio_channel_clear_fd_handlers(ioc, condition); } void qio_channel_wake_read(QIOChannel *ioc) diff --git a/migration/channel-block.c b/migration/channel-block.c index b7374363c3f..fff8d870942 100644 --- a/migration/channel-block.c +++ b/migration/channel-block.c @@ -158,8 +158,9 @@ qio_channel_block_close(QIOChannel *ioc, static void qio_channel_block_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, + AioContext *read_ctx, IOHandler *io_read, + AioContext *write_ctx, IOHandler *io_write, void *opaque) { diff --git a/migration/rdma.c b/migration/rdma.c index ca430d319d9..a2a3db35b1d 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3103,22 +3103,23 @@ static GSource *qio_channel_rdma_create_watch(QIOCh= annel *ioc, } static void qio_channel_rdma_set_aio_fd_handler(QIOChannel *ioc, - AioContext *ctx, - IOHandler *io_read, - IOHandler *io_write, - void *opaque) + AioContext *read_ctx, + IOHandler *io_read, + AioContext *write_ctx, + IOHandler *io_write, + void *opaque) { QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(ioc); if (io_read) { - aio_set_fd_handler(ctx, rioc->rdmain->recv_comp_channel->fd, io_re= ad, - io_write, NULL, NULL, opaque); - aio_set_fd_handler(ctx, rioc->rdmain->send_comp_channel->fd, io_re= ad, - io_write, NULL, NULL, opaque); + aio_set_fd_handler(read_ctx, rioc->rdmain->recv_comp_channel->fd, + io_read, io_write, NULL, NULL, opaque); + aio_set_fd_handler(read_ctx, rioc->rdmain->send_comp_channel->fd, + io_read, io_write, NULL, NULL, opaque); } else { - aio_set_fd_handler(ctx, rioc->rdmaout->recv_comp_channel->fd, io_r= ead, - io_write, NULL, NULL, opaque); - aio_set_fd_handler(ctx, rioc->rdmaout->send_comp_channel->fd, io_r= ead, - io_write, NULL, NULL, opaque); + aio_set_fd_handler(write_ctx, rioc->rdmaout->recv_comp_channel->fd, + io_read, io_write, NULL, NULL, opaque); + aio_set_fd_handler(write_ctx, rioc->rdmaout->send_comp_channel->fd, + io_read, io_write, NULL, NULL, opaque); } } diff --git a/nbd/server.c b/nbd/server.c index 8486b64b15d..b5f93a20c9c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1333,6 +1333,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) */ qio_channel_set_blocking(client->ioc, false, NULL); + qio_channel_set_follow_coroutine_ctx(client->ioc, true); trace_nbd_negotiate_begin(); memcpy(buf, "NBDMAGIC", 8); @@ -1352,11 +1353,6 @@ static coroutine_fn int nbd_negotiate(NBDClient *cli= ent, Error **errp) return ret; } - /* Attach the channel to the same AioContext as the export */ - if (client->exp && client->exp->common.ctx) { - qio_channel_attach_aio_context(client->ioc, client->exp->common.ct= x); - } - assert(!client->optlen); trace_nbd_negotiate_success(); @@ -1465,7 +1461,6 @@ void nbd_client_put(NBDClient *client) */ assert(client->closing); - qio_channel_detach_aio_context(client->ioc); object_unref(OBJECT(client->sioc)); object_unref(OBJECT(client->ioc)); if (client->tlscreds) { @@ -1544,8 +1539,6 @@ static void blk_aio_attached(AioContext *ctx, void *o= paque) exp->common.ctx =3D ctx; QTAILQ_FOREACH(client, &exp->clients, next) { - qio_channel_attach_aio_context(client->ioc, ctx); - assert(client->nb_requests =3D=3D 0); assert(client->recv_coroutine =3D=3D NULL); assert(client->send_coroutine =3D=3D NULL); @@ -1555,14 +1548,9 @@ static void blk_aio_attached(AioContext *ctx, void *= opaque) static void blk_aio_detach(void *opaque) { NBDExport *exp =3D opaque; - NBDClient *client; trace_nbd_blk_aio_detach(exp->name, exp->common.ctx); - QTAILQ_FOREACH(client, &exp->clients, next) { - qio_channel_detach_aio_context(client->ioc); - } - exp->common.ctx =3D NULL; } diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index ae44a816e17..c6c6347e9b6 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -735,8 +735,7 @@ static void coroutine_fn prh_co_entry(void *opaque) qio_channel_set_blocking(QIO_CHANNEL(client->ioc), false, NULL); - qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), - qemu_get_aio_context()); + qio_channel_set_follow_coroutine_ctx(QIO_CHANNEL(client->ioc), true); /* A very simple negotiation for future extensibility. No features * are defined so write 0. @@ -796,7 +795,6 @@ static void coroutine_fn prh_co_entry(void *opaque) } out: - qio_channel_detach_aio_context(QIO_CHANNEL(client->ioc)); object_unref(OBJECT(client->ioc)); g_free(client); } diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index cd17fb53265..b4b6bf30a21 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -127,7 +127,14 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserM= sg *vmsg) if (rc < 0) { if (rc =3D=3D QIO_CHANNEL_ERR_BLOCK) { assert(local_err =3D=3D NULL); - qio_channel_yield(ioc, G_IO_IN); + if (server->ctx) { + server->in_qio_channel_yield =3D true; + qio_channel_yield(ioc, G_IO_IN); + server->in_qio_channel_yield =3D false; + } else { + /* Wait until attached to an AioContext again */ + qemu_coroutine_yield(); + } continue; } else { error_report_err(local_err); @@ -278,7 +285,7 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt, vu_fd_watch->fd =3D fd; vu_fd_watch->cb =3D cb; qemu_socket_set_nonblock(fd); - aio_set_fd_handler(server->ioc->ctx, fd, kick_handler, + aio_set_fd_handler(server->ctx, fd, kick_handler, NULL, NULL, NULL, vu_fd_watch); vu_fd_watch->vu_dev =3D vu_dev; vu_fd_watch->pvt =3D pvt; @@ -299,7 +306,7 @@ static void remove_watch(VuDev *vu_dev, int fd) if (!vu_fd_watch) { return; } - aio_set_fd_handler(server->ioc->ctx, fd, NULL, NULL, NULL, NULL, NULL); + aio_set_fd_handler(server->ctx, fd, NULL, NULL, NULL, NULL, NULL); QTAILQ_REMOVE(&server->vu_fd_watches, vu_fd_watch, next); g_free(vu_fd_watch); @@ -344,6 +351,8 @@ static void vu_accept(QIONetListener *listener, QIOChan= nelSocket *sioc, /* TODO vu_message_write() spins if non-blocking! */ qio_channel_set_blocking(server->ioc, false, NULL); + qio_channel_set_follow_coroutine_ctx(server->ioc, true); + server->co_trip =3D qemu_coroutine_create(vu_client_trip, server); aio_context_acquire(server->ctx); @@ -399,13 +408,12 @@ void vhost_user_server_attach_aio_context(VuServer *s= erver, AioContext *ctx) return; } - qio_channel_attach_aio_context(server->ioc, ctx); - QTAILQ_FOREACH(vu_fd_watch, &server->vu_fd_watches, next) { aio_set_fd_handler(ctx, vu_fd_watch->fd, kick_handler, NULL, NULL, NULL, vu_fd_watch); } + assert(!server->in_qio_channel_yield); aio_co_schedule(ctx, server->co_trip); } @@ -419,11 +427,16 @@ void vhost_user_server_detach_aio_context(VuServer *s= erver) aio_set_fd_handler(server->ctx, vu_fd_watch->fd, NULL, NULL, NULL, NULL, vu_fd_watch); } - - qio_channel_detach_aio_context(server->ioc); } server->ctx =3D NULL; + + if (server->ioc) { + if (server->in_qio_channel_yield) { + /* Stop receiving the next vhost-user message */ + qio_channel_wake_read(server->ioc); + } + } } bool vhost_user_server_start(VuServer *server, --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137085; cv=none; d=zohomail.com; s=zohoarc; b=HEzmXJsLINWHmwSChXXPcwMFvxbgVO6Xg7ZkJRQM2ag+uWfrcvmr88GXuZsrZO8hEiFEQUGbjOstNH8C7WzGziPvm7XVmopYE4xETieguOMiMFh76EHMPEeW1lfTvpo2ocryh3h63WjiyIR2FxmQ5KyLzQthMUhdE4AfMEjK3AM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137085; h=Content-Type: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; bh=CtSjEfAHzdABoPlEeICugrYydeLlInhjYHAqu5v/yu8=; b=ife1KGUEQFQT/NiGcRc9FUQQNzJrEeOcdf/6T+JqjS35a3p2BjLp/7CIawpy4C0Zx53qHRxIdNnilbaMIVWjvrYDgAQhS2YR0DMvYPm/Rct/NNwRQSMiVoygMpvzB+tVWeI+mXbjklx3lKsU22GKn8VZsdJFt8GE76gSn06kKXs= 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 1694137085724325.8859048877322; Thu, 7 Sep 2023 18:38:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ5-0008U0-Jp; Thu, 07 Sep 2023 21:36:25 -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 1qeQQ3-0008Sk-Lx for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:23 -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 1qeQPz-0007ti-V3 for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:23 -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-144-HDzedw99Pm6C-GTspxfQdg-1; Thu, 07 Sep 2023 21:36:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A5493811728; Fri, 8 Sep 2023 01:36:14 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5083040C2070; Fri, 8 Sep 2023 01:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136979; 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: in-reply-to:in-reply-to:references:references; bh=CtSjEfAHzdABoPlEeICugrYydeLlInhjYHAqu5v/yu8=; b=dOt9gOUtmcjwz4lP10WBHV+rp2byv5pUpWBOEvEEVA/d/XcVnAPtC2SbclhImhOWV9NFTr kTgRPF6m4U9azBjgIRoGhQGUcu7AxCerOu+nd4YYDQZ0KO7Ve0Vpnek7hdlrNXmRm2qGXU 7FwsGfds59JDwMj4VBmgeQhZ2argCnA= X-MC-Unique: HDzedw99Pm6C-GTspxfQdg-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PULL 06/13] util/iov: Avoid dynamic stack allocation Date: Thu, 7 Sep 2023 20:35:42 -0500 Message-ID: <20230908013535.990731-21-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_H3=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: 1694137087024100001 From: Philippe Mathieu-Daud=C3=A9 Use autofree heap allocation instead of variable-length array on the stack. The codebase has very few VLAs, and if we can get rid of them all we can make the compiler error on new additions. This is a defensive measure against security bugs where an on-stack dynamic allocation isn't correctly size-checked (e.g. CVE-2021-3527). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Peter Maydell Message-ID: <20230824164706.2652277-1-peter.maydell@linaro.org> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- util/iov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/iov.c b/util/iov.c index 866fb577f30..7e73948f5e3 100644 --- a/util/iov.c +++ b/util/iov.c @@ -571,7 +571,7 @@ static int sortelem_cmp_src_index(const void *a, const = void *b) */ void qemu_iovec_clone(QEMUIOVector *dest, const QEMUIOVector *src, void *b= uf) { - IOVectorSortElem sortelems[src->niov]; + g_autofree IOVectorSortElem *sortelems =3D g_new(IOVectorSortElem, src= ->niov); void *last_end; int i; --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137047; cv=none; d=zohomail.com; s=zohoarc; b=mujSlCGWWoOqaEaJrZVQGgAEDHdk5SusUNQ7oj+PSsCc0+c72fb/U5AiIZqqbWANfH+EDt1uO+VhkZzymE1tknwjDY95uZuPKVNaGZ1vib+uWFowLf9gOvKc3hUje26SAsejcM4fyeVC8h8i5jYp5EzcSa6MVOng3b5Wpl8jiH4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137047; h=Content-Type: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; bh=qCymb+XKC5BGfrNg5MkNioHTkONLw1SJSajLqrf9dlU=; b=P8hdfKkU3nnV0RS/RKL++lYdHjUZAIW33odyvTmncI/0Cv4EtY3rtnGjSLYBvAzpTSTgYGBZVUwTkRFUr8Z/5SsONC3PxdfkaVW34aENkUAd8XO1crKSSCBqWRgnRugRT7rSl45OS1aUHIUIIitmdISHv1gO08beUndECDKXJRc= 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 1694137047534392.5628519564741; Thu, 7 Sep 2023 18:37:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ1-0008Rl-R3; Thu, 07 Sep 2023 21:36:21 -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 1qeQPz-0008RA-UO for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQPx-0007tJ-So for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:19 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-413-BIHw3ZV4OeCS4cAZISQwDg-1; Thu, 07 Sep 2023 21:36:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4A5F31C07839; Fri, 8 Sep 2023 01:36:15 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE9314024322; Fri, 8 Sep 2023 01:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136977; 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: in-reply-to:in-reply-to:references:references; bh=qCymb+XKC5BGfrNg5MkNioHTkONLw1SJSajLqrf9dlU=; b=V26sdMCRNK8/45WZnp6ajZP0TZI8LX4Mum0+TE+qGmefNYcvGB4HiaDABgl+Sql7nUSzZ5 9ycXfuaiSThbibL9wyRLDNe4PEBH+eFOzUjB63XYS8TXU97fmfc6GCPtR++JwCsLY5xEvU 1+vm5WxOp21gUfiU+07O0g1kcu7LpP8= X-MC-Unique: BIHw3ZV4OeCS4cAZISQwDg-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 07/13] qemu-nbd: improve error message for dup2 error Date: Thu, 7 Sep 2023 20:35:43 -0500 Message-ID: <20230908013535.990731-22-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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: 1694137048527100002 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" This error happens if we are not able to close the pipe to the parent (to trace errors in the child process) and assign stderr to /dev/null as required by the daemonizing convention. Signed-off-by: Denis V. Lunev Suggested-by: Eric Blake CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906093210.339585-2-den@openvz.org> Reviewed-by: Eric Blake [eblake: commit message grammar] Signed-off-by: Eric Blake --- qemu-nbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index b47459f781d..e2480061a16 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -324,7 +324,7 @@ static void *nbd_client_thread(void *arg) } else { /* Close stderr so that the qemu-nbd process exits. */ if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { - error_report("Could not set stderr to /dev/null: %s", + error_report("Could not release pipe to parent: %s", strerror(errno)); exit(EXIT_FAILURE); } @@ -1181,7 +1181,7 @@ int main(int argc, char **argv) if (fork_process) { if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { - error_report("Could not set stderr to /dev/null: %s", + error_report("Could not release pipe to parent: %s", strerror(errno)); exit(EXIT_FAILURE); } --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137120; cv=none; d=zohomail.com; s=zohoarc; b=KvTSbyV6Hhryrqv6FGgTH5QOEQX/hqlqBsOTvrg4W3lhntX/R9Xtd7ey5odAP0JpjW1EhcYpB6vxnR4wHi4BiXIDTFsln6BW1gsOx8JOK29zEeqPGor3y2soLPq08kLeenpK4XpIfSW8zMpNBGTlbp2FkJy89oOpyiDHcc1zlp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137120; h=Content-Type: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; bh=63Ix7Q5D9PN9ujxdrnZSPehQvT/Y89bchGCE2+919r0=; b=H2asRAHIWdz/OidF9IEOKF3XBX6Qe2fMbu4LQZuGfjKkEwQ8BZy/coguIp1XVjjW01ggieAw0r7FSmy4iNg8kwxlTyllLahYV5Tzs8ZuBVHiwvgOTjzZgyaPkGkKTFnY8KYPW8IbPt9cp8bgoVahw3QZCG0e5kIqRwoOcM19kSg= 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 1694137120468137.47316300149976; Thu, 7 Sep 2023 18:38:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ6-0008Uq-Lc; Thu, 07 Sep 2023 21:36:26 -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 1qeQQ4-0008TE-AH for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQQ0-0007to-5v for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:24 -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-473-vH5j-FoAPuuyBdjWvUmXmA-1; Thu, 07 Sep 2023 21:36:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3A5C948C01; Fri, 8 Sep 2023 01:36:16 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7007240C2070; Fri, 8 Sep 2023 01:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136979; 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: in-reply-to:in-reply-to:references:references; bh=63Ix7Q5D9PN9ujxdrnZSPehQvT/Y89bchGCE2+919r0=; b=LnJxqoYT+3wn8gOMhQPqeUplpJbsWACI3apaJ2IQISMwua2UI+ERMaahPzVKVynaQC/DB5 W3HxVZ3mqqnld+OcKTpOl6mnweOZPeoQ5vQBBtlRCY5Laf42tKF709qoqQRmrnJ65YXVwL MEZrZan2EPzLMIPyqzsGiTEC5sALfA8= X-MC-Unique: vH5j-FoAPuuyBdjWvUmXmA-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 08/13] qemu-nbd: define struct NbdClientOpts when HAVE_NBD_DEVICE is not defined Date: Thu, 7 Sep 2023 20:35:44 -0500 Message-ID: <20230908013535.990731-23-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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=unavailable 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: 1694137120713100001 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" This patch also drops definition of some locals in main() to avoid useless data copy. Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906093210.339585-3-den@openvz.org> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- qemu-nbd.c | 60 ++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index e2480061a16..acbdc0cd8fd 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -253,6 +253,12 @@ static int qemu_nbd_client_list(SocketAddress *saddr, = QCryptoTLSCreds *tls, } +struct NbdClientOpts { + char *device; + bool fork_process; + bool verbose; +}; + #if HAVE_NBD_DEVICE static void *show_parts(void *arg) { @@ -271,12 +277,6 @@ static void *show_parts(void *arg) return NULL; } -struct NbdClientOpts { - char *device; - bool fork_process; - bool verbose; -}; - static void *nbd_client_thread(void *arg) { struct NbdClientOpts *opts =3D arg; @@ -519,7 +519,6 @@ int main(int argc, char **argv) const char *bindto =3D NULL; const char *port =3D NULL; char *sockpath =3D NULL; - char *device =3D NULL; QemuOpts *sn_opts =3D NULL; const char *sn_id_or_name =3D NULL; const char *sopt =3D "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L"; @@ -582,16 +581,16 @@ int main(int argc, char **argv) const char *tlshostname =3D NULL; bool imageOpts =3D false; bool writethrough =3D false; /* Client will flush as needed. */ - bool verbose =3D false; - bool fork_process =3D false; bool list =3D false; unsigned socket_activation; const char *pid_file_name =3D NULL; const char *selinux_label =3D NULL; BlockExportOptions *export_opts; -#if HAVE_NBD_DEVICE - struct NbdClientOpts opts; -#endif + struct NbdClientOpts opts =3D { + .fork_process =3D false, + .verbose =3D false, + .device =3D NULL, + }; #ifdef CONFIG_POSIX os_setup_early_signal_handling(); @@ -719,7 +718,7 @@ int main(int argc, char **argv) disconnect =3D true; break; case 'c': - device =3D optarg; + opts.device =3D optarg; break; case 'e': if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 || @@ -750,7 +749,7 @@ int main(int argc, char **argv) } break; case 'v': - verbose =3D true; + opts.verbose =3D true; break; case 'V': version(argv[0]); @@ -782,7 +781,7 @@ int main(int argc, char **argv) tlsauthz =3D optarg; break; case QEMU_NBD_OPT_FORK: - fork_process =3D true; + opts.fork_process =3D true; break; case 'L': list =3D true; @@ -802,12 +801,12 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } if (export_name || export_description || dev_offset || - device || disconnect || fmt || sn_id_or_name || bitmaps || + opts.device || disconnect || fmt || sn_id_or_name || bitmaps || alloc_depth || seen_aio || seen_discard || seen_cache) { error_report("List mode is incompatible with per-device settin= gs"); exit(EXIT_FAILURE); } - if (fork_process) { + if (opts.fork_process) { error_report("List mode is incompatible with forking"); exit(EXIT_FAILURE); } @@ -832,7 +831,8 @@ int main(int argc, char **argv) } } else { /* Using socket activation - check user didn't use -p etc. */ - const char *err_msg =3D socket_activation_validate_opts(device, so= ckpath, + const char *err_msg =3D socket_activation_validate_opts(opts.devic= e, + sockpath, bindto, port, selinux_labe= l, list); @@ -850,7 +850,7 @@ int main(int argc, char **argv) } if (tlscredsid) { - if (device) { + if (opts.device) { error_report("TLS is not supported with a host device"); exit(EXIT_FAILURE); } @@ -880,7 +880,7 @@ int main(int argc, char **argv) if (selinux_label) { #ifdef CONFIG_SELINUX - if (sockpath =3D=3D NULL && device =3D=3D NULL) { + if (sockpath =3D=3D NULL && opts.device =3D=3D NULL) { error_report("--selinux-label is not permitted without --socke= t"); exit(EXIT_FAILURE); } @@ -897,7 +897,7 @@ int main(int argc, char **argv) } #if !HAVE_NBD_DEVICE - if (disconnect || device) { + if (disconnect || opts.device) { error_report("Kernel /dev/nbdN support not available"); exit(EXIT_FAILURE); } @@ -919,7 +919,7 @@ int main(int argc, char **argv) } #endif - if ((device && !verbose) || fork_process) { + if ((opts.device && !opts.verbose) || opts.fork_process) { #ifndef WIN32 g_autoptr(GError) err =3D NULL; int stderr_fd[2]; @@ -1002,9 +1002,9 @@ int main(int argc, char **argv) #endif /* WIN32 */ } - if (device !=3D NULL && sockpath =3D=3D NULL) { + if (opts.device !=3D NULL && sockpath =3D=3D NULL) { sockpath =3D g_malloc(128); - snprintf(sockpath, 128, SOCKET_PATH, basename(device)); + snprintf(sockpath, 128, SOCKET_PATH, basename(opts.device)); } server =3D qio_net_listener_new(); @@ -1145,15 +1145,9 @@ int main(int argc, char **argv) blk_exp_add(export_opts, &error_fatal); qapi_free_BlockExportOptions(export_opts); - if (device) { + if (opts.device) { #if HAVE_NBD_DEVICE int ret; - opts =3D (struct NbdClientOpts) { - .device =3D device, - .fork_process =3D fork_process, - .verbose =3D verbose, - }; - ret =3D pthread_create(&client_thread, NULL, nbd_client_thread, &o= pts); if (ret !=3D 0) { error_report("Failed to create client thread: %s", strerror(re= t)); @@ -1179,7 +1173,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - if (fork_process) { + if (opts.fork_process) { if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { error_report("Could not release pipe to parent: %s", strerror(errno)); @@ -1203,7 +1197,7 @@ int main(int argc, char **argv) qemu_opts_del(sn_opts); - if (device) { + if (opts.device) { void *ret; pthread_join(client_thread, &ret); exit(ret !=3D NULL); --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137120; cv=none; d=zohomail.com; s=zohoarc; b=QS5M0eqUWEGKye1XYHjAQaa0Y2AeXegKTERPU3d153G1WWVQ6Y9msicnh8NTw4igDYy0DbfaWOl3/R+Y4V8qUjL8DE11nBT9djDUUQbY6/mjJ5n13wvnFHkPL+YKl8oLan5uAKu/VXfL0UHFufe818r2+Qc/T5nICt5jHjTgWfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137120; h=Content-Type: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; bh=wTez80S1XdCord+X4wsj2A7zlFo9Zap+JHk8yhuflk8=; b=mEEfcCFNZ+d+XXHkHbnrLDiyWEBwMC1IBAZmF2npdfbkvFmZxeYbjyh3pi+liEN4ViTCbiJlM4D9sYVjlBTpcOUXgV3DnjIQzZmpgd70tgemAsENe3GIiqrAjOyosR44P0WdKHoMnpIaVDJQwR9XGRqiiDTiom2waru2Oh/yYoA= 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 1694137120532908.5350226115254; Thu, 7 Sep 2023 18:38:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ7-0008VS-8N; Thu, 07 Sep 2023 21:36:27 -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 1qeQQ5-0008Ti-Ev for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQQ0-0007tr-80 for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:24 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-551-zx5z4aXRM_qORPZhalV7mg-1; Thu, 07 Sep 2023 21:36:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D2AE38008A9; Fri, 8 Sep 2023 01:36:17 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09BDC40C2070; Fri, 8 Sep 2023 01:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136979; 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: in-reply-to:in-reply-to:references:references; bh=wTez80S1XdCord+X4wsj2A7zlFo9Zap+JHk8yhuflk8=; b=egARFX4+/fCligMpyk2i9+1aXFHpa51h/eQEYjQLU19Nl8qEu/TftsgKEOAZzWm9tvajcX S+6Iiyt9OMTvZHbkWhlgN/hyDCRGrGQOE2MDzqhqohPfVV7cvPQ8BQ3gPixiXQwpSlpNw2 cPxGQzcKdGA1tP/q2+K4AM6a6kkviHI= X-MC-Unique: zx5z4aXRM_qORPZhalV7mg-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 09/13] qemu-nbd: move srcpath into struct NbdClientOpts Date: Thu, 7 Sep 2023 20:35:45 -0500 Message-ID: <20230908013535.990731-24-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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: 1694137121630100003 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" We pass other parameters into nbd_client_thread() in this way. This patch makes the code more consistent. Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906093210.339585-4-den@openvz.org> Reviewed-by: Eric Blake [eblake: Note that this also cleans up a -Wshadow issue, first introduced in e5b815b0] Signed-off-by: Eric Blake --- qemu-nbd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index acbdc0cd8fd..16c59424f13 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -73,7 +73,6 @@ #define MBR_SIZE 512 -static char *srcpath; static SocketAddress *saddr; static int persistent =3D 0; static enum { RUNNING, TERMINATE, TERMINATED } state; @@ -255,6 +254,7 @@ static int qemu_nbd_client_list(SocketAddress *saddr, Q= CryptoTLSCreds *tls, struct NbdClientOpts { char *device; + char *srcpath; bool fork_process; bool verbose; }; @@ -320,7 +320,7 @@ static void *nbd_client_thread(void *arg) if (opts->verbose && !opts->fork_process) { fprintf(stderr, "NBD device %s is now connected to %s\n", - opts->device, srcpath); + opts->device, opts->srcpath); } else { /* Close stderr so that the qemu-nbd process exits. */ if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { @@ -590,6 +590,7 @@ int main(int argc, char **argv) .fork_process =3D false, .verbose =3D false, .device =3D NULL, + .srcpath =3D NULL, }; #ifdef CONFIG_POSIX @@ -1059,19 +1060,19 @@ int main(int argc, char **argv) bdrv_init(); atexit(qemu_nbd_shutdown); - srcpath =3D argv[optind]; + opts.srcpath =3D argv[optind]; if (imageOpts) { - QemuOpts *opts; + QemuOpts *o; if (fmt) { error_report("--image-opts and -f are mutually exclusive"); exit(EXIT_FAILURE); } - opts =3D qemu_opts_parse_noisily(&file_opts, srcpath, true); - if (!opts) { + o =3D qemu_opts_parse_noisily(&file_opts, opts.srcpath, true); + if (!o) { qemu_opts_reset(&file_opts); exit(EXIT_FAILURE); } - options =3D qemu_opts_to_qdict(opts, NULL); + options =3D qemu_opts_to_qdict(o, NULL); qemu_opts_reset(&file_opts); blk =3D blk_new_open(NULL, NULL, options, flags, &local_err); } else { @@ -1079,7 +1080,7 @@ int main(int argc, char **argv) options =3D qdict_new(); qdict_put_str(options, "driver", fmt); } - blk =3D blk_new_open(srcpath, NULL, options, flags, &local_err); + blk =3D blk_new_open(opts.srcpath, NULL, options, flags, &local_er= r); } if (!blk) { --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137110; cv=none; d=zohomail.com; s=zohoarc; b=NptfFwwLLLGSYzcd4EF1S+GLX2S6nSrjlz8rVTyMmVbMx0KmCul4jpcNFQ/d0is9tZX3AVnMVsJHVLWZoxxy/wyY4fWKz+qcLMwA7tjttHwAvEkgjP5oDjCgF+FBO8+2+c1FsUOTop9JGJN/W9yBOYRJNRyIHJ/EJV+HlkYoTvw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137110; h=Content-Type: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; bh=4lPMbSASnD44GbgamL1dxZUWAxhOG0A6Kn43vHsAFa4=; b=UYTxOJQhGh8SF6UosaXcigVzcW2lJh0oWvZwj3XeOChNDWRK6sTFptPNIDUYRmWGk2IBWKnw3FbwGzQGLMhwJ1+6l8ydd3E90/FhzO0Uoh9sbKa4bM4tSkwkzZ5tTUl+HMDUkEoAwIxSImzn700tC9S6W6y4Ix5DSb68q6vCR7A= 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 1694137110510626.8651917557112; Thu, 7 Sep 2023 18:38:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ6-0008Un-D6; Thu, 07 Sep 2023 21:36:26 -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 1qeQQ5-0008U4-Jj for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQQ0-0007u5-RU for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:25 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-237-zwUxaUcyMiC5VpXQ4F4ZkQ-1; Thu, 07 Sep 2023 21:36:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 061771C07834; Fri, 8 Sep 2023 01:36:18 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96FE840C2070; Fri, 8 Sep 2023 01:36:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136980; 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: in-reply-to:in-reply-to:references:references; bh=4lPMbSASnD44GbgamL1dxZUWAxhOG0A6Kn43vHsAFa4=; b=UvvSWRk8H56YGK+R37uTwUovFwq1asIA0GuVodRYgkVtWZjQjLbZNk7Z+OM41tJzagGIsf jaELhupptcX6hbMr/jAEe9dwSKmy7uk+nGAU/2ceZN8j4B1yWuX54TJp3OdMKYII9IOYsf gO1Kkpaw0ZVxbFR0Oydc9/c1gS3S088= X-MC-Unique: zwUxaUcyMiC5VpXQ4F4ZkQ-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 10/13] qemu-nbd: put saddr into into struct NbdClientOpts Date: Thu, 7 Sep 2023 20:35:46 -0500 Message-ID: <20230908013535.990731-25-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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: 1694137111515100005 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" We pass other parameters into nbd_client_thread() in this way. This patch makes the code more consistent. Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906093210.339585-5-den@openvz.org> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- qemu-nbd.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 16c59424f13..86bb2f04e24 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -73,7 +73,6 @@ #define MBR_SIZE 512 -static SocketAddress *saddr; static int persistent =3D 0; static enum { RUNNING, TERMINATE, TERMINATED } state; static int shared =3D 1; @@ -255,6 +254,7 @@ static int qemu_nbd_client_list(SocketAddress *saddr, Q= CryptoTLSCreds *tls, struct NbdClientOpts { char *device; char *srcpath; + SocketAddress *saddr; bool fork_process; bool verbose; }; @@ -289,7 +289,7 @@ static void *nbd_client_thread(void *arg) sioc =3D qio_channel_socket_new(); if (qio_channel_socket_connect_sync(sioc, - saddr, + opts->saddr, &local_error) < 0) { error_report_err(local_error); goto out; @@ -591,6 +591,7 @@ int main(int argc, char **argv) .verbose =3D false, .device =3D NULL, .srcpath =3D NULL, + .saddr =3D NULL, }; #ifdef CONFIG_POSIX @@ -892,8 +893,8 @@ int main(int argc, char **argv) } if (list) { - saddr =3D nbd_build_socket_address(sockpath, bindto, port); - return qemu_nbd_client_list(saddr, tlscreds, + opts.saddr =3D nbd_build_socket_address(sockpath, bindto, port); + return qemu_nbd_client_list(opts.saddr, tlscreds, tlshostname ? tlshostname : bindto); } @@ -1024,8 +1025,8 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } #endif - saddr =3D nbd_build_socket_address(sockpath, bindto, port); - if (qio_net_listener_open_sync(server, saddr, backlog, + opts.saddr =3D nbd_build_socket_address(sockpath, bindto, port); + if (qio_net_listener_open_sync(server, opts.saddr, backlog, &local_err) < 0) { object_unref(OBJECT(server)); error_report_err(local_err); --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137039; cv=none; d=zohomail.com; s=zohoarc; b=Islb7I/vOvf0rVCrIWsL7sV9Ba0GTmnbiABnwVU/AlbErqynPL2wZvVLlMgIbuqUs9Rgh3KBBuLZ1Pajixh+n4N2jCUfJH+FxIYA7JF2ykRdfhXCyq9vuyrmRizg0NZh9Gi5qCEjevU2hdRUC5ABHFor8K3By2zvRZBgOonkujM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137039; h=Content-Type: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; bh=f5jd/6kc4vjjX7uDpoVyEKlPLRMa8RsVseLch70y3qo=; b=cbeBT4NIF45VyLjYJhLZB9Tj2tx26Pwz8ya/g5SVq5QYip4Y0yX2xj6q6KOmqxi3e/XHCSjug3JVgyTNf0CPlfMRu6EAk9Y1EtiLOJrOIQWINVmf0sL4yA33e1mPKdnHa6d6QIadiQ+YgdrwCBWAwMjmNmPRcHEsRRfeIwxag2c= 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 1694137039011888.4176430149345; Thu, 7 Sep 2023 18:37:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQ9-00006L-3p; Thu, 07 Sep 2023 21:36:29 -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 1qeQQ7-0008Vx-GO for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:27 -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 1qeQQ2-0007uv-In for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:27 -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-408-SFcbv7h9MTaOInXUmbq41A-1; Thu, 07 Sep 2023 21:36:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 93C708007CE; Fri, 8 Sep 2023 01:36:18 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FC2740C2070; Fri, 8 Sep 2023 01:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136982; 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: in-reply-to:in-reply-to:references:references; bh=f5jd/6kc4vjjX7uDpoVyEKlPLRMa8RsVseLch70y3qo=; b=WmH6IFcCzOPDAkAGHoH7aVMyqXcA3ZiK/hAIA0iAJ2w6yZPI0ij3DQg7QgIi2X7QDvLq18 15vgKdT42FzlkV/7IyGxtt1X1gY8B/8wFsHiXtpCPsl4a0XH7vosbNqp7Q9IPhPF5D1jnM qXr3I9mMkZyE7FGEy7yU6R4044g3UYU= X-MC-Unique: SFcbv7h9MTaOInXUmbq41A-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 11/13] qemu-nbd: invent nbd_client_release_pipe() helper Date: Thu, 7 Sep 2023 20:35:47 -0500 Message-ID: <20230908013535.990731-26-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1694137040981100009 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Move the code from main() and nbd_client_thread() into the specific helper. This code is going to be grown. Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906093210.339585-6-den@openvz.org> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- qemu-nbd.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 86bb2f04e24..7c4e22def17 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -259,6 +259,16 @@ struct NbdClientOpts { bool verbose; }; +static void nbd_client_release_pipe(void) +{ + /* Close stderr so that the qemu-nbd process exits. */ + if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { + error_report("Could not release pipe to parent: %s", + strerror(errno)); + exit(EXIT_FAILURE); + } +} + #if HAVE_NBD_DEVICE static void *show_parts(void *arg) { @@ -322,12 +332,7 @@ static void *nbd_client_thread(void *arg) fprintf(stderr, "NBD device %s is now connected to %s\n", opts->device, opts->srcpath); } else { - /* Close stderr so that the qemu-nbd process exits. */ - if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { - error_report("Could not release pipe to parent: %s", - strerror(errno)); - exit(EXIT_FAILURE); - } + nbd_client_release_pipe(); } if (nbd_client(fd) < 0) { @@ -1176,11 +1181,7 @@ int main(int argc, char **argv) } if (opts.fork_process) { - if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { - error_report("Could not release pipe to parent: %s", - strerror(errno)); - exit(EXIT_FAILURE); - } + nbd_client_release_pipe(); } state =3D RUNNING; --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137082; cv=none; d=zohomail.com; s=zohoarc; b=S79kcSMdAMLphqCOEceDKfd7Lf8fh9rqavbl/cYtr1RSF4dZlDI6ZnBq3qoNZ9NTIzingIQBg6Y7cSJYZPo07ws+9k2QMZg6rfhytXnP6p2xXMWnqoZPqyFX3UbnEFZKlB+LkkYa3up51Zi2BDla+3nulnZ6EwNOxgWZhiTp8Xo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137082; h=Content-Type: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; bh=ZJNuuaCbNsUMHmTTdY8oCUznspz2tWW1RL2/pUYQEtM=; b=UQzQCzNuM0zGORcvyIKi4PtDVUgDIsAJwLBAbB3ATyu4zpgpFKdTGU5OTg8G7cqYjo8T7BCBy095FHkadx0fZaJ1A66BLBXXzcgFfd+QbfR23z8e0Z0xIGQ3LeI8DrJNmcZWq4qx6/GrlTtLdKitx2BoIlb+d/IMYjkHHTuygdo= 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 1694137082938858.9344024592622; Thu, 7 Sep 2023 18:38:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQA-000070-M1; Thu, 07 Sep 2023 21:36:30 -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 1qeQQ8-000061-Vo for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:28 -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 1qeQQ5-0007vl-Io for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:28 -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-446-ahgntnL3MPKegEPnF7aQbA-1; Thu, 07 Sep 2023 21:36:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 690EB181792D; Fri, 8 Sep 2023 01:36:19 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id C033B40C2070; Fri, 8 Sep 2023 01:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136985; 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: in-reply-to:in-reply-to:references:references; bh=ZJNuuaCbNsUMHmTTdY8oCUznspz2tWW1RL2/pUYQEtM=; b=huiLsrJp07x+Uqa3JwUcxknv7AG9ZhSYIJuYNi70PUDryulSVQ6otBAB+wJ872jkJ9ia31 cCWvfVy/3GjJ8A5AZXtBv45h/83ylb7OjGb2jzVrq3vq7KoTd/ALNiNdkXujRMSnFHnbU+ fRfHguxARqKqt60dzYDWlX2CN9t+jUY= X-MC-Unique: ahgntnL3MPKegEPnF7aQbA-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Hanna Reitz , Mike Maslenkin , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 12/13] qemu-nbd: Restore "qemu-nbd -v --fork" output Date: Thu, 7 Sep 2023 20:35:48 -0500 Message-ID: <20230908013535.990731-27-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1694137083782100003 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" 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 should preserve original stderr and restore it once the setup stage is done. This commit restores the original behavior with -v option. In this case original output inside the test is kept intact. Reported-by: Kevin Wolf Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy CC: Hanna Reitz CC: Mike Maslenkin Fixes: 5c56dd27a2 ("qemu-nbd: fix regression with qemu-nbd --fork run over = ssh") Message-ID: <20230906093210.339585-7-den@openvz.org> Reviewed-by: Eric Blake Tested-by: Eric Blake Signed-off-by: Eric Blake --- qemu-nbd.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 7c4e22def17..1cdc41ed292 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -255,18 +255,23 @@ struct NbdClientOpts { char *device; char *srcpath; SocketAddress *saddr; + int stderr; bool fork_process; bool verbose; }; -static void nbd_client_release_pipe(void) +static void nbd_client_release_pipe(int old_stderr) { /* Close stderr so that the qemu-nbd process exits. */ - if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { + if (dup2(old_stderr, STDERR_FILENO) < 0) { error_report("Could not release pipe to parent: %s", strerror(errno)); exit(EXIT_FAILURE); } + if (old_stderr !=3D STDOUT_FILENO && close(old_stderr) < 0) { + error_report("Could not release qemu-nbd: %s", strerror(errno)); + exit(EXIT_FAILURE); + } } #if HAVE_NBD_DEVICE @@ -332,7 +337,7 @@ static void *nbd_client_thread(void *arg) fprintf(stderr, "NBD device %s is now connected to %s\n", opts->device, opts->srcpath); } else { - nbd_client_release_pipe(); + nbd_client_release_pipe(opts->stderr); } if (nbd_client(fd) < 0) { @@ -597,6 +602,7 @@ int main(int argc, char **argv) .device =3D NULL, .srcpath =3D NULL, .saddr =3D NULL, + .stderr =3D STDOUT_FILENO, }; #ifdef CONFIG_POSIX @@ -951,6 +957,16 @@ int main(int argc, char **argv) close(stderr_fd[0]); + /* Remember parent's stderr if we will be restoring it. */ + if (opts.verbose /* fork_process is set */) { + opts.stderr =3D dup(STDERR_FILENO); + if (opts.stderr < 0) { + error_report("Could not dup original stderr: %s", + strerror(errno)); + exit(EXIT_FAILURE); + } + } + ret =3D qemu_daemon(1, 0); saved_errno =3D errno; /* dup2 will overwrite error below */ @@ -1181,7 +1197,7 @@ int main(int argc, char **argv) } if (opts.fork_process) { - nbd_client_release_pipe(); + nbd_client_release_pipe(opts.stderr); } state =3D RUNNING; --=20 2.41.0 From nobody Thu Nov 28 07:59:32 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=1694137068; cv=none; d=zohomail.com; s=zohoarc; b=YsRBMvcST7HVxTuA5UYqL4JO+9V+hckffuXE/nHrNz/Je0k8IlDKyE+GFoJVrcN9ZEYd5a9yzwhqDeJTBYJqHecfQc1O4byT5aVufsK9+tLEtrmpNhNKmF+72l/Cz9WUEX2lUmPMmxSFk5e1U7KUYVOv+eFZsb82ZyCWdjsuEcU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137068; h=Content-Type: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; bh=awEkG8sN6HD0PdbvMt4WBDnB9d5YLTzjslaJQCs8hSE=; b=SvJ3+bD4aSF37whTp+qEhCNwEvNil9Ci+sePzw+aPx1kU38/p/eaSlmS96jOkMT+w4DIOtd3Dt4T7tbUWaYRmFF1RxhqKBinG+R+8+7h7r1OB0JRY1ek+N8ZGpRHAIJVTwXSn2YJxL4CnAwRwMgqSNcT7P1P7QoNwq5R2s0okOY= 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 1694137068617451.1182739558301; Thu, 7 Sep 2023 18:37:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQB-00007J-8W; Thu, 07 Sep 2023 21:36:31 -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 1qeQQ8-00005Y-RG for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQQ6-0007w4-8l for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:28 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-315-TdnS9XBaMoGHl3CyUEaMFg-1; Thu, 07 Sep 2023 21:36:20 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 026B93C0EACC; Fri, 8 Sep 2023 01:36:20 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92AF240C2070; Fri, 8 Sep 2023 01:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136985; 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: in-reply-to:in-reply-to:references:references; bh=awEkG8sN6HD0PdbvMt4WBDnB9d5YLTzjslaJQCs8hSE=; b=bdDtgwVf7YyVnjiMsuz3iql64LmfCSdyg6V/vf8+QCNqNP/65OxGxaoiKCUrEnBz9Rgygj DsNXXxvo4nBkPA460Xd8ChJVV3I7Ip3xun4R6SPJuQGG8kyI/OjfVunE3T9HIpYRSY5E1U KG1p89N7stf/Wi74g8lH0jeGBpk/l9o= X-MC-Unique: TdnS9XBaMoGHl3CyUEaMFg-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 13/13] qemu-nbd: document -v behavior in respect to --fork in man Date: Thu, 7 Sep 2023 20:35:49 -0500 Message-ID: <20230908013535.990731-28-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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=unavailable 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: 1694137069099100003 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906093210.339585-8-den@openvz.org> Reviewed-by: Eric Blake [eblake: Wording improvement] Signed-off-by: Eric Blake --- docs/tools/qemu-nbd.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/tools/qemu-nbd.rst b/docs/tools/qemu-nbd.rst index faf6349ea51..329f44d9895 100644 --- a/docs/tools/qemu-nbd.rst +++ b/docs/tools/qemu-nbd.rst @@ -197,7 +197,9 @@ driver options if :option:`--image-opts` is specified. .. option:: -v, --verbose - Display extra debugging information. + Display extra debugging information. This option also keeps the original + *STDERR* stream open if the ``qemu-nbd`` process is daemonized due to + other options like :option:`--fork` or :option:`-c`. .. option:: -h, --help --=20 2.41.0