From nobody Fri Dec 19 16:02:41 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 1518544865769916.4478155938275; Tue, 13 Feb 2018 10:01:05 -0800 (PST) Received: from localhost ([::1]:56747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1elet6-0007yD-S5 for importer@patchew.org; Tue, 13 Feb 2018 13:01:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ele2H-0003ad-O7 for qemu-devel@nongnu.org; Tue, 13 Feb 2018 12:06:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ele2E-0005nO-4a for qemu-devel@nongnu.org; Tue, 13 Feb 2018 12:06:28 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41068 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 1ele26-0005f8-0k; Tue, 13 Feb 2018 12:06:18 -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 A38C18163C60; Tue, 13 Feb 2018 17:06:17 +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 F3E9C10073CD; Tue, 13 Feb 2018 17:06:16 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 13 Feb 2018 18:05:19 +0100 Message-Id: <20180213170529.10858-46-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.8]); Tue, 13 Feb 2018 17:06:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 13 Feb 2018 17:06:17 +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 45/55] qcow2: Prepare expand_zero_clusters_in_l1() 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 expand_zero_clusters_in_l1() 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: c2ae9f31ed5b6e591477ad4654448badd1c89d73.1517840877.git.berto@i= galia.com Signed-off-by: Max Reitz --- block/qcow2-cluster.c | 187 ++++++++++++++++++++++++++--------------------= ---- 1 file changed, 96 insertions(+), 91 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 1041dcb6dd..ccb2944eda 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1904,118 +1904,123 @@ static int expand_zero_clusters_in_l1(BlockDriver= State *bs, uint64_t *l1_table, goto fail; } =20 - if (is_active_l1) { - /* get active L2 tables from cache */ - ret =3D qcow2_cache_get(bs, s->l2_table_cache, l2_offset, - (void **)&l2_table); - } else { - /* load inactive L2 tables from disk */ - ret =3D bdrv_read(bs->file, l2_offset / BDRV_SECTOR_SIZE, - (void *)l2_table, s->cluster_sectors); - } - if (ret < 0) { - goto fail; - } - - for (j =3D 0; j < s->l2_size; j++) { - uint64_t l2_entry =3D be64_to_cpu(l2_table[j]); - int64_t offset =3D l2_entry & L2E_OFFSET_MASK; - QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(l2_en= try); - - if (cluster_type !=3D QCOW2_CLUSTER_ZERO_PLAIN && - cluster_type !=3D QCOW2_CLUSTER_ZERO_ALLOC) { - continue; + { + if (is_active_l1) { + /* get active L2 tables from cache */ + ret =3D qcow2_cache_get(bs, s->l2_table_cache, l2_offset, + (void **)&l2_table); + } else { + /* load inactive L2 tables from disk */ + ret =3D bdrv_read(bs->file, l2_offset / BDRV_SECTOR_SIZE, + (void *)l2_table, s->cluster_sectors); + } + if (ret < 0) { + goto fail; } =20 - if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { - if (!bs->backing) { - /* not backed; therefore we can simply deallocate the - * cluster */ - l2_table[j] =3D 0; - l2_dirty =3D true; + for (j =3D 0; j < s->l2_size; j++) { + uint64_t l2_entry =3D be64_to_cpu(l2_table[j]); + int64_t offset =3D l2_entry & L2E_OFFSET_MASK; + QCow2ClusterType cluster_type =3D + qcow2_get_cluster_type(l2_entry); + + if (cluster_type !=3D QCOW2_CLUSTER_ZERO_PLAIN && + cluster_type !=3D QCOW2_CLUSTER_ZERO_ALLOC) { continue; } =20 - offset =3D qcow2_alloc_clusters(bs, s->cluster_size); - if (offset < 0) { - ret =3D offset; - goto fail; - } + if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { + if (!bs->backing) { + /* not backed; therefore we can simply deallocate = the + * cluster */ + l2_table[j] =3D 0; + l2_dirty =3D true; + continue; + } + + offset =3D qcow2_alloc_clusters(bs, s->cluster_size); + if (offset < 0) { + ret =3D offset; + goto fail; + } =20 - if (l2_refcount > 1) { - /* For shared L2 tables, set the refcount accordingly = (it is - * already 1 and needs to be l2_refcount) */ - ret =3D qcow2_update_cluster_refcount(bs, - offset >> s->cluster_bits, + if (l2_refcount > 1) { + /* For shared L2 tables, set the refcount accordin= gly + * (it is already 1 and needs to be l2_refcount) */ + ret =3D qcow2_update_cluster_refcount( + bs, offset >> s->cluster_bits, refcount_diff(1, l2_refcount), false, QCOW2_DISCARD_OTHER); - if (ret < 0) { - qcow2_free_clusters(bs, offset, s->cluster_size, - QCOW2_DISCARD_OTHER); - goto fail; + if (ret < 0) { + qcow2_free_clusters(bs, offset, s->cluster_siz= e, + QCOW2_DISCARD_OTHER); + goto fail; + } } } - } =20 - 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); - if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { - qcow2_free_clusters(bs, offset, s->cluster_size, - QCOW2_DISCARD_ALWAYS); + 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); + if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { + qcow2_free_clusters(bs, offset, s->cluster_size, + QCOW2_DISCARD_ALWAYS); + } + ret =3D -EIO; + goto fail; } - ret =3D -EIO; - goto fail; - } =20 - ret =3D qcow2_pre_write_overlap_check(bs, 0, offset, s->cluste= r_size); - if (ret < 0) { - if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { - qcow2_free_clusters(bs, offset, s->cluster_size, - QCOW2_DISCARD_ALWAYS); + ret =3D qcow2_pre_write_overlap_check(bs, 0, offset, + s->cluster_size); + if (ret < 0) { + if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { + qcow2_free_clusters(bs, offset, s->cluster_size, + QCOW2_DISCARD_ALWAYS); + } + goto fail; } - goto fail; - } =20 - ret =3D bdrv_pwrite_zeroes(bs->file, offset, s->cluster_size, = 0); - if (ret < 0) { - if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { - qcow2_free_clusters(bs, offset, s->cluster_size, - QCOW2_DISCARD_ALWAYS); + ret =3D bdrv_pwrite_zeroes(bs->file, offset, s->cluster_si= ze, 0); + if (ret < 0) { + if (cluster_type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN) { + qcow2_free_clusters(bs, offset, s->cluster_size, + QCOW2_DISCARD_ALWAYS); + } + goto fail; } - goto fail; - } =20 - if (l2_refcount =3D=3D 1) { - l2_table[j] =3D cpu_to_be64(offset | QCOW_OFLAG_COPIED); - } else { - l2_table[j] =3D cpu_to_be64(offset); + if (l2_refcount =3D=3D 1) { + l2_table[j] =3D cpu_to_be64(offset | QCOW_OFLAG_COPIED= ); + } else { + l2_table[j] =3D cpu_to_be64(offset); + } + l2_dirty =3D true; } - l2_dirty =3D true; - } =20 - if (is_active_l1) { - if (l2_dirty) { - qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table); - qcow2_cache_depends_on_flush(s->l2_table_cache); - } - qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); - } else { - if (l2_dirty) { - ret =3D qcow2_pre_write_overlap_check(bs, - QCOW2_OL_INACTIVE_L2 | QCOW2_OL_ACTIVE_L2, l2_offs= et, - s->cluster_size); - if (ret < 0) { - goto fail; + if (is_active_l1) { + if (l2_dirty) { + qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_tab= le); + qcow2_cache_depends_on_flush(s->l2_table_cache); } + qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); + } else { + if (l2_dirty) { + ret =3D qcow2_pre_write_overlap_check( + bs, QCOW2_OL_INACTIVE_L2 | QCOW2_OL_ACTIVE_L2, + l2_offset, s->cluster_size); + if (ret < 0) { + goto fail; + } =20 - ret =3D bdrv_write(bs->file, l2_offset / BDRV_SECTOR_SIZE, - (void *)l2_table, s->cluster_sectors); - if (ret < 0) { - goto fail; + ret =3D bdrv_write(bs->file, l2_offset / BDRV_SECTOR_S= IZE, + (void *)l2_table, s->cluster_sectors); + if (ret < 0) { + goto fail; + } } } } --=20 2.13.6