From nobody Sun Oct 26 00:02: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 1516280091078311.5888781307044; Thu, 18 Jan 2018 04:54:51 -0800 (PST) Received: from localhost ([::1]:57112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ec9iU-0001r5-0T for importer@patchew.org; Thu, 18 Jan 2018 07:54:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ec9Y6-0001L6-P7 for qemu-devel@nongnu.org; Thu, 18 Jan 2018 07:44:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ec9Y2-0004aC-SI for qemu-devel@nongnu.org; Thu, 18 Jan 2018 07:44:06 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:36150) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ec9Y2-0004ZW-ME; Thu, 18 Jan 2018 07:44:02 -0500 Received: by mail-wr0-x243.google.com with SMTP id d9so22403142wre.3; Thu, 18 Jan 2018 04:44:02 -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 t51sm13006472wrc.21.2018.01.18.04.44.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 04:44:00 -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=QmURZG1y+gTB/C9JXVxccmDWFWmU2/nD/YEkTymeXgk=; b=Jv6Y4dhqjZMjDiuIV3Ei+jb7asYw9jhJ9cpizvBu0sECxgJ18SZYnA22S3b5j4sNKC IUUqIEzenfCromdKaQ8X9DXj6XWiqxSNbSL8v1M1RPF7wzo0IcF89ZfBvMUfp1f0kl0I X9roIqIjFa8YKDtWxAFV+j2Vd59veFtPp1+cgiyfhMUmhb1ULbWTq+P/t24qD6sLHkiz YEzSqW/fKS2TuaGTJyvzb1US9qd0WF+rY3X/0cbJp2IXHA6EeLUMAnkOb/p3fRA05sg5 63AQfeqtCUdWyOTnufcbKo1rZeZa6wNMdTrLBQJ8WIVz+WtcNx1xgRr5DU97JekACdtX 06IA== 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=QmURZG1y+gTB/C9JXVxccmDWFWmU2/nD/YEkTymeXgk=; b=tvlFTqWnO21vs2ZzwpPekLcLl1P+sfNQLRR6KNSyNz8QgJbi1jFH7PRJPhGN5SLJZf ecjv426zMvwk8Cf585oLh586tjRgzA1DC9DN0ca9NRs0EUdPjotuIAC6OEkZX/1cfwkH Rfx75jH8fndeUfsHg7EOhKZMxEYKP0cMGQt8e6Cem5m22w9P7l89z0Tk5ztJVxdzrv2x YzUQXZQ+mw1C02T1zuw7aYXgbGMaBUKVUO110H+yPNGHO/D/VC+jDUAgccaRKs1nj1LR rMLS2JHXIM7N1KutVhyCJbFUbxzhlMG5S2h+hx9I0yLmPgJPtmBRQOBMXSTEDupmf5wH 0hsQ== X-Gm-Message-State: AKwxytdu5Clw5g3HwQH05qHm18FlqJJNUo9IHk5qojkbBOK+EAjehPJ3 +tScHPcaFKEXhOlzmXbIFe6mL//R X-Google-Smtp-Source: ACJfBosqRiavjNEKRw8t/7ErHhNAk8G8w/VEOz4yDKOonEeowv9aqDzWfyRrcPbp3cvHgypm6ZCwqQ== X-Received: by 10.223.173.165 with SMTP id w34mr6187622wrc.75.1516279441263; Thu, 18 Jan 2018 04:44:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Jan 2018 13:43:50 +0100 Message-Id: <1516279431-30424-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516279431-30424-1-git-send-email-pbonzini@redhat.com> References: <1516279431-30424-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::243 Subject: [Qemu-devel] [PATCH 6/7] 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-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" 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 3de1ab5..e0d9dc1 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1172,7 +1172,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 e886a44..4a10b55 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -492,7 +492,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; } @@ -522,7 +522,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; } @@ -3653,22 +3653,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, diff --git a/block/qcow2.h b/block/qcow2.h index 46c8cf4..25b50f8 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -570,6 +570,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 1.8.3.1