From nobody Wed Nov 5 09:04:11 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; 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 1499706004719539.1499620919385; Mon, 10 Jul 2017 10:00:04 -0700 (PDT) Received: from localhost ([::1]:42105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUc2U-0004z6-9X for importer@patchew.org; Mon, 10 Jul 2017 13:00:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUc18-00044z-QP for qemu-devel@nongnu.org; Mon, 10 Jul 2017 12:58:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUc17-00030q-H4 for qemu-devel@nongnu.org; Mon, 10 Jul 2017 12:58:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59436) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUc17-00030h-7h for qemu-devel@nongnu.org; Mon, 10 Jul 2017 12:58:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AECA80481 for ; Mon, 10 Jul 2017 16:58:36 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-181.ams2.redhat.com [10.36.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C86ED5D6A6; Mon, 10 Jul 2017 16:58:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0AECA80481 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0AECA80481 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 18:58:25 +0200 Message-Id: <20170710165827.4250-4-pbonzini@redhat.com> In-Reply-To: <20170710165827.4250-1-pbonzini@redhat.com> References: <20170710165827.4250-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 10 Jul 2017 16:58:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/5] 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, marcandre.lureau@redhat.com 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" 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 223ca3f85f..c8856cc594 100644 --- a/block.c +++ b/block.c @@ -4014,7 +4014,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; @@ -4030,7 +4031,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; @@ -4038,8 +4039,8 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Erro= r **errp) } =20 bs->open_flags &=3D ~BDRV_O_INACTIVE; - 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); @@ -4075,6 +4076,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 7aab379c48..01a4063d93 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2168,8 +2168,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); @@ -2200,7 +2200,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 06e0c6f5f8..455240677f 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -865,8 +865,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); @@ -899,7 +899,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 b5de67d113..4ff7e89009 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1854,7 +1854,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; @@ -1877,7 +1878,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); @@ -3540,7 +3543,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 3c2867c946..56254faee8 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1543,7 +1543,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; @@ -1552,13 +1553,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: "); @@ -1633,7 +1630,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 68c04a0d9d..2ccb9e41ca 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1077,8 +1077,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); @@ -1144,7 +1144,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 50ba349db7..8558d7b78d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -181,7 +181,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 2.13.0