From nobody Wed May 8 20:53:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569332391; cv=none; d=zoho.com; s=zohoarc; b=FoG95KRlh98+T+EnC9/7TbxS3xJ82sGNr+jpOSX7Dl/uFRg1fW4/tLU9FGEj54Znm9NgctVSDWDvDFm+KzxZwsnfbFgDHNSDvceRSN7KhqkHPvnC+mKYeFgCv0+xWuu4rkQx4xiicscVhmi6d2e5BW1MRqjgW6TX7mfGIOKA8GY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569332391; 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:ARC-Authentication-Results; bh=KIIpiZL3PEr92D1/UdLF/2TCl6gMzBXKFETDqwO9kOQ=; b=Ce98gAAk/RpiOc05mDkp9DxOwxpuVbD5OI1I73vkuOJVWJXNPT0EcPf60lkVTAxKfcbNAiJhpVN4pE1nXum69zZHkXFkgQS21idQtXq3dXdIGreC6pg0PRR8RjPxZpC8Tqotw9zxKYkYWBr8cMYPaCBZq1ZORM/lH386xbLtBnU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569332391071477.5619433827644; Tue, 24 Sep 2019 06:39:51 -0700 (PDT) Received: from localhost ([::1]:45776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCl2i-0000ah-Vi for importer@patchew.org; Tue, 24 Sep 2019 09:39:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51510) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk6X-00065c-DJ for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:39:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk6V-0001vs-Ul for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:39:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42752) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk6T-0001sJ-3I; Tue, 24 Sep 2019 08:39:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DB9F10DCC9F; Tue, 24 Sep 2019 12:39:36 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-249.phx2.redhat.com [10.3.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id D99EF60C5D; Tue, 24 Sep 2019 12:39:35 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 1/4] nbd/client: Add hint when TLS is missing Date: Tue, 24 Sep 2019 07:39:30 -0500 Message-Id: <20190924123933.10607-2-eblake@redhat.com> In-Reply-To: <20190924123933.10607-1-eblake@redhat.com> References: <20190924123933.10607-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 24 Sep 2019 12:39:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Max Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , "open list:Network Block Dev..." , Tingting Mao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" I received an off-list report of failure to connect to an NBD server expecting an x509 certificate, when the client was attempting something similar to this command line: $ ./x86_64-softmmu/qemu-system-x86_64 -name 'blah' -machine q35 -nodefaults= \ -object tls-creds-x509,id=3Dtls0,endpoint=3Dclient,dir=3D$path_to_certs \ -device virtio-scsi-pci,id=3Dvirtio_scsi_pci0,bus=3Dpcie.0,addr=3D0x6 \ -drive id=3Ddrive_image1,if=3Dnone,snapshot=3Doff,aio=3Dthreads,cache=3Dn= one,format=3Draw,file=3Dnbd:localhost:9000,werror=3Dstop,rerror=3Dstop,tls-= creds=3Dtls0 \ -device scsi-hd,id=3Dimage1,drive=3Ddrive_image1,bootindex=3D0 qemu-system-x86_64: -drive id=3Ddrive_image1,if=3Dnone,snapshot=3Doff,aio= =3Dthreads,cache=3Dnone,format=3Draw,file=3Dnbd:localhost:9000,werror=3Dsto= p,rerror=3Dstop,tls-creds=3Dtls0: TLS negotiation required before option 7 = (go) server reported: Option 0x7 not permitted before TLS The problem? As specified, -drive is trying to pass tls-creds to the raw format driver instead of the nbd protocol driver, but before we get to the point where we can detect that raw doesn't know what to do with tls-creds, the nbd driver has already failed because the server complained. The fix to the broken command line? Pass '...,file.tls-creds=3Dtls0' to ensure the tls-creds option is handed to nbd, not raw. But since the error message was rather cryptic, I'm trying to improve the error message. With this patch, the error message adds a line: qemu-system-x86_64: -drive id=3Ddrive_image1,if=3Dnone,snapshot=3Doff,aio= =3Dthreads,cache=3Dnone,format=3Draw,file=3Dnbd:localhost:9000,werror=3Dsto= p,rerror=3Dstop,tls-creds=3Dtls0: TLS negotiation required before option 7 = (go) Did you forget a valid tls-creds? server reported: Option 0x7 not permitted before TLS And with luck, someone grepping for that error message will find this commit message and figure out their command line mistake. Sadly, the only mention of file.tls-creds in our docs relates to an --image-opts use of PSK encryption with qemu-img as the client, rather than x509 certificate encryption with qemu-kvm as the client. CC: Tingting Mao CC: Daniel P. Berrang=C3=A9 Signed-off-by: Eric Blake Message-Id: <20190907172055.26870-1-eblake@redhat.com> [eblake: squash in iotest 233 fix] Reviewed-by: Daniel P. Berrang=C3=A9 --- nbd/client.c | 1 + tests/qemu-iotests/233.out | 2 ++ 2 files changed, 3 insertions(+) diff --git a/nbd/client.c b/nbd/client.c index b9dc829175f9..f6733962b49b 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -204,6 +204,7 @@ static int nbd_handle_reply_err(QIOChannel *ioc, NBDOpt= ionReply *reply, case NBD_REP_ERR_TLS_REQD: error_setg(errp, "TLS negotiation required before option %" PRIu32 " (%s)", reply->option, nbd_opt_lookup(reply->option)); + error_append_hint(errp, "Did you forget a valid tls-creds?\n"); break; case NBD_REP_ERR_UNKNOWN: diff --git a/tests/qemu-iotests/233.out b/tests/qemu-iotests/233.out index 24321efa113b..c3c344811b2b 100644 --- a/tests/qemu-iotests/233.out +++ b/tests/qemu-iotests/233.out @@ -21,8 +21,10 @@ server reported: TLS not configured =3D=3D check plain client to TLS server fails =3D=3D qemu-img: Could not open 'nbd://localhost:PORT': TLS negotiation required = before option 7 (go) +Did you forget a valid tls-creds? server reported: Option 0x7 not permitted before TLS qemu-nbd: TLS negotiation required before option 3 (list) +Did you forget a valid tls-creds? server reported: Option 0x3 not permitted before TLS =3D=3D check TLS works =3D=3D --=20 2.21.0 From nobody Wed May 8 20:53:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330809; cv=none; d=zoho.com; s=zohoarc; b=UOS7jNYGB/YR2Bmy0eoJXhcE+a3k9//3ysb/Qa5b1GyJm+xC9CRa75C6H/jKlM5KRQZizmyURsIxvFnS2Ko7qYcBbp0DFQk2voZpZHVriTDK4PGoc005a0z6vL9yfAxuVmXVnISMIk7zsERc/QLz5fDkanrcoNAOV4POA/1Oq5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330809; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=GnkZVcIodJ+7WdChzzv0oy2gg2YsWCHqVzxqUD5SQS4=; b=as3rgs0hSHnUjfAx2rxiXKJdG57QQzpJ63iEcSrX/Gt17Wm7qC+zGzdA6zOO6YhTBs7191vEYgwFImyq1HFHoEhMvrO15Q3rk5S037yFrYzSt4qw44uxr6ynfE9iT9OlTJaQ8m3Zqoy//RYR6JFo7BGOl1cS2xTvA0ZfNB8CJKU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330809340270.4369507163733; Tue, 24 Sep 2019 06:13:29 -0700 (PDT) Received: from localhost ([::1]:45498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkd8-0000ln-0W for importer@patchew.org; Tue, 24 Sep 2019 09:13:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51552) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk6a-00068o-3O for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:39:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk6Y-0001zY-OQ for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:39:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58918) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk6W-0001vh-3U; Tue, 24 Sep 2019 08:39:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6274930B2502; Tue, 24 Sep 2019 12:39:39 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-249.phx2.redhat.com [10.3.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 979BD60BFB; Tue, 24 Sep 2019 12:39:36 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 2/4] nbd/server: attach client channel to the export's AioContext Date: Tue, 24 Sep 2019 07:39:31 -0500 Message-Id: <20190924123933.10607-3-eblake@redhat.com> In-Reply-To: <20190924123933.10607-1-eblake@redhat.com> References: <20190924123933.10607-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 24 Sep 2019 12:39:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:Network Block Dev..." , Sergio Lopez Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Sergio Lopez On creation, the export's AioContext is set to the same one as the BlockBackend, while the AioContext in the client QIOChannel is left untouched. As a result, when using data-plane, nbd_client_receive_next_request() schedules coroutines in the IOThread AioContext, while the client's QIOChannel is serviced from the main_loop, potentially triggering the assertion at qio_channel_restart_[read|write]. To fix this, as soon we have the export corresponding to the client, we call qio_channel_attach_aio_context() to attach the QIOChannel context to the export's AioContext. This matches with the logic at blk_aio_attached(). RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=3D1748253 Signed-off-by: Sergio Lopez Message-Id: <20190912110032.26395-1-slp@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- nbd/server.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nbd/server.c b/nbd/server.c index 28c3c8be854c..31d624e146cb 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1297,6 +1297,11 @@ 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->ctx) { + qio_channel_attach_aio_context(client->ioc, client->exp->ctx); + } + assert(!client->optlen); trace_nbd_negotiate_success(); --=20 2.21.0 From nobody Wed May 8 20:53:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331340; cv=none; d=zoho.com; s=zohoarc; b=bq+q2kqSbhZrKBzaiNebUwKHleuhA8LO0AgYvKwPO90fnl3Qm6+VUuXxBqZ1/cH8itX40LSQwckyLviS8fvrS77pf61nMieYNx82p1cbzEnvysZK9CZM8MqS6TWCRy5nLwyu82Y3jZ/JnDokmwH8lUbMmSIUJZVP7JfJfr0Grng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331340; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=bWw+s/VPSieBrLeWmHgQa4wxw55vbV5eYtTHsUSgRlQ=; b=cIfGOOTAB8Rwv0y28FeU4l6lOPWxMYKoR0YeFXaIgeLv8P3Nz51Wu0ui6l+2m9S8i/+3pyvNleJx76NSvdVhIxPF5ZqP7WfRTS1PApH5J8ImantF0LyznRzH5TwNuUnjTyXe47BVtxQPceTY9Q0vF+i6jyacvdbnKcMYsyVIdEU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569331340719419.79375440278636; Tue, 24 Sep 2019 06:22:20 -0700 (PDT) Received: from localhost ([::1]:45574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCklm-00083R-Ss for importer@patchew.org; Tue, 24 Sep 2019 09:22:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51574) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk6b-0006Al-Sx for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:39:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk6a-00020H-2N for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:39:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58176) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk6W-0001w2-O7; Tue, 24 Sep 2019 08:39:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13687756; Tue, 24 Sep 2019 12:39:40 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-249.phx2.redhat.com [10.3.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91B3460BFB; Tue, 24 Sep 2019 12:39:39 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 3/4] nbd: Grab aio context lock in more places Date: Tue, 24 Sep 2019 07:39:32 -0500 Message-Id: <20190924123933.10607-4-eblake@redhat.com> In-Reply-To: <20190924123933.10607-1-eblake@redhat.com> References: <20190924123933.10607-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 24 Sep 2019 12:39:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "open list:Network Block Dev..." , Sergio Lopez , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When iothreads are in use, the failure to grab the aio context results in an assertion failure when trying to unlock things during blk_unref, when trying to unlock a mutex that was not locked. In short, all calls to nbd_export_put need to done while within the correct aio context. But since nbd_export_put can recursively reach itself via nbd_export_close, and recursively grabbing the context would deadlock, we can't do the context grab directly in those functions, but must do so in their callers. Hoist the use of the correct aio_context from nbd_export_new() to its caller qmp_nbd_server_add(). Then tweak qmp_nbd_server_remove(), nbd_eject_notifier(), and nbd_esport_close_all() to grab the right context, so that all callers during qemu now own the context before nbd_export_put() can call blk_unref(). Remaining uses in qemu-nbd don't matter (since that use case does not support iothreads). Suggested-by: Kevin Wolf Signed-off-by: Eric Blake Message-Id: <20190917023917.32226-1-eblake@redhat.com> Reviewed-by: Sergio Lopez --- include/block/nbd.h | 1 + blockdev-nbd.c | 14 ++++++++++++-- nbd/server.c | 22 ++++++++++++++++++---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 21550747cf35..316fd705a9e4 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -340,6 +340,7 @@ void nbd_export_put(NBDExport *exp); BlockBackend *nbd_export_get_blockdev(NBDExport *exp); +AioContext *nbd_export_aio_context(NBDExport *exp); NBDExport *nbd_export_find(const char *name); void nbd_export_close_all(void); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 213f226ac1c4..6a8b206e1d74 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -151,6 +151,7 @@ void qmp_nbd_server_add(const char *device, bool has_na= me, const char *name, BlockBackend *on_eject_blk; NBDExport *exp; int64_t len; + AioContext *aio_context; if (!nbd_server) { error_setg(errp, "NBD server not running"); @@ -173,11 +174,13 @@ void qmp_nbd_server_add(const char *device, bool has_= name, const char *name, return; } + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); len =3D bdrv_getlength(bs); if (len < 0) { error_setg_errno(errp, -len, "Failed to determine the NBD export's length"); - return; + goto out; } if (!has_writable) { @@ -190,13 +193,16 @@ void qmp_nbd_server_add(const char *device, bool has_= name, const char *name, exp =3D nbd_export_new(bs, 0, len, name, NULL, bitmap, !writable, !wri= table, NULL, false, on_eject_blk, errp); if (!exp) { - return; + goto out; } /* The list of named exports has a strong reference to this export now= and * our only way of accessing it is through nbd_export_find(), so we ca= n drop * the strong reference that is @exp. */ nbd_export_put(exp); + + out: + aio_context_release(aio_context); } void qmp_nbd_server_remove(const char *name, @@ -204,6 +210,7 @@ void qmp_nbd_server_remove(const char *name, Error **errp) { NBDExport *exp; + AioContext *aio_context; if (!nbd_server) { error_setg(errp, "NBD server not running"); @@ -220,7 +227,10 @@ void qmp_nbd_server_remove(const char *name, mode =3D NBD_SERVER_REMOVE_MODE_SAFE; } + aio_context =3D nbd_export_aio_context(exp); + aio_context_acquire(aio_context); nbd_export_remove(exp, mode, errp); + aio_context_release(aio_context); } void qmp_nbd_server_stop(Error **errp) diff --git a/nbd/server.c b/nbd/server.c index 31d624e146cb..d8d1e6245532 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1461,7 +1461,12 @@ static void blk_aio_detach(void *opaque) static void nbd_eject_notifier(Notifier *n, void *data) { NBDExport *exp =3D container_of(n, NBDExport, eject_notifier); + AioContext *aio_context; + + aio_context =3D exp->ctx; + aio_context_acquire(aio_context); nbd_export_close(exp); + aio_context_release(aio_context); } NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, @@ -1480,12 +1485,11 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uin= t64_t dev_offset, * NBD exports are used for non-shared storage migration. Make sure * that BDRV_O_INACTIVE is cleared and the image is ready for write * access since the export could be available before migration handove= r. + * ctx was acquired in the caller. */ assert(name); ctx =3D bdrv_get_aio_context(bs); - aio_context_acquire(ctx); bdrv_invalidate_cache(bs, NULL); - aio_context_release(ctx); /* Don't allow resize while the NBD server is running, otherwise we do= n't * care what happens with the node. */ @@ -1493,7 +1497,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint6= 4_t dev_offset, if (!readonly) { perm |=3D BLK_PERM_WRITE; } - blk =3D blk_new(bdrv_get_aio_context(bs), perm, + blk =3D blk_new(ctx, perm, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD); ret =3D blk_insert_bs(blk, bs, errp); @@ -1560,7 +1564,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint6= 4_t dev_offset, } exp->close =3D close; - exp->ctx =3D blk_get_aio_context(blk); + exp->ctx =3D ctx; blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, ex= p); if (on_eject_blk) { @@ -1593,6 +1597,12 @@ NBDExport *nbd_export_find(const char *name) return NULL; } +AioContext * +nbd_export_aio_context(NBDExport *exp) +{ + return exp->ctx; +} + void nbd_export_close(NBDExport *exp) { NBDClient *client, *next; @@ -1687,9 +1697,13 @@ BlockBackend *nbd_export_get_blockdev(NBDExport *exp) void nbd_export_close_all(void) { NBDExport *exp, *next; + AioContext *aio_context; QTAILQ_FOREACH_SAFE(exp, &exports, next, next) { + aio_context =3D exp->ctx; + aio_context_acquire(aio_context); nbd_export_close(exp); + aio_context_release(aio_context); } } --=20 2.21.0 From nobody Wed May 8 20:53:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331076; cv=none; d=zoho.com; s=zohoarc; b=dbzSY6aH0Wl+Wl6sa3F2a+uctdYjQfGr6KO/7l62yPh+j9/wQzrsAKbqL5K0FyqhMoHjaOoQNh5ABszsxI19sLVi47N+BCs/0tjN5hRBELUL5bzUDgMwc3zdPpu4z6qXbba64v0nU0pFt3rGJMMB636u/1K8UBYb9U84v3lg/uQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331076; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7qwg9ehAj9BVKRSSC9IKXAPPuDVmKsNVZCiKhTy8o48=; b=Ua8TRAgIU3ZQUQN27TlNfEu3vf2HwvCAmnPSMEwNeTH4IOiPS7qMkJ//jHgjecHY0P4EHcCCQ91BNZ3fmnJE1eJWecIAqLArtbSM7wotihrZUJrf5KVdQQ6E/+qPQRXo5xqiT3l+x+XpO4B0Wb60OmLdaEGOKDNwXNNpqC6I8iw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156933107631857.07748971702915; Tue, 24 Sep 2019 06:17:56 -0700 (PDT) Received: from localhost ([::1]:45544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkhW-0004Sh-8L for importer@patchew.org; Tue, 24 Sep 2019 09:17:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51566) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk6b-0006AF-4B for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:39:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk6Z-000207-VW for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:39:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42256) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk6X-0001ww-Ar; Tue, 24 Sep 2019 08:39:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A06913A17F; Tue, 24 Sep 2019 12:39:40 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-249.phx2.redhat.com [10.3.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FB9F60C63; Tue, 24 Sep 2019 12:39:40 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 4/4] tests: Use iothreads during iotest 223 Date: Tue, 24 Sep 2019 07:39:33 -0500 Message-Id: <20190924123933.10607-5-eblake@redhat.com> In-Reply-To: <20190924123933.10607-1-eblake@redhat.com> References: <20190924123933.10607-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 24 Sep 2019 12:39:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Doing so catches the bugs we just fixed with NBD not properly using correct contexts. Signed-off-by: Eric Blake Message-Id: <20190920220729.31801-1-eblake@redhat.com> --- tests/qemu-iotests/223 | 6 ++++-- tests/qemu-iotests/223.out | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/223 b/tests/qemu-iotests/223 index cc48e78ea7dc..2ba3d8124b4f 100755 --- a/tests/qemu-iotests/223 +++ b/tests/qemu-iotests/223 @@ -2,7 +2,7 @@ # # Test reading dirty bitmap over NBD # -# Copyright (C) 2018 Red Hat, Inc. +# Copyright (C) 2018-2019 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -109,7 +109,7 @@ echo echo "=3D=3D=3D End dirty bitmaps, and start serving image over NBD =3D=3D= =3D" echo -_launch_qemu 2> >(_filter_nbd) +_launch_qemu -object iothread,id=3Dio0 2> >(_filter_nbd) # Intentionally provoke some errors as well, to check error handling silent=3D @@ -117,6 +117,8 @@ _send_qemu_cmd $QEMU_HANDLE '{"execute":"qmp_capabiliti= es"}' "return" _send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add", "arguments":{"driver":"qcow2", "node-name":"n", "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return" +_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-blockdev-set-iothread", + "arguments":{"node-name":"n", "iothread":"io0"}}' "return" _send_qemu_cmd $QEMU_HANDLE '{"execute":"block-dirty-bitmap-disable", "arguments":{"node":"n", "name":"b"}}' "return" _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out index 5d00398c11cb..23b34fcd202e 100644 --- a/tests/qemu-iotests/223.out +++ b/tests/qemu-iotests/223.out @@ -27,6 +27,7 @@ wrote 2097152/2097152 bytes at offset 2097152 {"return": {}} {"return": {}} {"return": {}} +{"return": {}} {"error": {"class": "GenericError", "desc": "NBD server not running"}} {"return": {}} {"error": {"class": "GenericError", "desc": "NBD server already running"}} --=20 2.21.0