From nobody Sat Feb 7 21:24:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 153027617395352.434053198668835; Fri, 29 Jun 2018 05:42:53 -0700 (PDT) Received: from localhost ([::1]:41883 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYsjb-00083c-2W for importer@patchew.org; Fri, 29 Jun 2018 08:42:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYsiD-0006xH-JY for qemu-devel@nongnu.org; Fri, 29 Jun 2018 08:41:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYsiC-0003fI-AI for qemu-devel@nongnu.org; Fri, 29 Jun 2018 08:41:17 -0400 Received: from relay.sw.ru ([185.231.240.75]:39116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fYsi4-0003Ff-Tr; Fri, 29 Jun 2018 08:41:09 -0400 Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=dptest2.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fYsi0-0002JG-0X; Fri, 29 Jun 2018 15:41:04 +0300 From: Denis Plotnikov To: kwolf@redhat.com, reitz@redhat.com, stefanha@redhat.com, famz@redhat.com, qemu-stable@nongnu.org Date: Fri, 29 Jun 2018 15:40:52 +0300 Message-Id: <20180629124052.331406-3-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180629124052.331406-1-dplotnikov@virtuozzo.com> References: <20180629124052.331406-1-dplotnikov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v0 2/2] block: postpone the coroutine executing if the BDS's is drained 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: qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Fixes the problem of ide request appearing when the BDS is in the "drained section". Without the patch the request can come and be processed by the main event loop, as the ide requests are processed by the main event loop and the main event loop doesn't stop when its context is in the "drained section". The request execution is postponed until the end of "drained section". The patch doesn't modify ide specific code, as well as any other device code. Instead, it modifies the infrastructure of asynchronous Block Backend requests, in favor of postponing the requests arisen when in "drained section" to remove the possibility of request appearing for all the infrastructure clients. This approach doesn't make vCPU processing the request wait untill the end of request processing. Signed-off-by: Denis Plotnikov --- block/block-backend.c | 58 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index d55c328736..68dcd704d2 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1318,6 +1318,7 @@ typedef struct BlkAioEmAIOCB { BlkRwCo rwco; int bytes; bool has_returned; + CoroutineEntry *co_entry; } BlkAioEmAIOCB; =20 static const AIOCBInfo blk_aio_em_aiocb_info =3D { @@ -1340,16 +1341,55 @@ static void blk_aio_complete_bh(void *opaque) blk_aio_complete(acb); } =20 +static void blk_aio_create_co(void *opaque) +{ + BlockDriverState *current_bs; + AioContext *ctx; + BlkAioEmAIOCB *acb =3D (BlkAioEmAIOCB *) opaque; + BlockBackend *blk =3D acb->rwco.blk; + + /* The check makes sense if the action was postponed until the context + * is enabled for external requests: if a BlockDriverState of a BlockB= ackend + * was changed, for example on making a new snapshot, update BlockDriv= erState + * in ACB and try to run the coroutine in the changed BDS context + */ + current_bs =3D blk_bs(blk); + + if (current_bs !=3D acb->common.bs) { + acb->common.bs =3D current_bs; + } + + ctx =3D blk_get_aio_context(blk); + /* If a request comes from device (e.g. ide controller) when + * the context disabled, postpone the request until the context is + * enabled for external requests. + * Otherwise, create a couroutine and enter it right now + */ + aio_context_acquire(ctx); + if (aio_external_disabled(ctx)) { + AioPostponedAction *action =3D aio_create_postponed_action( + blk_aio_create_co, acb); + aio_postpone_action(ctx, action); + } else { + Coroutine *co =3D qemu_coroutine_create(acb->co_entry, acb); + blk_inc_in_flight(blk); + bdrv_coroutine_enter(acb->common.bs, co); + + acb->has_returned =3D true; + if (acb->rwco.ret !=3D NOT_DONE) { + aio_bh_schedule_oneshot(ctx, blk_aio_complete_bh, acb); + } + } + aio_context_release(ctx); +} + static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int byt= es, void *iobuf, CoroutineEntry co_entry, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque) { - BlkAioEmAIOCB *acb; - Coroutine *co; =20 - blk_inc_in_flight(blk); - acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); + BlkAioEmAIOCB *acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, op= aque); acb->rwco =3D (BlkRwCo) { .blk =3D blk, .offset =3D offset, @@ -1359,15 +1399,9 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, i= nt64_t offset, int bytes, }; acb->bytes =3D bytes; acb->has_returned =3D false; + acb->co_entry =3D co_entry; =20 - co =3D qemu_coroutine_create(co_entry, acb); - bdrv_coroutine_enter(blk_bs(blk), co); - - acb->has_returned =3D true; - if (acb->rwco.ret !=3D NOT_DONE) { - aio_bh_schedule_oneshot(blk_get_aio_context(blk), - blk_aio_complete_bh, acb); - } + blk_aio_create_co(acb); =20 return &acb->common; } --=20 2.17.0