From nobody Sun Oct 26 00:02:42 2025 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; 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 1516279946382552.5197280848006; Thu, 18 Jan 2018 04:52:26 -0800 (PST) Received: from localhost ([::1]:56956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ec9g9-0008Ft-EH for importer@patchew.org; Thu, 18 Jan 2018 07:52:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ec9Y8-0001Ms-Cp for qemu-devel@nongnu.org; Thu, 18 Jan 2018 07:44:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ec9Y1-0004ZO-UK for qemu-devel@nongnu.org; Thu, 18 Jan 2018 07:44:08 -0500 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:36149) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ec9Y1-0004Ys-LL; Thu, 18 Jan 2018 07:44:01 -0500 Received: by mail-wr0-x242.google.com with SMTP id d9so22403098wre.3; Thu, 18 Jan 2018 04:44:01 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id t51sm13006472wrc.21.2018.01.18.04.43.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 04:43:59 -0800 (PST) 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=rHZ3pOVowV0e4wA8HR7PmHb/nLDCrTpr05YR41QJ9Nc=; b=rOKuMcPW8P8SwqLkUZRi7/mQQOzy+qt6TxF/8nQt9Tv9SY2bZhA2Vgz7jgz6adYvrr 0nEyy2x6ZLjjIWRFT293flaSUSfiNh6/YAyzY+/HATLNnX0r5M8bRGeiXm6jF1tIkjbc MChJmhIGs20Q6P3CXRY+coz+lfFIv9u4RWj8GiMprtF6KdXEK3j/JMwF4WkEziLk2Zwd Np4x2aOFd7MEcWt5mHIqCjiSadKqaTpf4iBZ3Y8J0n6og0ciVeigJIoScFVack5ezv0X 53NIG/iVLmckkupiQ6qQgC3jYkf6VzpFHuEfCqIU7SBfghiDyxxdcLaRieQPpTV/wBaw 31sA== 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=rHZ3pOVowV0e4wA8HR7PmHb/nLDCrTpr05YR41QJ9Nc=; b=AWum/rDFg4921LwSGYuh+s11VNm9Pw/LEmUvXDP1GH/0OB9qH3FSoMqVsODpkwzo44 VrkqWZtUyyAG6ac91KL8ASyT/gUVRui+GuRHdpTT0Hr3oMB6WS3tPbfpT1nJN0oznBiE nep2f74ybORiwaf/S/O+u4coe+SENVyL45aHIp3x7N3N1wY1xDi+g2ysPvs6DkpB/YVj TbkOQrL9cwyLe65aoK23NetqMrdXWl4CcuDiAdrrHNid44hOFEa2soaZhPzwZ02tlZtz jwXO5JcMhGVjtfsWz0/nT+0OzYx/+lArpm9+9rXGoIBoMZQQR1iO01BkdGTTP48rGxRP gqxA== X-Gm-Message-State: AKwxytdwusgzo+EIMvnL8HlJYM0uok4ufXc2wbXcBTZ2Thk7jfSh6/Vf 9VxO/4W8FFlimxsiYlHgvLXPd2me X-Google-Smtp-Source: ACJfBot/c3mCsDxJ+GCyXPdHXYP2TDN0AYnUAEiWEzVyJza8vPMYxkpsGcPI1PUgjg9sD56CgnNZMQ== X-Received: by 10.223.142.56 with SMTP id n53mr5612867wrb.54.1516279440182; Thu, 18 Jan 2018 04:44:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Jan 2018 13:43:49 +0100 Message-Id: <1516279431-30424-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516279431-30424-1-git-send-email-pbonzini@redhat.com> References: <1516279431-30424-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PATCH 5/7] block: convert bdrv_invalidate_cache callback to coroutine_fn 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, 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" QED's bdrv_invalidate_cache implementation would like to reuse functions that acquire/release the metadata locks. Call it from coroutine context to simplify the logic. Signed-off-by: Paolo Bonzini --- block.c | 41 +++++++++++++++++++++++++++++++++++++---- block/iscsi.c | 6 +++--- block/nfs.c | 6 +++--- block/qcow2.c | 7 +++++-- block/qed.c | 13 +++++-------- block/rbd.c | 6 +++--- include/block/block_int.h | 3 ++- 7 files changed, 58 insertions(+), 24 deletions(-) diff --git a/block.c b/block.c index cf33135..6ba7471 100644 --- a/block.c +++ b/block.c @@ -4214,7 +4214,8 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } =20 -void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) +static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, + Error **errp) { BdrvChild *child, *parent; uint64_t perm, shared_perm; @@ -4230,7 +4231,7 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Erro= r **errp) } =20 QLIST_FOREACH(child, &bs->children, next) { - bdrv_invalidate_cache(child->bs, &local_err); + bdrv_co_invalidate_cache(child->bs, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -4260,8 +4261,8 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Erro= r **errp) } bdrv_set_perm(bs, perm, shared_perm); =20 - if (bs->drv->bdrv_invalidate_cache) { - bs->drv->bdrv_invalidate_cache(bs, &local_err); + if (bs->drv->bdrv_co_invalidate_cache) { + bs->drv->bdrv_co_invalidate_cache(bs, &local_err); if (local_err) { bs->open_flags |=3D BDRV_O_INACTIVE; error_propagate(errp, local_err); @@ -4287,6 +4288,38 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Err= or **errp) } } =20 +typedef struct InvalidateCacheCo { + BlockDriverState *bs; + Error **errp; + bool done; +} InvalidateCacheCo; + +static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque) +{ + InvalidateCacheCo *ico =3D opaque; + bdrv_co_invalidate_cache(ico->bs, ico->errp); + ico->done =3D true; +} + +void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) +{ + Coroutine *co; + InvalidateCacheCo ico =3D { + .bs =3D bs, + .done =3D false, + .errp =3D errp + }; + + if (qemu_in_coroutine()) { + /* Fast-path if already in coroutine context */ + bdrv_invalidate_cache_co_entry(&ico); + } else { + co =3D qemu_coroutine_create(bdrv_invalidate_cache_co_entry, &ico); + qemu_coroutine_enter(co); + BDRV_POLL_WHILE(bs, !ico.done); + } +} + void bdrv_invalidate_cache_all(Error **errp) { BlockDriverState *bs; diff --git a/block/iscsi.c b/block/iscsi.c index 5f358f9..9b70899 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2164,8 +2164,8 @@ static int iscsi_get_info(BlockDriverState *bs, Block= DriverInfo *bdi) return 0; } =20 -static void iscsi_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn iscsi_co_invalidate_cache(BlockDriverState *bs, + Error **errp) { IscsiLun *iscsilun =3D bs->opaque; iscsi_allocmap_invalidate(iscsilun); @@ -2196,7 +2196,7 @@ static BlockDriver bdrv_iscsi =3D { .create_opts =3D &iscsi_create_opts, .bdrv_reopen_prepare =3D iscsi_reopen_prepare, .bdrv_reopen_commit =3D iscsi_reopen_commit, - .bdrv_invalidate_cache =3D iscsi_invalidate_cache, + .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, =20 .bdrv_getlength =3D iscsi_getlength, .bdrv_get_info =3D iscsi_get_info, diff --git a/block/nfs.c b/block/nfs.c index 8029dc2..d7f9a6c 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -876,8 +876,8 @@ static void nfs_refresh_filename(BlockDriverState *bs, = QDict *options) } =20 #ifdef LIBNFS_FEATURE_PAGECACHE -static void nfs_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn nfs_co_invalidate_cache(BlockDriverState *bs, + Error **errp) { NFSClient *client =3D bs->opaque; nfs_pagecache_invalidate(client->context, client->fh); @@ -910,7 +910,7 @@ static BlockDriver bdrv_nfs =3D { .bdrv_refresh_filename =3D nfs_refresh_filename, =20 #ifdef LIBNFS_FEATURE_PAGECACHE - .bdrv_invalidate_cache =3D nfs_invalidate_cache, + .bdrv_co_invalidate_cache =3D nfs_co_invalidate_cache, #endif }; =20 diff --git a/block/qcow2.c b/block/qcow2.c index 7c11516..e886a44 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2109,7 +2109,8 @@ static void qcow2_close(BlockDriverState *bs) qcow2_free_snapshots(bs); } =20 -static void qcow2_invalidate_cache(BlockDriverState *bs, Error **errp) +static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; int flags =3D s->flags; @@ -2132,7 +2133,9 @@ static void qcow2_invalidate_cache(BlockDriverState *= bs, Error **errp) options =3D qdict_clone_shallow(bs->options); =20 flags &=3D ~BDRV_O_INACTIVE; + qemu_co_mutex_lock(&s->lock); ret =3D qcow2_do_open(bs, options, flags, &local_err); + qemu_co_mutex_unlock(&s->lock); QDECREF(options); if (local_err) { error_propagate(errp, local_err); @@ -4386,7 +4389,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_change_backing_file =3D qcow2_change_backing_file, =20 .bdrv_refresh_limits =3D qcow2_refresh_limits, - .bdrv_invalidate_cache =3D qcow2_invalidate_cache, + .bdrv_co_invalidate_cache =3D qcow2_co_invalidate_cache, .bdrv_inactivate =3D qcow2_inactivate, =20 .create_opts =3D &qcow2_create_opts, diff --git a/block/qed.c b/block/qed.c index 3e1f4bc..5cf519c 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1550,7 +1550,8 @@ static int bdrv_qed_change_backing_file(BlockDriverSt= ate *bs, return ret; } =20 -static void bdrv_qed_invalidate_cache(BlockDriverState *bs, Error **errp) +static void coroutine_fn bdrv_qed_co_invalidate_cache(BlockDriverState *bs, + Error **errp) { BDRVQEDState *s =3D bs->opaque; Error *local_err =3D NULL; @@ -1559,13 +1560,9 @@ static void bdrv_qed_invalidate_cache(BlockDriverSta= te *bs, Error **errp) bdrv_qed_close(bs); =20 bdrv_qed_init_state(bs); - if (qemu_in_coroutine()) { - qemu_co_mutex_lock(&s->table_lock); - } + qemu_co_mutex_lock(&s->table_lock); ret =3D bdrv_qed_do_open(bs, NULL, bs->open_flags, &local_err); - if (qemu_in_coroutine()) { - qemu_co_mutex_unlock(&s->table_lock); - } + qemu_co_mutex_unlock(&s->table_lock); if (local_err) { error_propagate(errp, local_err); error_prepend(errp, "Could not reopen qed layer: "); @@ -1640,7 +1637,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_get_info =3D bdrv_qed_get_info, .bdrv_refresh_limits =3D bdrv_qed_refresh_limits, .bdrv_change_backing_file =3D bdrv_qed_change_backing_file, - .bdrv_invalidate_cache =3D bdrv_qed_invalidate_cache, + .bdrv_co_invalidate_cache =3D bdrv_qed_co_invalidate_cache, .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, diff --git a/block/rbd.c b/block/rbd.c index 67ac2ee..9632355 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1090,8 +1090,8 @@ static BlockAIOCB *qemu_rbd_aio_pdiscard(BlockDriverS= tate *bs, #endif =20 #ifdef LIBRBD_SUPPORTS_INVALIDATE -static void qemu_rbd_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn qemu_rbd_co_invalidate_cache(BlockDriverState *bs, + Error **errp) { BDRVRBDState *s =3D bs->opaque; int r =3D rbd_invalidate_cache(s->image); @@ -1157,7 +1157,7 @@ static BlockDriver bdrv_rbd =3D { .bdrv_snapshot_list =3D qemu_rbd_snap_list, .bdrv_snapshot_goto =3D qemu_rbd_snap_rollback, #ifdef LIBRBD_SUPPORTS_INVALIDATE - .bdrv_invalidate_cache =3D qemu_rbd_invalidate_cache, + .bdrv_co_invalidate_cache =3D qemu_rbd_co_invalidate_cache, #endif }; =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index 05f498f..3481da1 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -218,7 +218,8 @@ struct BlockDriver { /* * Invalidate any cached meta-data. */ - void (*bdrv_invalidate_cache)(BlockDriverState *bs, Error **errp); + void coroutine_fn (*bdrv_co_invalidate_cache)(BlockDriverState *bs, + Error **errp); int (*bdrv_inactivate)(BlockDriverState *bs); =20 /* --=20 1.8.3.1