From nobody Sat Feb 7 06:55:14 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517844512734162.07574071147974; Mon, 5 Feb 2018 07:28:32 -0800 (PST) Received: from localhost ([::1]:53738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eiih0-0007IT-SY for importer@patchew.org; Mon, 05 Feb 2018 10:28:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eii4g-0006z8-Ug for qemu-devel@nongnu.org; Mon, 05 Feb 2018 09:48:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eii4d-0008Ig-QF for qemu-devel@nongnu.org; Mon, 05 Feb 2018 09:48:50 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:49480) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eii4d-0008HF-Fu; Mon, 05 Feb 2018 09:48:47 -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 1eihr5-0001rw-5g; Mon, 05 Feb 2018 15:34:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1eihqJ-0008OM-AN; 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=dwC5TwHvexisLUZs0mdekK1tXNXpbcj5BzDd2x3mDuI=; b=cJDkx3K/psqnlzJ+JYVIz6vuhYt6SCL2JfTPSeSOaqTkGaMSyUCQSa0Cn2ziACZUcZLrv9HZYykNNNaSfsYRH6CIkCs/gJUAynbPpezOyWUZcuQOr2Asx74lpH7024XOusrlZCcPGXTyM+E7DnqzA32t1Jc2qxezEjJdxTiRTmHjomGYAzLW4Q4Q6L0CLhcWtJyRMH2h3eCrLoy+hvZhmO1OdeY4gVe0S9OEFRpPb2+KsEOXXnsng7rfAF/whGlavfPyyBamQ+YuZTPW73BHLAJ8FV5BMUyRFdy1G+JEPVaLAQCUZrWQgURJFnNPQkAp655hgi03H0VMHFwS5fAYTg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 16:33:12 +0200 Message-Id: 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 12/39] qcow2: Add offset_to_l1_index() 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" Similar to offset_to_l2_index(), this function returns the index in the L1 table for a given guest offset. This is only used in a couple of places and it's not a particularly complex calculation, but it makes the code a bit more readable. Although in the qcow2_get_cluster_offset() case the old code was taking advantage of the l1_bits variable, we're going to get rid of the other uses of l1_bits in a later patch anyway, so it doesn't make sense to keep it just for this. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 4 ++-- block/qcow2.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 4a7b46038b..6369a74efe 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -541,7 +541,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, =20 /* seek to the l2 offset in the l1 table */ =20 - l1_index =3D offset >> l1_bits; + l1_index =3D offset_to_l1_index(s, offset); if (l1_index >=3D s->l1_size) { type =3D QCOW2_CLUSTER_UNALLOCATED; goto out; @@ -664,7 +664,7 @@ static int get_cluster_table(BlockDriverState *bs, uint= 64_t offset, =20 /* seek to the l2 offset in the l1 table */ =20 - l1_index =3D offset >> (s->l2_bits + s->cluster_bits); + l1_index =3D offset_to_l1_index(s, offset); if (l1_index >=3D s->l1_size) { ret =3D qcow2_grow_l1_table(bs, l1_index + 1, false); if (ret < 0) { diff --git a/block/qcow2.h b/block/qcow2.h index cb8dd784fa..0559afbc63 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -463,6 +463,11 @@ static inline int64_t size_to_l1(BDRVQcow2State *s, in= t64_t size) return (size + (1ULL << shift) - 1) >> shift; } =20 +static inline int offset_to_l1_index(BDRVQcow2State *s, uint64_t offset) +{ + return offset >> (s->l2_bits + s->cluster_bits); +} + static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset) { return (offset >> s->cluster_bits) & (s->l2_size - 1); --=20 2.11.0