From nobody Sun Nov 24 20:46:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720908057179918.1986947087802; Sat, 13 Jul 2024 15:00:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSkmf-0002ru-96; Sat, 13 Jul 2024 18:00:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSkma-0002n8-MT; Sat, 13 Jul 2024 17:59:56 -0400 Received: from icts-p-cavuit-1.kulnet.kuleuven.be ([134.58.240.132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sSkmU-0007Fz-VJ; Sat, 13 Jul 2024 17:59:54 -0400 Received: from icts-p-ceifnet-smtps-0.kuleuven.be (icts-p-ceifnet-smtps.service.icts.svcd [IPv6:2a02:2c40:0:51:140:242:ac11:55]) by icts-p-cavuit-1.kulnet.kuleuven.be (Postfix) with ESMTP id 4234C2005B; Sat, 13 Jul 2024 23:59:39 +0200 (CEST) Received: from flutterbat.volkihar.be (236.58-240-81.adsl-dyn.isp.belgacom.be [81.240.58.236]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by icts-p-ceifnet-smtps-0.kuleuven.be (Postfix) with ESMTPSA id 2B13CD4EDEA16; Sat, 13 Jul 2024 23:59:39 +0200 (CEST) Received: by flutterbat.volkihar.be (Postfix, from userid 1000) id E8FEE71CB72; Sat, 13 Jul 2024 23:59:38 +0200 (CEST) X-KULeuven-Envelope-From: libvirt-e6954efa@volkihar.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: 4234C2005B.AF519 X-KULeuven-Information: Katholieke Universiteit Leuven BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: X-CAV-Cluster: smtps X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Vincent Vanlaer To: qemu-devel@nongnu.org Cc: John Snow , Vladimir Sementsov-Ogievskiy , Kevin Wolf , qemu-block@nongnu.org, Hanna Reitz , Vincent Vanlaer Subject: [PATCH v2 3/4] block: allow commit to unmap zero blocks Date: Sat, 13 Jul 2024 23:56:43 +0200 Message-ID: <20240713215644.742244-4-libvirt-e6954efa@volkihar.be> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240713215644.742244-1-libvirt-e6954efa@volkihar.be> References: <20240713215644.742244-1-libvirt-e6954efa@volkihar.be> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.58.240.132; envelope-from=libvirt-e6954efa@volkihar.be; helo=icts-p-cavuit-1.kulnet.kuleuven.be X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1720908059796116600 Content-Type: text/plain; charset="utf-8" Non-active block commits do not discard blocks only containing zeros, causing images to lose sparseness after the commit. This commit fixes that by writing zero blocks using blk_co_pwrite_zeroes rather than writing them out as any other arbitrary data. Signed-off-by: Vincent Vanlaer --- block/commit.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block/commit.c b/block/commit.c index fb54fc9560..6ce30927ac 100644 --- a/block/commit.c +++ b/block/commit.c @@ -130,6 +130,7 @@ static void commit_clean(Job *job) =20 typedef enum CommitMethod { COMMIT_METHOD_COPY, + COMMIT_METHOD_ZERO, COMMIT_METHOD_IGNORE, } CommitMethod; =20 @@ -185,6 +186,18 @@ static int coroutine_fn commit_run(Job *job, Error **e= rrp) if (ret >=3D 0) { if (!(ret & BDRV_BLOCK_ALLOCATED)) { commit_method =3D COMMIT_METHOD_IGNORE; + } else if (ret & BDRV_BLOCK_ZERO) { + int64_t target_offset; + int64_t target_bytes; + WITH_GRAPH_RDLOCK_GUARD() { + bdrv_round_to_subclusters(s->base_bs, offset, n, + &target_offset, &target_bytes); + } + + if (target_offset =3D=3D offset && + target_bytes =3D=3D n) { + commit_method =3D COMMIT_METHOD_ZERO; + } } =20 switch (commit_method) { @@ -198,6 +211,11 @@ static int coroutine_fn commit_run(Job *job, Error **e= rrp) } } break; + case COMMIT_METHOD_ZERO: + ret =3D blk_co_pwrite_zeroes(s->base, offset, n, + BDRV_REQ_MAY_UNMAP); + error_in_source =3D false; + break; case COMMIT_METHOD_IGNORE: break; default: @@ -216,6 +234,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) continue; } } + /* Publish progress */ job_progress_update(&s->common.job, n); =20 --=20 2.44.1