From nobody Sat Feb 7 06:55:16 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 1517845965994458.66584110521467; Mon, 5 Feb 2018 07:52:45 -0800 (PST) Received: from localhost ([::1]:55740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eij4Q-000324-RN for importer@patchew.org; Mon, 05 Feb 2018 10:52:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eii5e-000840-7g for qemu-devel@nongnu.org; Mon, 05 Feb 2018 09:49:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eii5c-0001FX-63 for qemu-devel@nongnu.org; Mon, 05 Feb 2018 09:49:50 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:49571) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eii5b-0001Cu-SA; Mon, 05 Feb 2018 09:49:48 -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-0001s2-5a; Mon, 05 Feb 2018 15:34:47 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1eihqJ-0008Oe-Fo; 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=xHc+Xj39qxBTj8ZEW9Fydk/nZkzUY3LNCUgOMzEt0vw=; b=O5S/dH2OoKyhAmI8ezAFtUE6jC5/qhPM0tahEZ5ZOg9ueKaAGfpT2ufWblshDtNv6V3TrAmq92do1hDYpK8RVKZ9+fbfcPSADWddqOFyx9sxi7GbwgPvL3bflp4lWq1kB4uKHxenKXpbhpyI0DkpT9nS5Zin3ZegWb+Jzf9BPZRw90Oc2YCJu8CjQEZ2nDyH24TnakvACzV71GuwkQGp6UcbODvfj2cUnc3CuUO3U/VojVkdI0V41hZiYqJmU5b/teO6AxnpqumBu4+ut5BHeh7WYrg8bWaHORL2qhGRlGdRDrkm67eBxJF2seOvMs1ttRYh6zntsnIVNkcymjyhXQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 16:33:18 +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 18/39] qcow2: Refactor get_cluster_table() 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" After the previous patch we're now always using l2_load() in get_cluster_table() regardless of whether a new L2 table has to be allocated or not. This patch refactors that part of the code to use one single l2_load() call. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index e0a3802161..9311dafccd 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -695,15 +695,7 @@ static int get_cluster_table(BlockDriverState *bs, uin= t64_t offset, return -EIO; } =20 - /* seek the l2 table of the given l2 offset */ - - if (s->l1_table[l1_index] & QCOW_OFLAG_COPIED) { - /* load the l2 table in memory */ - ret =3D l2_load(bs, offset, l2_offset, &l2_table); - if (ret < 0) { - return ret; - } - } else { + if (!(s->l1_table[l1_index] & QCOW_OFLAG_COPIED)) { /* First allocate a new L2 table (and do COW if needed) */ ret =3D l2_allocate(bs, l1_index); if (ret < 0) { @@ -719,11 +711,12 @@ static int get_cluster_table(BlockDriverState *bs, ui= nt64_t offset, /* Get the offset of the newly-allocated l2 table */ l2_offset =3D s->l1_table[l1_index] & L1E_OFFSET_MASK; assert(offset_into_cluster(s, l2_offset) =3D=3D 0); - /* Load the l2 table in memory */ - ret =3D l2_load(bs, offset, l2_offset, &l2_table); - if (ret < 0) { - return ret; - } + } + + /* load the l2 table in memory */ + ret =3D l2_load(bs, offset, l2_offset, &l2_table); + if (ret < 0) { + return ret; } =20 /* find the cluster offset for the given disk offset */ --=20 2.11.0