From nobody Mon Feb 9 02:38:37 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 1516984781531197.38578078918306; Fri, 26 Jan 2018 08:39:41 -0800 (PST) Received: from localhost ([::1]:37269 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef72S-0007Qp-Lt for importer@patchew.org; Fri, 26 Jan 2018 11:39:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef6r4-0007Kl-3Y for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:27:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef6qz-0004Uy-3v for qemu-devel@nongnu.org; Fri, 26 Jan 2018 11:27:54 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:38620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ef6qy-0004SI-Nq; Fri, 26 Jan 2018 11:27:49 -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-0007gw-Pn; Fri, 26 Jan 2018 16:00:59 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ef5UH-00087f-L6; 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=/WTlBAj1n2xIiGdTQL46C8+6E7SApl7d9DlhkkezOhQ=; b=P3iAStxXZrq4Eery4ROjiX6s0oFy9BZw/lDAe8Xjw1d4K31U6oYHeEGEBBzg1NMnjPoZJUWrr9booLiB3YtjsU6YG5UtwR4UHvszlFuiwvdgHJ3nLdOilSl1koMxc1tOJuK4ug2Lqd9vBRYDzYsyFYeKt0fpwSPPkm7voLDMtBkVHRN0N/iG/4ov8cfE2P7XKGPrUQ7hgZ+sH5SXseGc66NvfZmlSpSsNtVUX5zc4L3wC5zGU9hLll98DMAkqN1enfXVpL4DX6w9JGov8uA+ZXTFNMY6+2ZQaH7Wr6TmAye2BpdVaDnDDRpzViTZlTgMKPXTVZRL1H/4k7A4qNov/g==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 16:59:53 +0200 Message-Id: <0c81220cf2141a5b720629fb6eaff04f833e77a4.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 26/39] qcow2: Prepare qcow2_update_snapshot_refcount() for adding L2 slice support 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" Adding support for L2 slices to qcow2_update_snapshot_refcount() needs (among other things) an extra loop that iterates over all slices of each L2 table. Putting all changes in one patch would make it hard to read because all semantic changes would be mixed with pure indentation changes. To make things easier this patch simply creates a new block and changes the indentation of all lines of code inside it. Thus, all modifications in this patch are cosmetic. There are no semantic changes and no variables are renamed yet. The next patch will take care of that. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 140 ++++++++++++++++++++++++++-------------------= ---- 1 file changed, 73 insertions(+), 67 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 9df380d52c..dfa28301c4 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1236,91 +1236,97 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, goto fail; } =20 - ret =3D qcow2_cache_get(bs, s->l2_table_cache, l2_offset, - (void**) &l2_table); - if (ret < 0) { - goto fail; - } + { + ret =3D qcow2_cache_get(bs, s->l2_table_cache, + l2_offset, + (void **) &l2_table); + if (ret < 0) { + goto fail; + } =20 - for (j =3D 0; j < s->l2_size; j++) { - uint64_t cluster_index; - uint64_t offset; + for (j =3D 0; j < s->l2_size; j++) { + uint64_t cluster_index; + uint64_t offset; =20 - entry =3D be64_to_cpu(l2_table[j]); - old_entry =3D entry; - entry &=3D ~QCOW_OFLAG_COPIED; - offset =3D entry & L2E_OFFSET_MASK; + entry =3D be64_to_cpu(l2_table[j]); + old_entry =3D entry; + entry &=3D ~QCOW_OFLAG_COPIED; + offset =3D entry & L2E_OFFSET_MASK; =20 - switch (qcow2_get_cluster_type(entry)) { - case QCOW2_CLUSTER_COMPRESSED: - nb_csectors =3D ((entry >> s->csize_shift) & - s->csize_mask) + 1; - if (addend !=3D 0) { - ret =3D update_refcount(bs, - (entry & s->cluster_offset_mask) & ~511, + switch (qcow2_get_cluster_type(entry)) { + case QCOW2_CLUSTER_COMPRESSED: + nb_csectors =3D ((entry >> s->csize_shift) & + s->csize_mask) + 1; + if (addend !=3D 0) { + ret =3D update_refcount( + bs, (entry & s->cluster_offset_mask) & ~51= 1, nb_csectors * 512, abs(addend), addend < 0, QCOW2_DISCARD_SNAPSHOT); - if (ret < 0) { + if (ret < 0) { + goto fail; + } + } + /* compressed clusters are never modified */ + refcount =3D 2; + break; + + case QCOW2_CLUSTER_NORMAL: + case QCOW2_CLUSTER_ZERO_ALLOC: + if (offset_into_cluster(s, offset)) { + qcow2_signal_corruption( + bs, true, -1, -1, "Cluster " + "allocation offset %#" PRIx64 + " unaligned (L2 offset: %#" + PRIx64 ", L2 index: %#x)", + offset, l2_offset, j); + ret =3D -EIO; goto fail; } - } - /* compressed clusters are never modified */ - refcount =3D 2; - break; - - case QCOW2_CLUSTER_NORMAL: - case QCOW2_CLUSTER_ZERO_ALLOC: - if (offset_into_cluster(s, offset)) { - qcow2_signal_corruption(bs, true, -1, -1, "Cluster= " - "allocation offset %#" PRI= x64 - " unaligned (L2 offset: %#" - PRIx64 ", L2 index: %#x)", - offset, l2_offset, j); - ret =3D -EIO; - goto fail; - } =20 - cluster_index =3D offset >> s->cluster_bits; - assert(cluster_index); - if (addend !=3D 0) { - ret =3D qcow2_update_cluster_refcount(bs, - cluster_index, abs(addend), addend < 0, - QCOW2_DISCARD_SNAPSHOT); + cluster_index =3D offset >> s->cluster_bits; + assert(cluster_index); + if (addend !=3D 0) { + ret =3D qcow2_update_cluster_refcount( + bs, cluster_index, abs(addend), addend < 0, + QCOW2_DISCARD_SNAPSHOT); + if (ret < 0) { + goto fail; + } + } + + ret =3D qcow2_get_refcount(bs, cluster_index, &ref= count); if (ret < 0) { goto fail; } - } + break; =20 - ret =3D qcow2_get_refcount(bs, cluster_index, &refcoun= t); - if (ret < 0) { - goto fail; - } - break; + case QCOW2_CLUSTER_ZERO_PLAIN: + case QCOW2_CLUSTER_UNALLOCATED: + refcount =3D 0; + break; =20 - case QCOW2_CLUSTER_ZERO_PLAIN: - case QCOW2_CLUSTER_UNALLOCATED: - refcount =3D 0; - break; - - default: - abort(); - } + default: + abort(); + } =20 - if (refcount =3D=3D 1) { - entry |=3D QCOW_OFLAG_COPIED; - } - if (entry !=3D old_entry) { - if (addend > 0) { - qcow2_cache_set_dependency(bs, s->l2_table_cache, - s->refcount_block_cache); + if (refcount =3D=3D 1) { + entry |=3D QCOW_OFLAG_COPIED; + } + if (entry !=3D old_entry) { + if (addend > 0) { + qcow2_cache_set_dependency(bs, s->l2_table_cac= he, + s->refcount_block_c= ache); + } + l2_table[j] =3D cpu_to_be64(entry); + qcow2_cache_entry_mark_dirty(s->l2_table_cache, + l2_table); } - l2_table[j] =3D cpu_to_be64(entry); - qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_tab= le); } + + qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); + } =20 - qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); - if (addend !=3D 0) { ret =3D qcow2_update_cluster_refcount(bs, l2_offset >> s->cluster_bits, --=20 2.11.0