From nobody Tue Oct 28 02:10:44 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 1516188626615944.8983126164966; Wed, 17 Jan 2018 03:30:26 -0800 (PST) Received: from localhost ([::1]:56727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eblvF-0004J6-3P for importer@patchew.org; Wed, 17 Jan 2018 06:30:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eblqZ-0000Yx-FD for qemu-devel@nongnu.org; Wed, 17 Jan 2018 06:25:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eblqY-00040f-1A for qemu-devel@nongnu.org; Wed, 17 Jan 2018 06:25:35 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:33635) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eblqX-0003zj-OZ; Wed, 17 Jan 2018 06:25:33 -0500 Received: by mail-wr0-x241.google.com with SMTP id p6so18491235wrd.0; Wed, 17 Jan 2018 03:25:33 -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 w11sm2548965wrg.42.2018.01.17.03.25.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 03:25:31 -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=KFAcOlt9jyvQsTpdIKUBqZBnTYpdQU1dHf0tbMSY0ScMjBV9ixrE3lw0QOUzKMs1NN mzjynujU2FLibv5H4q+E5sxS9gGzGCo6Jjx9zZ2vHui1DgRGCI1ek6Va7cKJdGAJ6eCo P5TxzLKzzJyohPCsO7kkLLidC3Cfk4LZSE33NDrrm9WcKHJCA0nIiobzGi/clW9P3Ods OR4+K0Gl2YLoNFfj3z6ODV295KZxHwurEbN6SOzcTYVoe+dxb3HSkOdMLM2s7ZJP7gPv N4md2542ytObeucDuc/+mqWR+kevNMi9e+t5aHSwzT6pisQyXw8JBGgwi+Vtv6kZMQaX araw== 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=oRDXlRkVKT1fTDh6jwVVxnsRKKYOtQTRm+Uy/89AkAoVkvvSiv93YWn03JuqevnJoT Yl/0RX58bHZqDp5gZgtfVmiRIAiB0KtP38z0oo/4riAYT/If1+I0Pkt2KWBwL1W32Gx8 ai4YOVNSwHUebZLEPhCkrT800yodli1qoJhhIBRFWU9HbTjZHlfI9PacpH3kKBGV6LMq CWO2R00rAgoNf9N5hkSlNLxogeCiwyJLfNZyZdrpIek+H8y50jr08ooP5LQ5D2aM8vV9 ewIDdzGs82adC8DzuJ6rozYr8c0R2o6l37h/fqo+utlBxp+e32LUKGkdfm047Zjwn1x/ 9Igg== X-Gm-Message-State: AKwxytfiMglKXtH/ngWXsOY7+3Eqqxg/G0/RP+fd84EORSRkPz1AEJJ0 StZirBSQQEmlR77T+B5SolXxLMCA X-Google-Smtp-Source: ACJfBosOSq5JC2kdMWIJQyUBdyMFURtt2/TovdBiWES9WK4agclqB1ZCx5S1oZ2oLMCIUg5Sv3HL9g== X-Received: by 10.223.196.211 with SMTP id o19mr2137878wrf.201.1516188332436; Wed, 17 Jan 2018 03:25:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 17 Jan 2018 12:25:10 +0100 Message-Id: <1516188312-29612-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516188312-29612-1-git-send-email-pbonzini@redhat.com> References: <1516188312-29612-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::241 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