From nobody Fri Oct 24 22:13:26 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 1519922493511151.2124969021329; Thu, 1 Mar 2018 08:41:33 -0800 (PST) Received: from localhost ([::1]:58009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erRGu-0001sV-Fn for importer@patchew.org; Thu, 01 Mar 2018 11:41:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erRC7-0006YG-UA for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:36:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erRC6-0002l0-Ju for qemu-devel@nongnu.org; Thu, 01 Mar 2018 11:36:35 -0500 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:34901) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1erRC6-0002jW-Ci; Thu, 01 Mar 2018 11:36:34 -0500 Received: by mail-wr0-x244.google.com with SMTP id l43so7256825wrc.2; Thu, 01 Mar 2018 08:36:34 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Mar 2018 08:36:32 -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=xf1G+oSOpKjXF12itEa1eNn8xO93J7w6XWhz+lITvLg=; b=ocCSwymb0j3gL+Nvv/mQkzKWDyvZC88T0KqqmNIlvfyqTImp74Mr2ohvcD3hEcToZ4 JRd1j4q1HwNIxYlWEKQGgwGao63uW/gyE5uYZbbJsm0PT6wR/x91Z9ATuwzC80EGyLwp rzH1Jd0IkEAM37u+3QJ83DFg+osq7gYbxTu/svCJ7KyxtVoYiJUvVFi0KnT4FVwTVnbl hpdUya4JOYZTaiAO4U7mvYnnDr7k1Tszx033+exGIm0G6xvLrmZ1uIzpp/8PVPikxOhh yxJNCnFOWgtsAmP1NjAF5JIgG6eCS1ObpYpJ1o6G7DZ8bwOOVDYcmKf5hjTRO6/rvWDW bdpw== 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=xf1G+oSOpKjXF12itEa1eNn8xO93J7w6XWhz+lITvLg=; b=r9+8itXzasxcxcSjPiW4wsffRWpP35wPU2Yg1bNCIuhrmi+7DBKxfwbU8QUVAWZFO6 4mkbDwuQ5kBZJYv1iMrG8vUIO7aBR4MEuONMJNLbmUT0/B01iOsc52A4tVypKbNQnOfc aIo8F7aRshRYcjPWYyDUF1fPR8izOkBjLXHyt75rcW5IPUPFexj3pXa8r7+IgY4jdeTm JfuyIkpybfN4ObbPuGQVeID2XoQbI/TbFVWZ9GnCN2mtQftYsEFp8MLadW1KNuFcTvvy oQHobSwwGHFi76aFWhjB2pDlvoyoFpPnXdRIAAw/M9JvF0sTEWH42EbtUwJ2V6RWsLZF e0UQ== X-Gm-Message-State: APf1xPDoCfGx/BhSBYIZhfGBO7UrzjME/RgxZnyfifSCBPoHkZj0s4so cYcyT1JdZKNdVOuD7Zcg/gpcw0UQ X-Google-Smtp-Source: AG47ELscojqqtDTpnoNJTs+uuXWi5yIcmm6aZ/XPSs2QtNPEYi9uO9am7qwvpJxhkl037E4ZIy6Vdg== X-Received: by 10.223.158.196 with SMTP id b4mr2291880wrf.112.1519922192926; Thu, 01 Mar 2018 08:36:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 17:36:14 +0100 Message-Id: <20180301163619.21072-4-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:c0c::244 Subject: [Qemu-devel] [PATCH 3/8] 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 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" 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 Reviewed-by: Eric Blake --- 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 92701ab7af..6482ade7fa 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 24edbb431b..4c216ecd63 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -502,7 +502,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; } @@ -532,7 +532,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; } @@ -3624,22 +3624,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 46c8cf44ec..25b50f8c01 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 2.14.3