From nobody Sat Nov 15 23:41:49 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1745926589; cv=none; d=zohomail.com; s=zohoarc; b=XCztIwIp5sAEh1b0w/CDVCEfhQfPXK6RJhH8cYMyVpdZZMj+FrFQA5aplmbT2DWLwCh9PMUlWmQDwm5SZqRxilF9KDd4N9Jt7aHD6NfmjGTzAEGbO/bw0kC3I8YzCoJtraaeLkh/yHnOEz+reS1etB9mw9gFI465bU3qAO6VQCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745926589; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=klMsBhm4nQV+bJbcH/oarfEWSHGxoD1YQoQrrYEdnVM=; b=Hf2rn4uojs8otLVKIhl/h1d2h3GsA3M+/iOusGCct6wKUNqyGtECa/hD3WiL96QgUvt8oVNCvKMvL+cIUbzE0b1hvGs6K+05nIjpRVcWRRqe5rH1nhQQq83hx3h+eODa/rH0PjthGMwKOl7YMOHN5qpvdrkXc5fy/QDhQYQsND0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1745926589196799.0826734522657; Tue, 29 Apr 2025 04:36:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u9jDv-0007DA-6n; Tue, 29 Apr 2025 07:34:03 -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 1u9jDj-0006wy-QV; Tue, 29 Apr 2025 07:33:52 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u9jDe-0008Fa-Du; Tue, 29 Apr 2025 07:33:51 -0400 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:cca4:0:640:432b:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 2A4B461323; Tue, 29 Apr 2025 14:33:42 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b423::1:3a]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id bXTAnY0Fe0U0-3PGDmJAX; Tue, 29 Apr 2025 14:33:41 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1745926421; bh=klMsBhm4nQV+bJbcH/oarfEWSHGxoD1YQoQrrYEdnVM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=JsnQkAtcfsMB/5tBEjPhnSGYbtymjzCEF7cUWoYf3kAyxaiCurqs0iVV7F7CUHkgz WkLWjerGO2nGebNOK244WwQuudi0y4KbYE1iM7QVmLN1m2FOa75kru6whhm2Pk1Pea nr9x4nG7ZwTnsjTFpmEMY0/RsbwA34jkkMQkVXBA= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Vincent Vanlaer , Vladimir Sementsov-Ogievskiy Subject: [PULL 4/8] block: allow commit to unmap zero blocks Date: Tue, 29 Apr 2025 14:33:29 +0300 Message-ID: <20250429113335.423535-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250429113335.423535-1-vsementsov@yandex-team.ru> References: <20250429113335.423535-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=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-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1745926591124019000 Content-Type: text/plain; charset="utf-8" From: Vincent Vanlaer 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 Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20241026163010.2865002-5-libvirt-e6954efa@volkihar.be> Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/commit.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/block/commit.c b/block/commit.c index 0fbf684728..4938714e0f 100644 --- a/block/commit.c +++ b/block/commit.c @@ -149,19 +149,39 @@ static int commit_iteration(CommitBlockJob *s, int64_= t offset, } =20 if (ret & BDRV_BLOCK_ALLOCATED) { - assert(bytes < SIZE_MAX); + if (ret & BDRV_BLOCK_ZERO) { + /* + * If the top (sub)clusters are smaller than the base + * (sub)clusters, this will not unmap unless the underlying de= vice + * does some tracking of these requests. Ideally, we would find + * the maximal extent of the zero clusters. + */ + ret =3D blk_co_pwrite_zeroes(s->base, offset, bytes, + BDRV_REQ_MAY_UNMAP); + if (ret < 0) { + error_in_source =3D false; + goto fail; + } + } else { + assert(bytes < SIZE_MAX); =20 - ret =3D blk_co_pread(s->top, offset, bytes, buf, 0); - if (ret < 0) { - goto fail; - } + ret =3D blk_co_pread(s->top, offset, bytes, buf, 0); + if (ret < 0) { + goto fail; + } =20 - ret =3D blk_co_pwrite(s->base, offset, bytes, buf, 0); - if (ret < 0) { - error_in_source =3D false; - goto fail; + ret =3D blk_co_pwrite(s->base, offset, bytes, buf, 0); + if (ret < 0) { + error_in_source =3D false; + goto fail; + } } =20 + /* + * Whether zeroes actually end up on disk depends on the details of + * the underlying driver. Therefore, this might rate limit more th= an + * is necessary. + */ block_job_ratelimit_processed_bytes(&s->common, bytes); } =20 --=20 2.48.1