From nobody Wed Nov 5 09:04:39 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 1499706117500620.5388210097914; Mon, 10 Jul 2017 10:01:57 -0700 (PDT) Received: from localhost ([::1]:42119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUc4I-0006uE-Ip for importer@patchew.org; Mon, 10 Jul 2017 13:01:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUc19-00045V-MM 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 1dUc18-00031M-Qx for qemu-devel@nongnu.org; Mon, 10 Jul 2017 12:58:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUc18-000318-Ir for qemu-devel@nongnu.org; Mon, 10 Jul 2017 12:58:38 -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 5600EC05678E for ; Mon, 10 Jul 2017 16:58:37 +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 52DD95D6A6; Mon, 10 Jul 2017 16:58:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5600EC05678E Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5600EC05678E From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 18:58:26 +0200 Message-Id: <20170710165827.4250-5-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.32]); Mon, 10 Jul 2017 16:58:37 +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 4/5] qcow2: introduce qcow2_write_caches and qcow2_flush_caches 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" Avoid recursively taking s->lock during bdrv_check. Signed-off-by: Paolo Bonzini --- block/qcow2-refcount.c | 28 ++++++++++++++++++++++++++++ block/qcow2.c | 20 ++++---------------- block/qcow2.h | 2 ++ 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 7c06061aae..57bf91422b 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1046,7 +1046,35 @@ void qcow2_free_any_clusters(BlockDriverState *bs, u= int64_t l2_entry, } } =20 +int coroutine_fn qcow2_write_caches(BlockDriverState *bs) +{ + BDRVQcow2State *s =3D bs->opaque; + int ret; =20 + ret =3D qcow2_cache_write(bs, s->l2_table_cache); + if (ret < 0) { + return ret; + } + + if (qcow2_need_accurate_refcounts(s)) { + ret =3D qcow2_cache_write(bs, s->refcount_block_cache); + if (ret < 0) { + return ret; + } + } + + return 0; +} + +int coroutine_fn qcow2_flush_caches(BlockDriverState *bs) +{ + int ret =3D qcow2_write_caches(bs); + if (ret < 0) { + return ret; + } + + return bdrv_flush(bs->file->bs); +} =20 /*********************************************************/ /* snapshots and image creation */ diff --git a/block/qcow2.c b/block/qcow2.c index 4ff7e89009..9bab0d3012 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -278,7 +278,7 @@ static int qcow2_mark_clean(BlockDriverState *bs) =20 s->incompatible_features &=3D ~QCOW2_INCOMPAT_DIRTY; =20 - ret =3D bdrv_flush(bs); + ret =3D qcow2_flush_caches(bs); if (ret < 0) { return ret; } @@ -308,7 +308,7 @@ int qcow2_mark_consistent(BlockDriverState *bs) BDRVQcow2State *s =3D bs->opaque; =20 if (s->incompatible_features & QCOW2_INCOMPAT_CORRUPT) { - int ret =3D bdrv_flush(bs); + int ret =3D qcow2_flush_caches(bs); if (ret < 0) { return ret; } @@ -2968,22 +2968,10 @@ static coroutine_fn int qcow2_co_flush_to_os(BlockD= riverState *bs) int ret; =20 qemu_co_mutex_lock(&s->lock); - ret =3D qcow2_cache_write(bs, s->l2_table_cache); - if (ret < 0) { - qemu_co_mutex_unlock(&s->lock); - return ret; - } - - if (qcow2_need_accurate_refcounts(s)) { - ret =3D qcow2_cache_write(bs, s->refcount_block_cache); - if (ret < 0) { - qemu_co_mutex_unlock(&s->lock); - return ret; - } - } + ret =3D qcow2_write_caches(bs); qemu_co_mutex_unlock(&s->lock); =20 - return 0; + return ret; } =20 static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) diff --git a/block/qcow2.h b/block/qcow2.h index 87b15eb4aa..1d3fffd8ac 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -525,6 +525,8 @@ void qcow2_free_any_clusters(BlockDriverState *bs, uint= 64_t l2_entry, int qcow2_update_snapshot_refcount(BlockDriverState *bs, int64_t l1_table_offset, int l1_size, int addend); =20 +int coroutine_fn qcow2_flush_caches(BlockDriverState *bs); +int coroutine_fn qcow2_write_caches(BlockDriverState *bs); int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); =20 --=20 2.13.0