From nobody Mon Nov 25 11:21:49 2024 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=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1715581985; cv=none; d=zohomail.com; s=zohoarc; b=ngoPDBbys13xD0UvkYFe+xpYH51HHv0zeLZybrfHcWc5qoUbL0L77R4dvyLIrr6DDg/35h18pPpEroZDQACp2BMvt02P6r99L4CgsRMDRwNCna+zMx0pwGIj6hFNLSZr9KXSUxDLP7mmHHyQKjbhS7f///yDUgONi0AfvO5skYw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715581985; 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=oPxzXi4hUhHjLonu4tB66NolHJvGgEnJxgj0ggWpcq0=; b=VmWzaSeEMyPcNb3znyejSmjoWup/bxaZidAMCsPIYAEMh45RXYJ460vXC/kZ+/5Hf6Z+ACYzyzyHMb7t7esgjXeNchbniTHr79F0jpDy/t/Bi7JAVvbsQBhBem/DfXThPP7OGXA71nEJnj73dseXHuMUhJjPeOVcJKc5eCVqKco= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1715581985569602.1154417680998; Sun, 12 May 2024 23:33:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6PEP-00079y-3o; Mon, 13 May 2024 02:32:17 -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 1s6PEL-00075N-8H; Mon, 13 May 2024 02:32:13 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s6PEI-0003wb-M9; Mon, 13 May 2024 02:32:12 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1s6PAR-000qpR-2r; Mon, 13 May 2024 08:31:57 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-Id:Date:Subject:From: Content-Type; bh=oPxzXi4hUhHjLonu4tB66NolHJvGgEnJxgj0ggWpcq0=; b=wZpFCyTuSl4s piCBdLSmbwied4LZymhUgnA/ulB/Zei/28KtJjMwjXXyzhTl//JhWMowgAHJlnsBP1JiQwh/N1984 V5gUhm6GNXllvcqwgMa4WqEtyfyFxss1sp19PKyYngI6xzH1lQ5smof6ns0tlXLMHnDkryLE+vWOP NPVwxDg/bM3whsUOp0pKaW3j5RWEEtA43bU8+ZSj9sW5+iSX+OAugy2SZ/sjLHz1wBxfCNC10IUrP XoQHuV9wj4CmFEwvBgIsE5qL895u/2oWTyOTfZn3/VOC+QtuGb9l55FSPKRng3xPlwGCQAidOB3Iq cf1kMAJuM6bhrd+6NK5Bjw==; From: Andrey Drobyshev To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, eblake@redhat.com, berto@igalia.com, jean-louis@dupond.be, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 08/11] qcow2: zeroize the entire cluster when there're no non-zero subclusters Date: Mon, 13 May 2024 09:32:00 +0300 Message-Id: <20240513063203.113911-9-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240513063203.113911-1-andrey.drobyshev@virtuozzo.com> References: <20240513063203.113911-1-andrey.drobyshev@virtuozzo.com> 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=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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 @virtuozzo.com) X-ZM-MESSAGEID: 1715581987609100003 Content-Type: text/plain; charset="utf-8" When zeroizing the last non-zero subclusters within single cluster, it makes sense to go zeroize the entire cluster and go down zero_in_l2_slice() path right away. That way we'd also update the corresponding refcount table. Signed-off-by: Andrey Drobyshev Reviewed-by: Hanna Czenczek Reviewed-by: Alexander Ivanov --- block/qcow2-cluster.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 475f167035..8d39e2f960 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -2221,7 +2221,7 @@ zero_in_l2_slice(BlockDriverState *bs, uint64_t offse= t, =20 static int coroutine_fn GRAPH_RDLOCK zero_l2_subclusters(BlockDriverState *bs, uint64_t offset, - unsigned nb_subclusters) + unsigned nb_subclusters, int flags) { BDRVQcow2State *s =3D bs->opaque; uint64_t new_l2_bitmap; @@ -2237,6 +2237,16 @@ zero_l2_subclusters(BlockDriverState *bs, uint64_t o= ffset, new_l2_bitmap |=3D QCOW_OFLAG_SUB_ZERO_RANGE(sc, sc + nb_subclusters); new_l2_bitmap &=3D ~QCOW_OFLAG_SUB_ALLOC_RANGE(sc, sc + nb_subclusters= ); =20 + /* + * If there're no non-zero subclusters left, we might as well zeroize + * the entire cluster. That way we'd also update the refcount table. + */ + if ((new_l2_bitmap & QCOW_L2_BITMAP_ALL_ZEROES) =3D=3D + QCOW_L2_BITMAP_ALL_ZEROES) { + return zero_in_l2_slice(bs, QEMU_ALIGN_DOWN(offset, s->cluster_siz= e), + 1, flags); + } + if (new_l2_bitmap !=3D scri.l2_bitmap) { set_l2_bitmap(s, scri.l2_slice, scri.l2_index, new_l2_bitmap); qcow2_cache_entry_mark_dirty(s->l2_table_cache, scri.l2_slice); @@ -2293,7 +2303,7 @@ int coroutine_fn qcow2_subcluster_zeroize(BlockDriver= State *bs, uint64_t offset, =20 if (head) { ret =3D zero_l2_subclusters(bs, offset - head, - size_to_subclusters(s, head)); + size_to_subclusters(s, head), flags); if (ret < 0) { goto fail; } @@ -2314,7 +2324,8 @@ int coroutine_fn qcow2_subcluster_zeroize(BlockDriver= State *bs, uint64_t offset, } =20 if (tail) { - ret =3D zero_l2_subclusters(bs, end_offset, size_to_subclusters(s,= tail)); + ret =3D zero_l2_subclusters(bs, end_offset, + size_to_subclusters(s, tail), flags); if (ret < 0) { goto fail; } --=20 2.39.3