From nobody Mon Feb 9 07:43:09 2026 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516980162767647.6009752868652; Fri, 26 Jan 2018 07:22:42 -0800 (PST) Received: from localhost ([::1]:33174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef5px-0000Mq-OK for importer@patchew.org; Fri, 26 Jan 2018 10:22:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef5nk-0007Pg-5S for qemu-devel@nongnu.org; Fri, 26 Jan 2018 10:20:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef5nf-0000lp-UR for qemu-devel@nongnu.org; Fri, 26 Jan 2018 10:20:23 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:54140) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ef5nX-0000j9-Sd; Fri, 26 Jan 2018 10:20:19 -0500 Received: from 88-114-101-230.elisa-laajakaista.fi ([88.114.101.230] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ef5Ux-0007gy-O4; Fri, 26 Jan 2018 16:00:59 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ef5UH-00087i-NJ; Fri, 26 Jan 2018 17:00:17 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=9pf3ogAqK5Ft6wS2orAsD4qLHkrBrJO6BJ5+TEty4zA=; b=Ilzpv3ltveqIl1mqh/DCNBoQ5tPRO+prt5lQGagGDfbKz6AKnl+Gxu/DThLfwIPEZo0al6pmx2G+XXUDxNWjf384L4REGH2hHqhQb/orScngwOfHMPp8Ri43CVzj7/DWz0/Sl8g1iKnRYfEe7XtBA6PD1pN916S/WZKbiK9ukMSI+eP/WPw8+BTYzPXZrO/EhchhOArooT/6KZSiQ70dcdX9lbpo+21hrAJFg+eB8T6BlYpYR6ZRmubfNTVHWiJS9UkXYi8GRjLhCJmiTUOz1TKvk9/AmZlCMsH5GY5dUP9KuMKZyuQQwxGDNOsdI3mfEk1tJO3K7iqx78+oxZW55w==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 16:59:54 +0200 Message-Id: <0c07738db12f556285f8db01d68c5d6b4304bde9.1516978645.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 27/39] qcow2: Update qcow2_update_snapshot_refcount() to support L2 slices 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: Kevin Wolf , Anton Nefedov , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , "Denis V . Lunev" 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" qcow2_update_snapshot_refcount() increases the refcount of all clusters of a given snapshot. In order to do that it needs to load all its L2 tables and iterate over their entries. Since we'll be loading L2 slices instead of full tables we need to add an extra loop that iterates over all slices of each L2 table. This function doesn't need any additional changes so apart from that this patch simply updates the variable name from l2_table to l2_slice. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index dfa28301c4..60b521cb89 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1183,17 +1183,20 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, int64_t l1_table_offset, int l1_size, int addend) { BDRVQcow2State *s =3D bs->opaque; - uint64_t *l1_table, *l2_table, l2_offset, entry, l1_size2, refcount; + uint64_t *l1_table, *l2_slice, l2_offset, entry, l1_size2, refcount; bool l1_allocated =3D false; int64_t old_entry, old_l2_offset; + unsigned slice, slice_size2, n_slices; int i, j, l1_modified =3D 0, nb_csectors; int ret; =20 assert(addend >=3D -1 && addend <=3D 1); =20 - l2_table =3D NULL; + l2_slice =3D NULL; l1_table =3D NULL; l1_size2 =3D l1_size * sizeof(uint64_t); + slice_size2 =3D s->l2_slice_size * sizeof(uint64_t); + n_slices =3D s->cluster_size / slice_size2; =20 s->cache_discards =3D true; =20 @@ -1236,19 +1239,19 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, goto fail; } =20 - { + for (slice =3D 0; slice < n_slices; slice++) { ret =3D qcow2_cache_get(bs, s->l2_table_cache, - l2_offset, - (void **) &l2_table); + l2_offset + slice * slice_size2, + (void **) &l2_slice); if (ret < 0) { goto fail; } =20 - for (j =3D 0; j < s->l2_size; j++) { + for (j =3D 0; j < s->l2_slice_size; j++) { uint64_t cluster_index; uint64_t offset; =20 - entry =3D be64_to_cpu(l2_table[j]); + entry =3D be64_to_cpu(l2_slice[j]); old_entry =3D entry; entry &=3D ~QCOW_OFLAG_COPIED; offset =3D entry & L2E_OFFSET_MASK; @@ -1273,12 +1276,13 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, case QCOW2_CLUSTER_NORMAL: case QCOW2_CLUSTER_ZERO_ALLOC: if (offset_into_cluster(s, offset)) { + int l2_index =3D slice * s->l2_slice_size + j; qcow2_signal_corruption( bs, true, -1, -1, "Cluster " "allocation offset %#" PRIx64 " unaligned (L2 offset: %#" PRIx64 ", L2 index: %#x)", - offset, l2_offset, j); + offset, l2_offset, l2_index); ret =3D -EIO; goto fail; } @@ -1317,14 +1321,13 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, qcow2_cache_set_dependency(bs, s->l2_table_cac= he, s->refcount_block_c= ache); } - l2_table[j] =3D cpu_to_be64(entry); + l2_slice[j] =3D cpu_to_be64(entry); qcow2_cache_entry_mark_dirty(s->l2_table_cache, - l2_table); + l2_slice); } } =20 - qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); - + qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); } =20 if (addend !=3D 0) { @@ -1352,8 +1355,8 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, =20 ret =3D bdrv_flush(bs); fail: - if (l2_table) { - qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); + if (l2_slice) { + qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); } =20 s->cache_discards =3D false; --=20 2.11.0