From nobody Fri Oct 24 22:13:25 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1519922526438468.62279930772286; Thu, 1 Mar 2018 08:42:06 -0800 (PST) Received: from localhost ([::1]:58011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erRHR-0002Hl-Ar for importer@patchew.org; Thu, 01 Mar 2018 11:42:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erRCN-0006mg-BF for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:36:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erRCL-00031B-RS for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:36:51 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:53237) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1erRCL-0002zg-I0; Thu, 01 Mar 2018 11:36:49 -0500 Received: by mail-wm0-x242.google.com with SMTP id t3so13291482wmc.2; Thu, 01 Mar 2018 08:36:49 -0800 (PST) Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it. [94.36.191.219]) by smtp.gmail.com with ESMTPSA id a14sm4187152wrf.22.2018.03.01.08.36.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Mar 2018 08:36:44 -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=A7mtfWu3Bq94OhPM5CAG/le/1fc175Y8u+eiHHP+5HA=; b=ITk3zaU2bhTrlscamtMp1oyhm56wSicuoIF7K9z6WTRlQwvwVksCAFqiqmYUagI0T6 I0wR0U+VrdpSPiWw95+KpoOc4E///34D9LUVm/msQxdO9OZ6loN+Q0rxG+G4Gz7lWmaV aj1psgpUq1Fu1RCxJWsZzKP4pXqLaN0+oyYYWZS0FDxKwmL87c9mOr9tFVM87k4KHBuZ B8CgauTgCo87cyw7kAJMaZKXELlebfaUsREY+T9lhSyWQ3Pk7ZA2nbyyzJjx7cLwD7d8 iUSbDYTehjcX7VEtqxijF2zEok8+QYnuEAN6JeAorJ6gkVZUslLEFDM5b1Eo7R1sT0og PY6g== 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=A7mtfWu3Bq94OhPM5CAG/le/1fc175Y8u+eiHHP+5HA=; b=Kw8CaECZQ9y4cSwKPOmzhH2e4ulLbbS2xGGURexYwfUY5XvGLQpLLanSjs89vyjtuG 4VV2lKriyrSjVmu2dGhqvPmaS5N3ivXqB8iZwHlw/irfXA2VcaEgKp+8YyINq928JRc3 rwx9TmvCR8jWroFbpYrVVW4LAI6wwxkqF4EJ0FqGfMqH6hc34+qZmDvZUTL+SzExI6xz Zezo40JYFwYDFo0Ojkg+dD7j7qCADHOtRP+hM5N5OCzY+PZ79MFbDfVRm5E9PY32oazf wlfp9mDR7tEwN5BS0M2IGgYdwfb3jNjcsu9SYLBuLDgQHSxruf9pTWkieH9GZjGxTaOS 97hA== X-Gm-Message-State: APf1xPDPsA68UDaHbV/mtdvdVHMUDFCn8Of/GHUBI2OOfg16I7svlcUE Zbhl7zVYAPgX6BOQSFEIcp1P53gE X-Google-Smtp-Source: AG47ELvH20bY6R+AduAPSPL1oRDIOieACDuBjoZ0dXW7kMsud1huIApHXqurfxc/Adqe+KoTkEdIag== X-Received: by 10.28.74.199 with SMTP id n68mr2233994wmi.83.1519922208004; Thu, 01 Mar 2018 08:36:48 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 17:36:18 +0100 Message-Id: <20180301163619.21072-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180301163619.21072-1-pbonzini@redhat.com> References: <20180301163619.21072-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::242 Subject: [Qemu-devel] [PATCH 7/8] 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 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 Message-Id: <1516279431-30424-6-git-send-email-pbonzini@redhat.com> 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 e713fe3d00..b72ed976fd 100644 --- a/block.c +++ b/block.c @@ -4211,7 +4211,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; @@ -4227,7 +4228,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; @@ -4257,8 +4258,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); @@ -4284,6 +4285,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 662f441997..10e2eef03c 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 ce6e195a41..68d822b6ff 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 b5410c5b00..33e260a381 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2119,7 +2119,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; @@ -2142,7 +2143,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); @@ -4383,7 +4386,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 d379c8c2f0..7da553035e 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1549,7 +1549,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; @@ -1558,13 +1559,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: "); @@ -1639,7 +1636,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 c7dd32e213..c1275c1ec9 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1093,8 +1093,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); @@ -1160,7 +1160,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 f80683ded2..10064d2a2f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -216,7 +216,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.14.3