From nobody Sat Feb 7 08:55:13 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 1516979271328357.56749125203555; Fri, 26 Jan 2018 07:07:51 -0800 (PST) Received: from localhost ([::1]:60609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef5ba-0007oT-IB for importer@patchew.org; Fri, 26 Jan 2018 10:07:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef5VC-0003Zg-5L for qemu-devel@nongnu.org; Fri, 26 Jan 2018 10:01:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef5V9-0005UG-RO for qemu-devel@nongnu.org; Fri, 26 Jan 2018 10:01:14 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:50720) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ef5V9-0005TF-DW; 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-0007gw-RN; Fri, 26 Jan 2018 16:01:10 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ef5UH-00087B-6Z; 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=wMM6RX/1t6MV7nzkH4gqCc0RPd4aeZOjEMMDswmNa6w=; b=mt4C4lwM3iBVU/bHOcnyDkNsKtR4YQuq+m4YisnRiDYnbMR0+YMuTqWpqS8yezko+ga1jbTXbT6LKjmms5e4MxfX6VwksIu7knCRQ2oWSMSnjEN3XOfFya7svnjd4Gk1e5/fHcsIBhIByd0ZCudKS45cV9Xzq+Ri7lkolBbHr2ls6VucNdTP5NrBNmtdC1TByhb9CNWC5SqT/B3VpoLHkKm7MwnsQaKYjQ4bGxHNVLX77aq37/pUhqk25EUy2/VnFniYEiAvNni9t0tzOwZ/IFd0Gwt0y2R6GT28QF3BdRjw1UlpSrwTc9ZZ4VCIullSeQTza9k2CytGM/A4P5qtnA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 16:59:43 +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 16/39] qcow2: Prepare l2_allocate() 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: 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" Adding support for L2 slices to l2_allocate() needs (among other things) an extra loop that iterates over all slices of a new 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 --- block/qcow2-cluster.c | 55 ++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 8d92d623d8..57349928a9 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -300,38 +300,43 @@ static int l2_allocate(BlockDriverState *bs, int l1_i= ndex, uint64_t **table) /* allocate a new entry in the l2 cache */ =20 trace_qcow2_l2_allocate_get_empty(bs, l1_index); - ret =3D qcow2_cache_get_empty(bs, s->l2_table_cache, l2_offset, (void*= *) table); - if (ret < 0) { - goto fail; - } - - l2_table =3D *table; - - if ((old_l2_offset & L1E_OFFSET_MASK) =3D=3D 0) { - /* if there was no old l2 table, clear the new table */ - memset(l2_table, 0, s->l2_size * sizeof(uint64_t)); - } else { - uint64_t* old_table; - - /* if there was an old l2 table, read it from the disk */ - BLKDBG_EVENT(bs->file, BLKDBG_L2_ALLOC_COW_READ); - ret =3D qcow2_cache_get(bs, s->l2_table_cache, - old_l2_offset & L1E_OFFSET_MASK, - (void**) &old_table); + { + ret =3D qcow2_cache_get_empty(bs, s->l2_table_cache, + l2_offset, + (void **) table); if (ret < 0) { goto fail; } =20 - memcpy(l2_table, old_table, s->cluster_size); + l2_table =3D *table; =20 - qcow2_cache_put(s->l2_table_cache, (void **) &old_table); + if ((old_l2_offset & L1E_OFFSET_MASK) =3D=3D 0) { + /* if there was no old l2 table, clear the new table */ + memset(l2_table, 0, s->l2_size * sizeof(uint64_t)); + } else { + uint64_t *old_table; + + /* if there was an old l2 table, read it from the disk */ + BLKDBG_EVENT(bs->file, BLKDBG_L2_ALLOC_COW_READ); + ret =3D qcow2_cache_get(bs, s->l2_table_cache, + old_l2_offset & L1E_OFFSET_MASK, + (void **) &old_table); + if (ret < 0) { + goto fail; + } + + memcpy(l2_table, old_table, s->cluster_size); + + qcow2_cache_put(s->l2_table_cache, (void **) &old_table); + } + + /* write the l2 table to the file */ + BLKDBG_EVENT(bs->file, BLKDBG_L2_ALLOC_WRITE); + + trace_qcow2_l2_allocate_write_l2(bs, l1_index); + qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table); } =20 - /* write the l2 table to the file */ - BLKDBG_EVENT(bs->file, BLKDBG_L2_ALLOC_WRITE); - - trace_qcow2_l2_allocate_write_l2(bs, l1_index); - qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table); ret =3D qcow2_cache_flush(bs, s->l2_table_cache); if (ret < 0) { goto fail; --=20 2.11.0