From nobody Wed Dec 17 05:42:07 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; 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 1520612645507962.973360630921; Fri, 9 Mar 2018 08:24:05 -0800 (PST) Received: from localhost ([::1]:46288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euKoL-0003mi-RT for importer@patchew.org; Fri, 09 Mar 2018 11:24:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euKkk-0000ob-35 for qemu-devel@nongnu.org; Fri, 09 Mar 2018 11:20:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euKkh-0006Vg-95 for qemu-devel@nongnu.org; Fri, 09 Mar 2018 11:20:17 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42772 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1euKkY-0006R1-8d; Fri, 09 Mar 2018 11:20:06 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6314406804F; Fri, 9 Mar 2018 16:20:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E6A9215CDAC; Fri, 9 Mar 2018 16:20:05 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 17:18:39 +0100 Message-Id: <20180309161933.8168-3-kwolf@redhat.com> In-Reply-To: <20180309161933.8168-1-kwolf@redhat.com> References: <20180309161933.8168-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 09 Mar 2018 16:20:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 09 Mar 2018 16:20:05 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 02/56] 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, qemu-devel@nongnu.org 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" From: Paolo Bonzini They will be used to avoid recursively taking s->lock during bdrv_open or bdrv_check. Signed-off-by: Paolo Bonzini Message-Id: <1516279431-30424-7-git-send-email-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- block/qcow2.h | 2 ++ block/qcow2-refcount.c | 28 ++++++++++++++++++++++++++++ block/qcow2.c | 20 ++++---------------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 1a84cc77b0..965846f7af 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -576,6 +576,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 diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 126cca3276..2f7e710fa6 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1171,7 +1171,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 071dc4d608..ee040a49cd 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -500,7 +500,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; } @@ -530,7 +530,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; } @@ -3647,22 +3647,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 BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *i= n_bs, --=20 2.13.6