From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155068560726199.38010987637813; Wed, 20 Feb 2019 10:00:07 -0800 (PST) Received: from localhost ([127.0.0.1]:44861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW9z-000692-22 for importer@patchew.org; Wed, 20 Feb 2019 12:59:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwVzW-0005AT-VT for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwVzV-000528-Rn for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49184) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwVzS-0004vT-At; Wed, 20 Feb 2019 12:49:02 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5904EF6870; Wed, 20 Feb 2019 17:49:01 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF42661B89; Wed, 20 Feb 2019 17:48:54 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:31 +0100 Message-Id: <20190220174843.8847-2-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Feb 2019 17:49:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 01/13] block-backend: Make blk_inc/dec_in_flight public X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" For some users of BlockBackends, just increasing the in_flight counter is easier than implementing separate handlers in BlockDevOps. Make the helper functions for this public. Signed-off-by: Kevin Wolf --- include/sysemu/block-backend.h | 2 ++ block/block-backend.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 832a4bf168..e2066eb06b 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -156,6 +156,8 @@ int blk_co_pdiscard(BlockBackend *blk, int64_t offset, = int bytes); int blk_co_flush(BlockBackend *blk); int blk_flush(BlockBackend *blk); int blk_commit_all(void); +void blk_inc_in_flight(BlockBackend *blk); +void blk_dec_in_flight(BlockBackend *blk); void blk_drain(BlockBackend *blk); void blk_drain_all(void); void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, diff --git a/block/block-backend.c b/block/block-backend.c index f6ea824308..0219555f89 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1262,12 +1262,12 @@ int blk_make_zero(BlockBackend *blk, BdrvRequestFla= gs flags) return bdrv_make_zero(blk->root, flags); } =20 -static void blk_inc_in_flight(BlockBackend *blk) +void blk_inc_in_flight(BlockBackend *blk) { atomic_inc(&blk->in_flight); } =20 -static void blk_dec_in_flight(BlockBackend *blk) +void blk_dec_in_flight(BlockBackend *blk) { atomic_dec(&blk->in_flight); aio_wait_kick(); --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550686300192388.9776684724584; Wed, 20 Feb 2019 10:11:40 -0800 (PST) Received: from localhost ([127.0.0.1]:45101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwWLH-00078n-58 for importer@patchew.org; Wed, 20 Feb 2019 13:11:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwVzY-0005Dc-Hq for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwVzX-00053g-6k for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwVzU-0004yg-27; Wed, 20 Feb 2019 12:49:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F1A31CFF58; Wed, 20 Feb 2019 17:49:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD4413792; Wed, 20 Feb 2019 17:49:01 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:32 +0100 Message-Id: <20190220174843.8847-3-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 20 Feb 2019 17:49:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 02/13] virtio-blk: Increase in_flight for request restart BH X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" virtio_blk_dma_restart_bh() submits new requests, so in order to make sure that these requests are not started inside a drained section of the attached BlockBackend, we need to make sure that draining the BlockBackend waits for the BH to be executed. This BH is still questionable because its scheduled in the main thread instead of the configured iothread. Leave a FIXME comment for this. But with this fix, enabling the data plane at least waits for these requests (in bdrv_set_aio_context()) instead of changing the AioContext under their feet and making them run in the wrong thread, causing crashes and failures (e.g. due to missing locking). Signed-off-by: Kevin Wolf --- hw/block/virtio-blk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index cf7f47eaba..e11e6e45d0 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -675,6 +675,7 @@ static void virtio_blk_dma_restart_bh(void *opaque) if (mrb.num_reqs) { virtio_blk_submit_multireq(s->blk, &mrb); } + blk_dec_in_flight(s->conf.conf.blk); aio_context_release(blk_get_aio_context(s->conf.conf.blk)); } =20 @@ -688,8 +689,11 @@ static void virtio_blk_dma_restart_cb(void *opaque, in= t running, } =20 if (!s->bh) { + /* FIXME The data plane is not started yet, so these requests are + * processed in the main thread. */ s->bh =3D aio_bh_new(blk_get_aio_context(s->conf.conf.blk), virtio_blk_dma_restart_bh, s); + blk_inc_in_flight(s->conf.conf.blk); qemu_bh_schedule(s->bh); } } --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550685127972674.5765412898933; Wed, 20 Feb 2019 09:52:07 -0800 (PST) Received: from localhost ([127.0.0.1]:44723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW2O-0007GP-Qm for importer@patchew.org; Wed, 20 Feb 2019 12:52:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwVzf-0005J9-6r for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwVzd-00059I-6Y for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45866) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwVzX-000532-Gr; Wed, 20 Feb 2019 12:49:07 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 829A8359968; Wed, 20 Feb 2019 17:49:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BE2261B89; Wed, 20 Feb 2019 17:49:03 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:33 +0100 Message-Id: <20190220174843.8847-4-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 20 Feb 2019 17:49:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 03/13] nbd: Restrict connection_co reentrance X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" nbd_client_attach_aio_context() schedules connection_co in the new AioContext and this way reenters it in any arbitrary place that has yielded. We can restrict this a bit to the function call where the coroutine actually sits waiting when it's idle. This doesn't solve any bug yet, but it shows where in the code we need to support this random reentrance and where we don't have to care. Add FIXME comments for the existing bugs that the rest of this series will fix. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/nbd-client.h | 1 + block/nbd-client.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/block/nbd-client.h b/block/nbd-client.h index d990207a5c..09e03013d2 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -35,6 +35,7 @@ typedef struct NBDClientSession { =20 NBDClientRequest requests[MAX_NBD_REQUESTS]; NBDReply reply; + BlockDriverState *bs; bool quit; } NBDClientSession; =20 diff --git a/block/nbd-client.c b/block/nbd-client.c index f0ad54ce21..5ce4aa9520 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -76,8 +76,24 @@ static coroutine_fn void nbd_connection_entry(void *opaq= ue) Error *local_err =3D NULL; =20 while (!s->quit) { + /* + * The NBD client can only really be considered idle when it has + * yielded from qio_channel_readv_all_eof(), waiting for data. Thi= s is + * the point where the additional scheduled coroutine entry happens + * after nbd_client_attach_aio_context(). + * + * Therefore we keep an additional in_flight reference all the tim= e and + * only drop it temporarily here. + * + * FIXME This is not safe because the QIOChannel could wake up the + * coroutine for a second time; it is not prepared for coroutine + * resumption from external code. + */ + bdrv_dec_in_flight(s->bs); assert(s->reply.handle =3D=3D 0); ret =3D nbd_receive_reply(s->ioc, &s->reply, &local_err); + bdrv_inc_in_flight(s->bs); + if (local_err) { trace_nbd_read_reply_entry_fail(ret, error_get_pretty(local_er= r)); error_free(local_err); @@ -116,6 +132,8 @@ static coroutine_fn void nbd_connection_entry(void *opa= que) =20 s->quit =3D true; nbd_recv_coroutines_wake_all(s); + bdrv_dec_in_flight(s->bs); + s->connection_co =3D NULL; aio_wait_kick(); } @@ -970,6 +988,8 @@ void nbd_client_attach_aio_context(BlockDriverState *bs, { NBDClientSession *client =3D nbd_get_client_session(bs); qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), new_context); + + /* FIXME Really need a bdrv_inc_in_flight() here */ aio_co_schedule(new_context, client->connection_co); } =20 @@ -1076,6 +1096,7 @@ static int nbd_client_connect(BlockDriverState *bs, * kick the reply mechanism. */ qio_channel_set_blocking(QIO_CHANNEL(sioc), false, NULL); client->connection_co =3D qemu_coroutine_create(nbd_connection_entry, = client); + bdrv_inc_in_flight(bs); nbd_client_attach_aio_context(bs, bdrv_get_aio_context(bs)); =20 logout("Established connection with NBD server\n"); @@ -1108,6 +1129,7 @@ int nbd_client_init(BlockDriverState *bs, { NBDClientSession *client =3D nbd_get_client_session(bs); =20 + client->bs =3D bs; qemu_co_mutex_init(&client->send_mutex); qemu_co_queue_init(&client->free_sema); =20 --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550685782970959.7847813652545; Wed, 20 Feb 2019 10:03:02 -0800 (PST) Received: from localhost ([127.0.0.1]:44922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwWCt-0000Ee-Pz for importer@patchew.org; Wed, 20 Feb 2019 13:02:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwVzh-0005LD-4u for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwVzf-0005BR-5e for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45972) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwVzZ-00054y-7G; Wed, 20 Feb 2019 12:49:10 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 504BF31F3FC; Wed, 20 Feb 2019 17:49:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id D131261B89; Wed, 20 Feb 2019 17:49:06 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:34 +0100 Message-Id: <20190220174843.8847-5-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 20 Feb 2019 17:49:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 04/13] io: Make qio_channel_yield() interruptible X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Similar to how qemu_co_sleep_ns() allows preemption from an external coroutine entry, allow reentering qio_channel_yield() early. Signed-off-by: Kevin Wolf --- include/io/channel.h | 9 ++++++--- io/channel.c | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index da2f138200..59460cb1ec 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -739,10 +739,13 @@ void qio_channel_detach_aio_context(QIOChannel *ioc); * addition, no two coroutine can be waiting on the same condition * and channel at the same time. * - * This must only be called from coroutine context + * This must only be called from coroutine context. It is safe to + * reenter the coroutine externally while it is waiting; in this + * case the function will return even if @condition is not yet + * available. */ -void qio_channel_yield(QIOChannel *ioc, - GIOCondition condition); +void coroutine_fn qio_channel_yield(QIOChannel *ioc, + GIOCondition condition); =20 /** * qio_channel_wait: diff --git a/io/channel.c b/io/channel.c index 8dd0684f5d..303376e08d 100644 --- a/io/channel.c +++ b/io/channel.c @@ -469,6 +469,16 @@ void coroutine_fn qio_channel_yield(QIOChannel *ioc, } qio_channel_set_aio_fd_handlers(ioc); qemu_coroutine_yield(); + + /* Allow interrupting the operation by reentering the coroutine other = than + * through the aio_fd_handlers. */ + if (condition =3D=3D G_IO_IN && ioc->read_coroutine) { + ioc->read_coroutine =3D NULL; + qio_channel_set_aio_fd_handlers(ioc); + } else if (condition =3D=3D G_IO_OUT && ioc->write_coroutine) { + ioc->write_coroutine =3D NULL; + qio_channel_set_aio_fd_handlers(ioc); + } } =20 =20 --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15506853065051011.2970272816409; Wed, 20 Feb 2019 09:55:06 -0800 (PST) Received: from localhost ([127.0.0.1]:44752 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW5G-0001yI-Tq for importer@patchew.org; Wed, 20 Feb 2019 12:55:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwVzk-0005Md-5D for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwVzj-0005EK-8s for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43346) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwVzd-00056H-5o; Wed, 20 Feb 2019 12:49:15 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AD70C0F1D0C; Wed, 20 Feb 2019 17:49:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E7013792; Wed, 20 Feb 2019 17:49:08 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:35 +0100 Message-Id: <20190220174843.8847-6-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 20 Feb 2019 17:49:10 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 05/13] io: Remove redundant read/write_coroutine assignments X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" qio_channel_yield() now updates ioc->read_write/coroutine and calls qio_channel_set_aio_fd_handlers(), so the code in the handlers has become redundant and can be removed. This does not make a difference in intermediate states because aio_co_wake() really enters the coroutine immediately here: These handlers are never run in coroutine context, and we're in the right AioContext because qio_channel_attach_aio_context() asserts that the handlers are inactive. To make these conditions more obvious, replace the aio_co_wake() with a direct qemu_coroutine_enter() and assert the right AioContext. Suggested-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- io/channel.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/io/channel.c b/io/channel.c index 303376e08d..aa3edf6019 100644 --- a/io/channel.c +++ b/io/channel.c @@ -400,16 +400,14 @@ off_t qio_channel_io_seek(QIOChannel *ioc, } =20 =20 -static void qio_channel_set_aio_fd_handlers(QIOChannel *ioc); - static void qio_channel_restart_read(void *opaque) { QIOChannel *ioc =3D opaque; Coroutine *co =3D ioc->read_coroutine; =20 - ioc->read_coroutine =3D NULL; - qio_channel_set_aio_fd_handlers(ioc); - aio_co_wake(co); + assert(qemu_get_current_aio_context() =3D=3D + qemu_coroutine_get_aio_context(co)); + qemu_coroutine_enter(co); } =20 static void qio_channel_restart_write(void *opaque) @@ -417,9 +415,9 @@ static void qio_channel_restart_write(void *opaque) QIOChannel *ioc =3D opaque; Coroutine *co =3D ioc->write_coroutine; =20 - ioc->write_coroutine =3D NULL; - qio_channel_set_aio_fd_handlers(ioc); - aio_co_wake(co); + assert(qemu_get_current_aio_context() =3D=3D + qemu_coroutine_get_aio_context(co)); + qemu_coroutine_enter(co); } =20 static void qio_channel_set_aio_fd_handlers(QIOChannel *ioc) --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550685993553650.9776920984839; Wed, 20 Feb 2019 10:06:33 -0800 (PST) Received: from localhost ([127.0.0.1]:45000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwWGK-000364-EU for importer@patchew.org; Wed, 20 Feb 2019 13:06:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW00-0005Xs-M7 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwVzw-0005Np-MR for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50142) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwVzo-0005Hj-0i; Wed, 20 Feb 2019 12:49:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E62CF622F; Wed, 20 Feb 2019 17:49:23 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 682AA17150; Wed, 20 Feb 2019 17:49:10 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:36 +0100 Message-Id: <20190220174843.8847-7-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Feb 2019 17:49:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 06/13] nbd: Move nbd_read_eof() to nbd/client.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The only caller of nbd_read_eof() is nbd_receive_reply(), so it doesn't have to live in the header file, but can move next to its caller. Also add the missing coroutine_fn to the function and its caller. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/nbd.h | 3 ++- nbd/nbd-internal.h | 19 ------------------- nbd/client.c | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 96cfb1d7d5..cad975e00c 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -300,7 +300,8 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoTLS= Creds *tlscreds, int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info, Error **errp); int nbd_send_request(QIOChannel *ioc, NBDRequest *request); -int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp); +int coroutine_fn nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, + Error **errp); int nbd_client(int fd); int nbd_disconnect(int fd); int nbd_errno_to_system_errno(int err); diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 82aa221227..049f83df77 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -64,25 +64,6 @@ #define NBD_SET_TIMEOUT _IO(0xab, 9) #define NBD_SET_FLAGS _IO(0xab, 10) =20 -/* nbd_read_eof - * Tries to read @size bytes from @ioc. - * Returns 1 on success - * 0 on eof, when no data was read (errp is not set) - * negative errno on failure (errp is set) - */ -static inline int nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size, - Error **errp) -{ - int ret; - - assert(size); - ret =3D qio_channel_read_all_eof(ioc, buffer, size, errp); - if (ret < 0) { - ret =3D -EIO; - } - return ret; -} - /* nbd_write * Writes @size bytes to @ioc. Returns 0 on success. */ diff --git a/nbd/client.c b/nbd/client.c index 10a52ad7d0..28d174c0f3 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1387,12 +1387,32 @@ static int nbd_receive_structured_reply_chunk(QIOCh= annel *ioc, return 0; } =20 +/* nbd_read_eof + * Tries to read @size bytes from @ioc. + * Returns 1 on success + * 0 on eof, when no data was read (errp is not set) + * negative errno on failure (errp is set) + */ +static inline int coroutine_fn +nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size, Error **errp) +{ + int ret; + + assert(size); + ret =3D qio_channel_read_all_eof(ioc, buffer, size, errp); + if (ret < 0) { + ret =3D -EIO; + } + return ret; +} + /* nbd_receive_reply * Returns 1 on success * 0 on eof, when no data was read (errp is not set) * negative errno on failure (errp is set) */ -int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) +int coroutine_fn nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, + Error **errp) { int ret; const char *type; --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550686193874735.7073925059807; Wed, 20 Feb 2019 10:09:53 -0800 (PST) Received: from localhost ([127.0.0.1]:45045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwWJZ-0005fm-R5 for importer@patchew.org; Wed, 20 Feb 2019 13:09:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW04-0005aI-4F for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwW03-0005Rl-0v for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46930) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwVzu-0005Jy-3X; Wed, 20 Feb 2019 12:49:30 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1225235955C; Wed, 20 Feb 2019 17:49:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D06217267; Wed, 20 Feb 2019 17:49:23 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:37 +0100 Message-Id: <20190220174843.8847-8-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 20 Feb 2019 17:49:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 07/13] nbd: Use low-level QIOChannel API in nbd_read_eof() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of using the convenience wrapper qio_channel_read_all_eof(), use the lower level QIOChannel API. This means duplicating some code, but we'll need this because this coroutine yield is special: We want it to be interruptible so that nbd_client_attach_aio_context() can correctly reenter the coroutine. This moves the bdrv_dec/inc_in_flight() pair into nbd_read_eof(), so that connection_co will always sit in this exact qio_channel_yield() call when bdrv_drain() returns. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/nbd.h | 4 ++-- block/nbd-client.c | 8 +------- nbd/client.c | 46 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index cad975e00c..c6ef1ef42e 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -300,8 +300,8 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoTLS= Creds *tlscreds, int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info, Error **errp); int nbd_send_request(QIOChannel *ioc, NBDRequest *request); -int coroutine_fn nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, - Error **errp); +int coroutine_fn nbd_receive_reply(BlockDriverState *bs, QIOChannel *ioc, + NBDReply *reply, Error **errp); int nbd_client(int fd); int nbd_disconnect(int fd); int nbd_errno_to_system_errno(int err); diff --git a/block/nbd-client.c b/block/nbd-client.c index 5ce4aa9520..60f38f0320 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -84,15 +84,9 @@ static coroutine_fn void nbd_connection_entry(void *opaq= ue) * * Therefore we keep an additional in_flight reference all the tim= e and * only drop it temporarily here. - * - * FIXME This is not safe because the QIOChannel could wake up the - * coroutine for a second time; it is not prepared for coroutine - * resumption from external code. */ - bdrv_dec_in_flight(s->bs); assert(s->reply.handle =3D=3D 0); - ret =3D nbd_receive_reply(s->ioc, &s->reply, &local_err); - bdrv_inc_in_flight(s->bs); + ret =3D nbd_receive_reply(s->bs, s->ioc, &s->reply, &local_err); =20 if (local_err) { trace_nbd_read_reply_entry_fail(ret, error_get_pretty(local_er= r)); diff --git a/nbd/client.c b/nbd/client.c index 28d174c0f3..de7da48246 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1394,30 +1394,58 @@ static int nbd_receive_structured_reply_chunk(QIOCh= annel *ioc, * negative errno on failure (errp is set) */ static inline int coroutine_fn -nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size, Error **errp) +nbd_read_eof(BlockDriverState *bs, QIOChannel *ioc, void *buffer, size_t s= ize, + Error **errp) { - int ret; + bool partial =3D false; =20 assert(size); - ret =3D qio_channel_read_all_eof(ioc, buffer, size, errp); - if (ret < 0) { - ret =3D -EIO; + while (size > 0) { + struct iovec iov =3D { .iov_base =3D buffer, .iov_len =3D size }; + ssize_t len; + + len =3D qio_channel_readv(ioc, &iov, 1, errp); + if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { + bdrv_dec_in_flight(bs); + qio_channel_yield(ioc, G_IO_IN); + bdrv_inc_in_flight(bs); + continue; + } else if (len < 0) { + return -EIO; + } else if (len =3D=3D 0) { + if (partial) { + error_setg(errp, + "Unexpected end-of-file before all bytes were r= ead"); + return -EIO; + } else { + return 0; + } + } + + partial =3D true; + size -=3D len; + buffer =3D (uint8_t*) buffer + len; } - return ret; + return 1; } =20 /* nbd_receive_reply + * + * Decreases bs->in_flight while waiting for a new reply. This yield is wh= ere + * we wait indefinitely and the coroutine must be able to be safely reente= red + * for nbd_client_attach_aio_context(). + * * Returns 1 on success * 0 on eof, when no data was read (errp is not set) * negative errno on failure (errp is set) */ -int coroutine_fn nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, - Error **errp) +int coroutine_fn nbd_receive_reply(BlockDriverState *bs, QIOChannel *ioc, + NBDReply *reply, Error **errp) { int ret; const char *type; =20 - ret =3D nbd_read_eof(ioc, &reply->magic, sizeof(reply->magic), errp); + ret =3D nbd_read_eof(bs, ioc, &reply->magic, sizeof(reply->magic), err= p); if (ret <=3D 0) { return ret; } --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550685491522618.9364656536517; Wed, 20 Feb 2019 09:58:11 -0800 (PST) Received: from localhost ([127.0.0.1]:44826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW8G-0004Xe-Gt for importer@patchew.org; Wed, 20 Feb 2019 12:58:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW07-0005fO-6U for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwW04-0005WE-Jy for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46648) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwW02-0005Ku-10; Wed, 20 Feb 2019 12:49:38 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DAF4E1CFF3D; Wed, 20 Feb 2019 17:49:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E3F5171C1; Wed, 20 Feb 2019 17:49:27 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:38 +0100 Message-Id: <20190220174843.8847-9-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 20 Feb 2019 17:49:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 08/13] nbd: Increase bs->in_flight during AioContext switch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_drain() must not leave connection_co scheduled, so bs->in_flight needs to be increased while the coroutine is waiting to be scheduled in the new AioContext after nbd_client_attach_aio_context(). Signed-off-by: Kevin Wolf --- block/nbd-client.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 60f38f0320..bfbaf7ebe9 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -977,14 +977,30 @@ void nbd_client_detach_aio_context(BlockDriverState *= bs) qio_channel_detach_aio_context(QIO_CHANNEL(client->ioc)); } =20 +static void nbd_client_attach_aio_context_bh(void *opaque) +{ + BlockDriverState *bs =3D opaque; + NBDClientSession *client =3D nbd_get_client_session(bs); + + /* The node is still drained, so we know the coroutine has yielded in + * nbd_read_eof(), the only place where bs->in_flight can reach 0, or = it is + * entered for the first time. Both places are safe for entering the + * coroutine.*/ + qemu_aio_coroutine_enter(bs->aio_context, client->connection_co); + bdrv_dec_in_flight(bs); +} + void nbd_client_attach_aio_context(BlockDriverState *bs, AioContext *new_context) { NBDClientSession *client =3D nbd_get_client_session(bs); qio_channel_attach_aio_context(QIO_CHANNEL(client->ioc), new_context); =20 - /* FIXME Really need a bdrv_inc_in_flight() here */ - aio_co_schedule(new_context, client->connection_co); + bdrv_inc_in_flight(bs); + + /* Need to wait here for the BH to run because the BH must run while t= he + * node is still drained. */ + aio_wait_bh_oneshot(new_context, nbd_client_attach_aio_context_bh, bs); } =20 void nbd_client_close(BlockDriverState *bs) --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550686475204621.0370654625036; Wed, 20 Feb 2019 10:14:35 -0800 (PST) Received: from localhost ([127.0.0.1]:45148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwWO4-00011a-QY for importer@patchew.org; Wed, 20 Feb 2019 13:14:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW07-0005fU-9L for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwW05-0005Wh-1A for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35320) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwW03-0005OY-1I; Wed, 20 Feb 2019 12:49:39 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CBD3C12FD4E; Wed, 20 Feb 2019 17:49:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A76C1710E; Wed, 20 Feb 2019 17:49:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:39 +0100 Message-Id: <20190220174843.8847-10-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 20 Feb 2019 17:49:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 09/13] block: Don't poll in bdrv_set_aio_context() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The explicit aio_poll() call in bdrv_set_aio_context() was added in commit c2b6428d388 as a workaround for bdrv_drain() failing to achieve to actually quiesce everything (specifically the NBD client code to switch AioContext). Now that the NBD client has been fixed to complete this operation during bdrv_drain(), we don't need the workaround any more. It was wrong anyway: aio_poll() must always be run in the home thread of the AioContext. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/block.c b/block.c index 0c12632661..17bc1d3dca 100644 --- a/block.c +++ b/block.c @@ -5273,10 +5273,6 @@ void bdrv_set_aio_context(BlockDriverState *bs, AioC= ontext *new_context) bdrv_parent_drained_begin(bs, NULL, false); bdrv_drain(bs); /* ensure there are no in-flight requests */ =20 - while (aio_poll(ctx, false)) { - /* wait for all bottom halves to execute */ - } - bdrv_detach_aio_context(bs); =20 /* This function executes in the old AioContext so acquire the new one= in --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550686612211401.52810939888036; Wed, 20 Feb 2019 10:16:52 -0800 (PST) Received: from localhost ([127.0.0.1]:45213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwWQJ-0002un-1g for importer@patchew.org; Wed, 20 Feb 2019 13:16:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW07-0005fV-9P for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwW05-0005Wn-25 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50820) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwW03-0005PG-1O; Wed, 20 Feb 2019 12:49:39 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 773D0F56F2; Wed, 20 Feb 2019 17:49:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB89A61D04; Wed, 20 Feb 2019 17:49:33 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:40 +0100 Message-Id: <20190220174843.8847-11-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Feb 2019 17:49:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 10/13] block: Fix AioContext switch for drained node X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When a drained node changes its AioContext, we need to move its aio_disable_external() to the new context, too. Without this fix, drain_end will try to reenable the new context, which has never been disabled, so an assertion failure is triggered. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block.c b/block.c index 17bc1d3dca..aefb5701f5 100644 --- a/block.c +++ b/block.c @@ -5227,6 +5227,9 @@ void bdrv_detach_aio_context(BlockDriverState *bs) bdrv_detach_aio_context(child->bs); } =20 + if (bs->quiesce_counter) { + aio_enable_external(bs->aio_context); + } bs->aio_context =3D NULL; } =20 @@ -5240,6 +5243,10 @@ void bdrv_attach_aio_context(BlockDriverState *bs, return; } =20 + if (bs->quiesce_counter) { + aio_disable_external(new_context); + } + bs->aio_context =3D new_context; =20 QLIST_FOREACH(child, &bs->children, next) { --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550685647070375.53703142561335; Wed, 20 Feb 2019 10:00:47 -0800 (PST) Received: from localhost ([127.0.0.1]:44900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwWAh-0007AA-36 for importer@patchew.org; Wed, 20 Feb 2019 13:00:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW07-0005fX-9W for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwW05-0005XD-8U for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwW03-0005QD-2V; Wed, 20 Feb 2019 12:49:39 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 143D8C12FD7E; Wed, 20 Feb 2019 17:49:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93B7E17267; Wed, 20 Feb 2019 17:49:35 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:41 +0100 Message-Id: <20190220174843.8847-12-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 20 Feb 2019 17:49:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 11/13] test-bdrv-drain: AioContext switch in drained section X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- tests/test-bdrv-drain.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index ee1740ff06..1b1f6c17a5 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -1522,6 +1522,36 @@ static void test_append_to_drained(void) blk_unref(blk); } =20 +static void test_set_aio_context(void) +{ + BlockDriverState *bs; + IOThread *a =3D iothread_new(); + IOThread *b =3D iothread_new(); + AioContext *ctx_a =3D iothread_get_aio_context(a); + AioContext *ctx_b =3D iothread_get_aio_context(b); + + bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, + &error_abort); + + bdrv_drained_begin(bs); + bdrv_set_aio_context(bs, ctx_a); + + aio_context_acquire(ctx_a); + bdrv_drained_end(bs); + + bdrv_drained_begin(bs); + bdrv_set_aio_context(bs, ctx_b); + aio_context_release(ctx_a); + aio_context_acquire(ctx_b); + bdrv_set_aio_context(bs, qemu_get_aio_context()); + aio_context_release(ctx_b); + bdrv_drained_end(bs); + + bdrv_unref(bs); + iothread_join(a); + iothread_join(b); +} + int main(int argc, char **argv) { int ret; @@ -1603,6 +1633,8 @@ int main(int argc, char **argv) =20 g_test_add_func("/bdrv-drain/attach/drain", test_append_to_drained); =20 + g_test_add_func("/bdrv-drain/set_aio_context", test_set_aio_context); + ret =3D g_test_run(); qemu_event_destroy(&done_event); return ret; --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550685409828548.4643299517389; Wed, 20 Feb 2019 09:56:49 -0800 (PST) Received: from localhost ([127.0.0.1]:44816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW6v-0003Pr-BI for importer@patchew.org; Wed, 20 Feb 2019 12:56:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW0I-0005rs-Jj for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwW07-0005YD-7j for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:49:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwW03-0005Ru-LG; Wed, 20 Feb 2019 12:49:39 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7005A649D; Wed, 20 Feb 2019 17:49:38 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6349461B98; Wed, 20 Feb 2019 17:49:37 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:42 +0100 Message-Id: <20190220174843.8847-13-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 20 Feb 2019 17:49:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 12/13] block: Use normal drain for bdrv_set_aio_context() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Now that bdrv_set_aio_context() works inside drained sections, it can also use the real drain function instead of open coding something similar. Signed-off-by: Kevin Wolf --- block.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index aefb5701f5..375a216f76 100644 --- a/block.c +++ b/block.c @@ -5268,18 +5268,16 @@ void bdrv_attach_aio_context(BlockDriverState *bs, bs->walking_aio_notifiers =3D false; } =20 +/* The caller must own the AioContext lock for the old AioContext of bs, b= ut it + * must not own the AioContext lock for new_context (unless new_context is + * the same as the current context of bs). */ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context) { - AioContext *ctx =3D bdrv_get_aio_context(bs); - - if (ctx =3D=3D new_context) { + if (bdrv_get_aio_context(bs) =3D=3D new_context) { return; } =20 - aio_disable_external(ctx); - bdrv_parent_drained_begin(bs, NULL, false); - bdrv_drain(bs); /* ensure there are no in-flight requests */ - + bdrv_drained_begin(bs); bdrv_detach_aio_context(bs); =20 /* This function executes in the old AioContext so acquire the new one= in @@ -5287,8 +5285,7 @@ void bdrv_set_aio_context(BlockDriverState *bs, AioCo= ntext *new_context) */ aio_context_acquire(new_context); bdrv_attach_aio_context(bs, new_context); - bdrv_parent_drained_end(bs, NULL, false); - aio_enable_external(ctx); + bdrv_drained_end(bs); aio_context_release(new_context); } =20 --=20 2.20.1 From nobody Sat May 18 16:18:04 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550686745191373.66684893757235; Wed, 20 Feb 2019 10:19:05 -0800 (PST) Received: from localhost ([127.0.0.1]:45239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwWST-0004w1-8N for importer@patchew.org; Wed, 20 Feb 2019 13:19:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwW0T-00062O-LS for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:50:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwW0S-0005hl-Ru for qemu-devel@nongnu.org; Wed, 20 Feb 2019 12:50:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwW0N-0005aT-TG; Wed, 20 Feb 2019 12:50:01 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE43AF5704; Wed, 20 Feb 2019 17:49:47 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-82.ams2.redhat.com [10.36.117.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 316B361D14; Wed, 20 Feb 2019 17:49:39 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Feb 2019 18:48:43 +0100 Message-Id: <20190220174843.8847-14-kwolf@redhat.com> In-Reply-To: <20190220174843.8847-1-kwolf@redhat.com> References: <20190220174843.8847-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Feb 2019 17:49:48 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 13/13] aio-posix: Assert that aio_poll() is always called in home thread X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" aio_poll() has an existing assertion that the function is only called from the AioContext's home thread if blocking is allowed. This is not enough, some handlers make assumptions about the thread they run in. Extend the assertion to non-blocking calls, too. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- util/aio-posix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index 8640dfde9f..6fbfa7924f 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -613,6 +613,8 @@ bool aio_poll(AioContext *ctx, bool blocking) int64_t timeout; int64_t start =3D 0; =20 + assert(in_aio_context_home_thread(ctx)); + /* aio_notify can avoid the expensive event_notifier_set if * everything (file descriptors, bottom halves, timers) will * be re-evaluated before the next blocking poll(). This is @@ -621,7 +623,6 @@ bool aio_poll(AioContext *ctx, bool blocking) * so disable the optimization now. */ if (blocking) { - assert(in_aio_context_home_thread(ctx)); atomic_add(&ctx->notify_me, 2); } =20 --=20 2.20.1