From nobody Mon Nov 25 11:52:41 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=1715582057; cv=none; d=zohomail.com; s=zohoarc; b=TDkcPArZZ9mHM+zTyQgnjP7GUC/ZfvRy3N1lGMeEYOpaF8FdzJ5QG5SD+7lHSX7NWj+eiwaT4CJomEyZ38+Eqia8q49B0SVxK5DoOvzqi5pDvnNTPy4FlLS3LPfVfnsPoqWPcyHCPb1MMq7cFdkeEwFtYXPvepXrq58K/9Oozxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1715582057; 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=jNFNcCdQsEhrr/inHNaL9PAgwDbEWRLGawhpTFzfYH0=; b=O+kG7HjWiBqSnbVyLoF5dulO39ZhkECSFG0cnfpDiSd2CklmXZo1liHx9WpdHrL8I8JX8xmxtPogxaIT9Y8wSz+57p7qGQXPqYflqvFG0g6wD4GSzcik83IMIJr7F1oW8zKHt5xpEOHolf6BqWGqiyRJhO8UPz1OgUMUrcKB1+Q= 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 1715582057239941.166113102574; Sun, 12 May 2024 23:34:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6PF2-00085R-6N; Mon, 13 May 2024 02:32:58 -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 1s6PEr-0007xY-HM; Mon, 13 May 2024 02:32:45 -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 1s6PEp-000487-Sg; Mon, 13 May 2024 02:32:45 -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 1s6PAS-000qpR-00; 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=jNFNcCdQsEhrr/inHNaL9PAgwDbEWRLGawhpTFzfYH0=; b=w3JJu9fLUMai E8XtXn/Fw2JVmMunx47gwCiNJ9ss+gCFQsOW33lUeykJDLvE4oORcL7JoIhRBOp00NM8seq3T0DYF q5MWo03YdnRUNvi2VBBrISmu9NSnS8ebgIS6URJxqL/tLpKpMQF4gA8rne47Y7HsGAw6IF80KlpcF JViTLVhnYhDs4+3aT82TzItcv3HO+4JXcj+Pq9FOMbIXs9/7ZcQLpljh7rroImeTHlXK66mZrmIlr 6BwI2LhB8xrGcGlOZ4Ji58dMAlf+6xnDD/cg/IGiZKFHUZSdkspwKVOOHBTyFilI+pAURTmuEh/q7 yoI/NLuCMJhZY6LYoQSKJQ==; 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 10/11] qcow2: zero_l2_subclusters: fall through to discard operation when requested Date: Mon, 13 May 2024 09:32:02 +0300 Message-Id: <20240513063203.113911-11-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: 1715582057878100003 Content-Type: text/plain; charset="utf-8" When zeroizing subclusters within single cluster, detect usage of the BDRV_REQ_MAY_UNMAP flag and fall through to the subcluster-based discard operation, much like it's done with the cluster-based discards. That way subcluster-aligned operations "qemu-io -c 'write -z -u ...'" will lead to actual unmap. Signed-off-by: Andrey Drobyshev Reviewed-by: Alexander Ivanov --- block/qcow2-cluster.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 3c134a7e80..53e04eff93 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -2107,15 +2107,16 @@ discard_in_l2_slice(BlockDriverState *bs, uint64_t = offset, uint64_t nb_clusters, =20 static int coroutine_fn GRAPH_RDLOCK discard_l2_subclusters(BlockDriverState *bs, uint64_t offset, - uint64_t nb_subclusters, - enum qcow2_discard_type type, - bool full_discard) + uint64_t nb_subclusters, enum qcow2_discard_type ty= pe, + bool full_discard, bool uncond_zeroize) { BDRVQcow2State *s =3D bs->opaque; uint64_t new_l2_bitmap, bitmap_alloc_mask, bitmap_zero_mask; int ret, sc =3D offset_to_sc_index(s, offset); g_auto(SubClusterRangeInfo) scri =3D { 0 }; =20 + assert(!(full_discard && uncond_zeroize)); + ret =3D get_sc_range_info(bs, offset, nb_subclusters, &scri); if (ret < 0) { return ret; @@ -2140,7 +2141,8 @@ discard_l2_subclusters(BlockDriverState *bs, uint64_t= offset, */ if (full_discard) { new_l2_bitmap &=3D ~bitmap_zero_mask; - } else if (bs->backing || scri.l2_bitmap & bitmap_alloc_mask) { + } else if (uncond_zeroize || bs->backing || + scri.l2_bitmap & bitmap_alloc_mask) { new_l2_bitmap |=3D bitmap_zero_mask; } =20 @@ -2197,7 +2199,7 @@ int qcow2_subcluster_discard(BlockDriverState *bs, ui= nt64_t offset, if (head) { ret =3D discard_l2_subclusters(bs, offset - head, size_to_subclusters(s, head), type, - full_discard); + full_discard, false); if (ret < 0) { goto fail; } @@ -2221,7 +2223,7 @@ int qcow2_subcluster_discard(BlockDriverState *bs, ui= nt64_t offset, if (tail) { ret =3D discard_l2_subclusters(bs, end_offset, size_to_subclusters(s, tail), type, - full_discard); + full_discard, false); if (ret < 0) { goto fail; } @@ -2318,6 +2320,18 @@ zero_l2_subclusters(BlockDriverState *bs, uint64_t o= ffset, int ret, sc =3D offset_to_sc_index(s, offset); g_auto(SubClusterRangeInfo) scri =3D { 0 }; =20 + /* + * If the request allows discarding subclusters we go down the discard + * path regardless of their allocation status. After the discard + * operation with full_discard=3Dfalse subclusters are going to be rea= d as + * zeroes anyway. But we make sure that subclusters are explicitly + * zeroed anyway with uncond_zeroize=3Dtrue. + */ + if (flags & BDRV_REQ_MAY_UNMAP) { + return discard_l2_subclusters(bs, offset, nb_subclusters, + QCOW2_DISCARD_REQUEST, false, true); + } + ret =3D get_sc_range_info(bs, offset, nb_subclusters, &scri); if (ret < 0) { return ret; --=20 2.39.3