From nobody Fri Dec 19 15:46:13 2025 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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518544274599107.65097867463783; Tue, 13 Feb 2018 09:51:14 -0800 (PST) Received: from localhost ([::1]:56375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elejM-0007UZ-NU for importer@patchew.org; Tue, 13 Feb 2018 12:51:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ele2A-0003U3-Dc for qemu-devel@nongnu.org; Tue, 13 Feb 2018 12:06:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ele27-0005gh-Lg for qemu-devel@nongnu.org; Tue, 13 Feb 2018 12:06:22 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50796 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ele23-0005cr-95; Tue, 13 Feb 2018 12:06:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2EEFEB705; Tue, 13 Feb 2018 17:06:14 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-94.ams2.redhat.com [10.36.117.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E9BB10075C2; Tue, 13 Feb 2018 17:06:14 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 18:05:16 +0100 Message-Id: <20180213170529.10858-43-kwolf@redhat.com> In-Reply-To: <20180213170529.10858-1-kwolf@redhat.com> References: <20180213170529.10858-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 17:06:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 13 Feb 2018 17:06:14 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 42/55] 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alberto Garcia 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 Message-id: 8ffaa5e55bd51121f80e498f4045b64902a94293.1517840877.git.berto@i= galia.com Signed-off-by: Max Reitz --- block/qcow2-refcount.c | 144 +++++++++++++++++++++++++--------------------= ---- 1 file changed, 75 insertions(+), 69 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,90 +1236,96 @@ 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; - - entry =3D be64_to_cpu(l2_table[j]); - old_entry =3D entry; - entry &=3D ~QCOW_OFLAG_COPIED; - offset =3D entry & L2E_OFFSET_MASK; - - 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, + for (j =3D 0; j < s->l2_size; j++) { + uint64_t cluster_index; + uint64_t offset; + + entry =3D be64_to_cpu(l2_table[j]); + old_entry =3D entry; + entry &=3D ~QCOW_OFLAG_COPIED; + offset =3D entry & L2E_OFFSET_MASK; + + 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; + case QCOW2_CLUSTER_ZERO_PLAIN: + case QCOW2_CLUSTER_UNALLOCATED: + refcount =3D 0; + break; =20 - 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); } - } =20 - qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); + qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); + + } =20 if (addend !=3D 0) { ret =3D qcow2_update_cluster_refcount(bs, l2_offset >> --=20 2.13.6