From nobody Mon Feb 9 11:08:00 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 1516979020632102.45786404610294; Fri, 26 Jan 2018 07:03:40 -0800 (PST) Received: from localhost ([::1]:60438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef5XV-0004vA-4R for importer@patchew.org; Fri, 26 Jan 2018 10:03:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef5VJ-0003gu-Ot for qemu-devel@nongnu.org; Fri, 26 Jan 2018 10:01:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef5V9-0005UI-Rv for qemu-devel@nongnu.org; Fri, 26 Jan 2018 10:01:21 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:50719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ef5V9-0005TC-De; Fri, 26 Jan 2018 10:01:11 -0500 Received: from 88-114-101-230.elisa-laajakaista.fi ([88.114.101.230] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ef5V7-0007gv-Vl; Fri, 26 Jan 2018 16:01:10 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ef5UH-000877-5Z; Fri, 26 Jan 2018 17:00:17 +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=uqw0nefTZ38lsqY8ji7JnkWvem3jtSOxYwQuWv/4kjE=; b=AEtwsL0wxCvbiLjolo7oK0IQTrRF/Ka31qRdTB22uz/6B7DPDhivN4H3FChomO44GYPRth+tp5br3RxjteMeW3w1WpxtCb5N/qvsRzwrahfv1lhiwKe5Xh+UuRVJTHfbXzumdanpB8MJ3dElgZbDtchpBoSrBJx8nEphhkAtsiBqyn8EoNCL9aeN60qu/rtt8F7TPz51WF51niiJ3JO1vPkVXfRk3wchieLLZfHuE6/WZL95Lwa/fqeE/NyFd2S7uTFHbRTlM3118Lwk/jdn9zf4dg0B15+rj6B3inq6bjbama+p9SPUGEWn6OaPgmH5zkQR5FzRcv3cFbvOG+nE4A==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 16:59:42 +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 v3 15/39] qcow2: Update l2_load() 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" Each entry in the qcow2 L2 cache stores a full L2 table (which uses a complete cluster in the qcow2 image). A cluster is usually too large to be used efficiently as the size for a cache entry, so we want to decouple both values by allowing smaller cache entries. Therefore the qcow2 L2 cache will no longer return full L2 tables but slices instead. This patch updates l2_load() so it can handle L2 slices correctly. Apart from the offset of the L2 table (which we already had) we also need the guest offset in order to calculate which one of the slices we need. An L2 slice has currently the same size as an L2 table (one cluster), so for now this function will load exactly the same data as before. This patch also removes a stale comment about the return value being a pointer to the L2 table. This function returns an error code since 55c17e9821c474d5fcdebdc82ed2fc096777d611. Signed-off-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block/qcow2-cluster.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 6369a74efe..8d92d623d8 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -196,20 +196,26 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_= t min_size, /* * l2_load * - * Loads a L2 table into memory. If the table is in the cache, the cache - * is used; otherwise the L2 table is loaded from the image file. + * @bs: The BlockDriverState + * @offset: A guest offset, used to calculate what slice of the L2 + * table to load. + * @l2_offset: Offset to the L2 table in the image file. + * @l2_slice: Location to store the pointer to the L2 slice. * - * Returns a pointer to the L2 table on success, or NULL if the read from - * the image file failed. + * Loads a L2 slice into memory (L2 slices are the parts of L2 tables + * that are loaded by the qcow2 cache). If the slice is in the cache, + * the cache is used; otherwise the L2 slice is loaded from the image + * file. */ - -static int l2_load(BlockDriverState *bs, uint64_t l2_offset, - uint64_t **l2_table) +static int l2_load(BlockDriverState *bs, uint64_t offset, + uint64_t l2_offset, uint64_t **l2_slice) { BDRVQcow2State *s =3D bs->opaque; + int start_of_slice =3D sizeof(uint64_t) * + (offset_to_l2_index(s, offset) - offset_to_l2_slice_index(s, offse= t)); =20 - return qcow2_cache_get(bs, s->l2_table_cache, l2_offset, - (void **)l2_table); + return qcow2_cache_get(bs, s->l2_table_cache, l2_offset + start_of_sli= ce, + (void **)l2_slice); } =20 /* @@ -562,7 +568,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, =20 /* load the l2 table in memory */ =20 - ret =3D l2_load(bs, l2_offset, &l2_table); + ret =3D l2_load(bs, offset, l2_offset, &l2_table); if (ret < 0) { return ret; } @@ -685,7 +691,7 @@ static int get_cluster_table(BlockDriverState *bs, uint= 64_t offset, =20 if (s->l1_table[l1_index] & QCOW_OFLAG_COPIED) { /* load the l2 table in memory */ - ret =3D l2_load(bs, l2_offset, &l2_table); + ret =3D l2_load(bs, offset, l2_offset, &l2_table); if (ret < 0) { return ret; } --=20 2.11.0