From nobody Tue Feb 10 23:00:41 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.zoho.com; dkim=fail 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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496224574386457.7195092976774; Wed, 31 May 2017 02:56:14 -0700 (PDT) Received: from localhost ([::1]:58212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0MN-0004Ig-Lo for importer@patchew.org; Wed, 31 May 2017 05:56:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AM-0002Xp-C4 for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AL-0001oL-71 for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:46 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:33389) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AL-0001n1-0Y; Wed, 31 May 2017 05:43:45 -0400 Received: by mail-wm0-x244.google.com with SMTP id b84so2264092wmh.0; Wed, 31 May 2017 02:43:44 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2+DuydxWdK8NwVLM3O6tFEQ2TO9znVjWH3rgLfkZG3U=; b=sCMraupEZO7alVgnBoscpqiveMopClTwFrjxKRxW5U3OnkghYcRQPnFy5nsTxMSMZI ax3PbN/bFgnc53xJ0BTiDFBdlQ+pFaQ3wTU6XP+MkYMwcXvynlqGeooH1kLi1gC5kYTI 0EGqJQYpojfYk/kh4IXfaBdDS+da/t/zSAch+KBnLxRSExhPKmWjiRsZBimSF01yd8V3 x913U+TkwiZfhqHr/k5Y4ZZEILMGFk0KEZSp2UW4XIKasWT2BOCqB7u6KzVVHrBusZE/ fHfG9clpWYTCGU7JvbkjEweh8b/tijWUjANynui1o37VXrGQudGaudMkmUFRN0gmrDnl 5qrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=2+DuydxWdK8NwVLM3O6tFEQ2TO9znVjWH3rgLfkZG3U=; b=ugh/xML1KmVGB4vYZ+okamNt+gCoA5A19H20uQaS0gLQtPI9+WwxfLx3UvlT9UtwXK t8m604DZn4OOpjfMrCmWn1emfN9R5Ha7A63ZlOMHYslb9g8jw95+lWyMdUGIHaSr9cuY IemIQ2pZHs5+qZ8hOWZmMK6ykTzXX13eJXRCfq5kwiMXZRXSWl+0dpSo2Fj3sSJBBFbg cSOky70cDDX2qCUb8ViyNIAy4owsT6XTYqGzZ85rudt/H1u2CI76JtuQxykDZGOHTeyy Updw6JZuAKKPDE6xbYUb7A5DRja/WIuvEOo2UmCD38T/bavWYhSPt9A9jt6n5wcPxepg K32A== X-Gm-Message-State: AODbwcDub5PQa655/h4Oi+Qc2AEYS+Aj1/Lfh/09Y9BV6eoHo4BNOKhw IrfIj6UsJ/03nhclB2Y= X-Received: by 10.28.35.8 with SMTP id j8mr4438592wmj.96.1496223823722; Wed, 31 May 2017 02:43:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:27 +0200 Message-Id: <20170531094330.1808-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PATCH 08/11] block: invoke .bdrv_drain callback in coroutine context and from AioContext 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, famz@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This will let the callback take a CoMutex in the next patch. Signed-off-by: Paolo Bonzini --- block/io.c | 42 +++++++++++++++++++++++++++++++++--------- block/qed.c | 6 +++--- include/block/block_int.h | 2 +- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/block/io.c b/block/io.c index 03c77da66f..d5d9107885 100644 --- a/block/io.c +++ b/block/io.c @@ -157,6 +157,37 @@ bool bdrv_requests_pending(BlockDriverState *bs) return false; } =20 +typedef struct { + Coroutine *co; + BlockDriverState *bs; + bool done; +} BdrvCoDrainData; + +static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) +{ + BdrvCoDrainData *data =3D opaque; + BlockDriverState *bs =3D data->bs; + + bs->drv->bdrv_co_drain(bs); + + /* Set data->done before reading bs->wakeup. */ + atomic_mb_set(&data->done, true); + bdrv_wakeup(bs); +} + +static void bdrv_drain_invoke(BlockDriverState *bs) +{ + BdrvCoDrainData data =3D { .bs =3D bs, .done =3D false }; + + if (!bs->drv || !bs->drv->bdrv_co_drain) { + return; + } + + data.co =3D qemu_coroutine_create(bdrv_drain_invoke_entry, &data); + bdrv_coroutine_enter(bs, data.co); + BDRV_POLL_WHILE(bs, !data.done); +} + static bool bdrv_drain_recurse(BlockDriverState *bs) { BdrvChild *child, *tmp; @@ -164,9 +195,8 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) =20 waited =3D BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); =20 - if (bs->drv && bs->drv->bdrv_drain) { - bs->drv->bdrv_drain(bs); - } + /* Ensure any pending metadata writes are submitted to bs->file. */ + bdrv_drain_invoke(bs); =20 QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { BlockDriverState *bs =3D child->bs; @@ -192,12 +222,6 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) return waited; } =20 -typedef struct { - Coroutine *co; - BlockDriverState *bs; - bool done; -} BdrvCoDrainData; - static void bdrv_co_drain_bh_cb(void *opaque) { BdrvCoDrainData *data =3D opaque; diff --git a/block/qed.c b/block/qed.c index 83a0973cfb..990210cd9c 100644 --- a/block/qed.c +++ b/block/qed.c @@ -351,7 +351,7 @@ static void bdrv_qed_attach_aio_context(BlockDriverStat= e *bs, } } =20 -static void bdrv_qed_drain(BlockDriverState *bs) +static void coroutine_fn bdrv_qed_co_drain(BlockDriverState *bs) { BDRVQEDState *s =3D bs->opaque; =20 @@ -360,7 +360,7 @@ static void bdrv_qed_drain(BlockDriverState *bs) */ if (s->need_check_timer && timer_pending(s->need_check_timer)) { qed_cancel_need_check_timer(s); - qed_need_check_timer_cb(s); + qed_need_check_timer_entry(s); } } =20 @@ -1544,7 +1544,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_check =3D bdrv_qed_check, .bdrv_detach_aio_context =3D bdrv_qed_detach_aio_context, .bdrv_attach_aio_context =3D bdrv_qed_attach_aio_context, - .bdrv_drain =3D bdrv_qed_drain, + .bdrv_co_drain =3D bdrv_qed_co_drain, }; =20 static void bdrv_qed_init(void) diff --git a/include/block/block_int.h b/include/block/block_int.h index a150791f0f..b14340d751 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -314,7 +314,7 @@ struct BlockDriver { * Drain and stop any internal sources of requests in the driver, and * remain so until next I/O callback (e.g. bdrv_co_writev) is called. */ - void (*bdrv_drain)(BlockDriverState *bs); + void coroutine_fn (*bdrv_co_drain)(BlockDriverState *bs); =20 void (*bdrv_add_child)(BlockDriverState *parent, BlockDriverState *chi= ld, Error **errp); --=20 2.13.0