From nobody Sun Feb 8 22:18:29 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 1517842388889853.2471390751117; Mon, 5 Feb 2018 06:53:08 -0800 (PST) Received: from localhost ([::1]:51178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eii8q-0001tp-0Y for importer@patchew.org; Mon, 05 Feb 2018 09:53:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eihri-0002je-6t for qemu-devel@nongnu.org; Mon, 05 Feb 2018 09:35:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eihrc-0006TQ-84 for qemu-devel@nongnu.org; Mon, 05 Feb 2018 09:35:26 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:48493) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eihrb-00069s-UO; Mon, 05 Feb 2018 09:35:20 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1eihr4-0001ru-VH; Mon, 05 Feb 2018 15:34:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1eihqJ-0008Ok-Hi; Mon, 05 Feb 2018 16:33:59 +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=TtV4yWuhgTQc2+uYVOfVGliKIb9Fo4KBwki+O6hlG8E=; b=PyEDByUyorTz2qyWuVod85BBwK8q8GMZyTNpjjyYCMszGFead6jbKFQw+ExWAWp8noU1Ho0PbyWdN7q6E6baIjzbWDPiPnG5vN9ylArCFWKME2sCFtiQbbnaWvWGZseDO8ElNCS3TZcqqhZbpoT5zdnejuydByscE1uEdJDvmePNB36W5FRX9jZI88DASTnDzvpt9w0V0HIugbI3z9k4sQGENLrNIrgtW8D/IvMkySUO3P68BBDVhawHGi+nVzU13LLsr5f6tff9gL704XKGpPkWJdgqvX7HMnXmcvtMQM+kEGokWbD8b56rIVBXV6amg60x4lyHNSTiZlOfNP/8DA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 16:33:20 +0200 Message-Id: <6b602260acb33da56ed6af9611731cb7acd110eb.1517840877.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 v4 20/39] qcow2: Update qcow2_get_cluster_offset() 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_get_cluster_offset() checks how many contiguous bytes are available at a given offset. The returned number of bytes is limited by the amount that can be addressed without having to load more than one L2 table. Since we'll be loading L2 slices instead of full tables this patch changes the limit accordingly using the size of the L2 slice for the calculations instead of the full table size. One consequence of this is that with small L2 slices operations such as 'qemu-img map' will need to iterate in more steps because each qcow2_get_cluster_offset() call will potentially return a smaller number. However the code is already prepared for that so this doesn't break semantics. The l2_table variable is also renamed to l2_slice to reflect this, and offset_to_l2_index() is replaced with offset_to_l2_slice_index(). Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index de22685b21..9cd9cfff67 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -530,8 +530,8 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, { BDRVQcow2State *s =3D bs->opaque; unsigned int l2_index; - uint64_t l1_index, l2_offset, *l2_table; - int l1_bits, c; + uint64_t l1_index, l2_offset, *l2_slice; + int c; unsigned int offset_in_cluster; uint64_t bytes_available, bytes_needed, nb_clusters; QCow2ClusterType type; @@ -540,12 +540,12 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, ui= nt64_t offset, offset_in_cluster =3D offset_into_cluster(s, offset); bytes_needed =3D (uint64_t) *bytes + offset_in_cluster; =20 - l1_bits =3D s->l2_bits + s->cluster_bits; - /* compute how many bytes there are between the start of the cluster - * containing offset and the end of the l1 entry */ - bytes_available =3D (1ULL << l1_bits) - (offset & ((1ULL << l1_bits) -= 1)) - + offset_in_cluster; + * containing offset and the end of the l2 slice that contains + * the entry pointing to it */ + bytes_available =3D + ((uint64_t) (s->l2_slice_size - offset_to_l2_slice_index(s, offset= ))) + << s->cluster_bits; =20 if (bytes_needed > bytes_available) { bytes_needed =3D bytes_available; @@ -574,17 +574,17 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, ui= nt64_t offset, return -EIO; } =20 - /* load the l2 table in memory */ + /* load the l2 slice in memory */ =20 - ret =3D l2_load(bs, offset, l2_offset, &l2_table); + ret =3D l2_load(bs, offset, l2_offset, &l2_slice); if (ret < 0) { return ret; } =20 /* find the cluster offset for the given disk offset */ =20 - l2_index =3D offset_to_l2_index(s, offset); - *cluster_offset =3D be64_to_cpu(l2_table[l2_index]); + l2_index =3D offset_to_l2_slice_index(s, offset); + *cluster_offset =3D be64_to_cpu(l2_slice[l2_index]); =20 nb_clusters =3D size_to_clusters(s, bytes_needed); /* bytes_needed <=3D *bytes + offset_in_cluster, both of which are uns= igned @@ -611,14 +611,14 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, ui= nt64_t offset, case QCOW2_CLUSTER_UNALLOCATED: /* how many empty clusters ? */ c =3D count_contiguous_clusters_unallocated(nb_clusters, - &l2_table[l2_index], typ= e); + &l2_slice[l2_index], typ= e); *cluster_offset =3D 0; break; case QCOW2_CLUSTER_ZERO_ALLOC: case QCOW2_CLUSTER_NORMAL: /* how many allocated clusters ? */ c =3D count_contiguous_clusters(nb_clusters, s->cluster_size, - &l2_table[l2_index], QCOW_OFLAG_ZERO= ); + &l2_slice[l2_index], QCOW_OFLAG_ZERO= ); *cluster_offset &=3D L2E_OFFSET_MASK; if (offset_into_cluster(s, *cluster_offset)) { qcow2_signal_corruption(bs, true, -1, -1, @@ -634,7 +634,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, abort(); } =20 - qcow2_cache_put(s->l2_table_cache, (void **) &l2_table); + qcow2_cache_put(s->l2_table_cache, (void **) &l2_slice); =20 bytes_available =3D (int64_t)c * s->cluster_size; =20 @@ -652,7 +652,7 @@ out: return type; =20 fail: - qcow2_cache_put(s->l2_table_cache, (void **)&l2_table); + qcow2_cache_put(s->l2_table_cache, (void **)&l2_slice); return ret; } =20 --=20 2.11.0