From nobody Sun Feb 8 21:21:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1584470106; cv=none; d=zohomail.com; s=zohoarc; b=WAsuK7mAcmX2d0ae+3U4v2FEQtS0APHeOkfBBvY0hJpDvmmK20+ZgWwQ516TgUCunDfwThsQdFSYiE5AoT/2WExpe900sW4DlmJcHFNYJC/3mvji7gOHQZi1Csc+qQMIAlQZ/+yV/awh4VS1qfSis1avdm5dHmYipTMTOvFTXkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584470106; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=woi6foyn/GnsQXxokCfj/612eLxPV2bZbIy780eGch4=; b=IYEtHEItoo+DrdK2NUy7ZJGzIJ53MHddYFhOau13WiEaG202+h+e84ictAInJ+q+oTGOJvfWLk7ScCJcaVzcizG3kEVTyHxAjJ14fBXQ+s5DIqRxbEDrZFrlB+CNfDpl3ZcEEqW/C4P/iEAsCvNLeh3mZLnuJ3nqiN/T2WGyJ6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584470106296925.1566402023527; Tue, 17 Mar 2020 11:35:06 -0700 (PDT) Received: from localhost ([::1]:39432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEH3R-0003fV-37 for importer@patchew.org; Tue, 17 Mar 2020 14:35:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48705) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEGmu-0003Mn-57 for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEGms-0008UH-GF for qemu-devel@nongnu.org; Tue, 17 Mar 2020 14:18:00 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:57771) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEGms-0005Ys-5E; Tue, 17 Mar 2020 14:17:58 -0400 Received: from [81.0.35.138] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1jEGmD-00015Q-0o; Tue, 17 Mar 2020 19:17:17 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1jEGlw-0006OV-H0; Tue, 17 Mar 2020 19:17:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=woi6foyn/GnsQXxokCfj/612eLxPV2bZbIy780eGch4=; b=OOndXjn7oDji51bTAsQqtUeSdocQYLxrCgRLxHXRY7rd0r6xQ5e50lIG6RHnHgsgyW1pmkSbjqzgkbaJrsQp9kWTD+67kVTdU24Z6tCL1OoJxeOfb1rfGwVVB6Wne8hqqry0mNc+ZE6mjrLYLMHOPOTsb2LvBtbm1Dx/YCHlrhzoywalGTVauet9cBU9DMCScqc+niaQFrRwz31Cd63to6+c1TdLU5B6pj33JrsRjWpCIWhPJgHIfy57UqphjXahd/PVUtisPpdX6Lm+Lxr7vaLL2ERk+8sTGwkxhPQ27wyi/vYYDxa6vkUYB9OC0tFc8/5ruQwkIW5UoLKffpwaxw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v4 14/30] qcow2: Add cluster type parameter to qcow2_get_host_offset() Date: Tue, 17 Mar 2020 19:16:11 +0100 Message-Id: <348c0b057802b5b35eefe3dc7cc8ef2964024ed5.1584468723.git.berto@igalia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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 , Vladimir Sementsov-Ogievskiy , "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) Content-Type: text/plain; charset="utf-8" This function returns an integer that can be either an error code or a cluster type (a value from the QCow2ClusterType enum). We are going to start using subcluster types instead of cluster types in some functions so it's better to use the exact data types instead of integers for clarity and in order to detect errors more easily. This patch makes qcow2_get_host_offset() return 0 on success and puts the returned cluster type in a separate parameter. There are no semantic changes. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 3 ++- block/qcow2-cluster.c | 11 +++++++---- block/qcow2.c | 37 ++++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 52865787ee..6b7b286b91 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -859,7 +859,8 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t se= ctor_num, uint8_t *buf, int nb_sectors, bool enc, Error **= errp); =20 int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, - unsigned int *bytes, uint64_t *host_offset); + unsigned int *bytes, uint64_t *host_offset, + QCow2ClusterType *cluster_type); int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *host_offset, QCowL2Meta **m); diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 41a23c5305..acfcf8ea4c 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -514,13 +514,14 @@ static int coroutine_fn do_perform_cow_write(BlockDri= verState *bs, * * On exit, *bytes is the number of bytes starting at offset that have the= same * cluster type and (if applicable) are stored contiguously in the image f= ile. + * The cluster type is stored in *cluster_type. * Compressed clusters are always returned one by one. * - * Returns the cluster type (QCOW2_CLUSTER_*) on success, -errno in error - * cases. + * Returns 0 on success, -errno in error cases. */ int qcow2_get_host_offset(BlockDriverState *bs, uint64_t offset, - unsigned int *bytes, uint64_t *host_offset) + unsigned int *bytes, uint64_t *host_offset, + QCow2ClusterType *cluster_type) { BDRVQcow2State *s =3D bs->opaque; unsigned int l2_index; @@ -663,7 +664,9 @@ out: assert(bytes_available - offset_in_cluster <=3D UINT_MAX); *bytes =3D bytes_available - offset_in_cluster; =20 - return type; + *cluster_type =3D type; + + return 0; =20 fail: qcow2_cache_put(s->l2_table_cache, (void **)&l2_slice); diff --git a/block/qcow2.c b/block/qcow2.c index d3b8581aed..48e188152c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1971,6 +1971,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, BDRVQcow2State *s =3D bs->opaque; uint64_t host_offset; unsigned int bytes; + QCow2ClusterType type; int ret, status =3D 0; =20 qemu_co_mutex_lock(&s->lock); @@ -1982,7 +1983,7 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, } =20 bytes =3D MIN(INT_MAX, count); - ret =3D qcow2_get_host_offset(bs, offset, &bytes, &host_offset); + ret =3D qcow2_get_host_offset(bs, offset, &bytes, &host_offset, &type); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { return ret; @@ -1990,15 +1991,15 @@ static int coroutine_fn qcow2_co_block_status(Block= DriverState *bs, =20 *pnum =3D bytes; =20 - if ((ret =3D=3D QCOW2_CLUSTER_NORMAL || ret =3D=3D QCOW2_CLUSTER_ZERO_= ALLOC) && + if ((type =3D=3D QCOW2_CLUSTER_NORMAL || type =3D=3D QCOW2_CLUSTER_ZER= O_ALLOC) && !s->crypto) { *map =3D host_offset; *file =3D s->data_file->bs; status |=3D BDRV_BLOCK_OFFSET_VALID; } - if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || ret =3D=3D QCOW2_CLUSTER_ZE= RO_ALLOC) { + if (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || type =3D=3D QCOW2_CLUSTER_= ZERO_ALLOC) { status |=3D BDRV_BLOCK_ZERO; - } else if (ret !=3D QCOW2_CLUSTER_UNALLOCATED) { + } else if (type !=3D QCOW2_CLUSTER_UNALLOCATED) { status |=3D BDRV_BLOCK_DATA; } if (s->metadata_preallocation && (status & BDRV_BLOCK_DATA) && @@ -2207,6 +2208,7 @@ static coroutine_fn int qcow2_co_preadv_part(BlockDri= verState *bs, int ret =3D 0; unsigned int cur_bytes; /* number of bytes in current iteration */ uint64_t host_offset =3D 0; + QCow2ClusterType type; AioTaskPool *aio =3D NULL; =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -2218,22 +2220,23 @@ static coroutine_fn int qcow2_co_preadv_part(BlockD= riverState *bs, } =20 qemu_co_mutex_lock(&s->lock); - ret =3D qcow2_get_host_offset(bs, offset, &cur_bytes, &host_offset= ); + ret =3D qcow2_get_host_offset(bs, offset, &cur_bytes, + &host_offset, &type); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { goto out; } =20 - if (ret =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || - ret =3D=3D QCOW2_CLUSTER_ZERO_ALLOC || - (ret =3D=3D QCOW2_CLUSTER_UNALLOCATED && !bs->backing)) + if (type =3D=3D QCOW2_CLUSTER_ZERO_PLAIN || + type =3D=3D QCOW2_CLUSTER_ZERO_ALLOC || + (type =3D=3D QCOW2_CLUSTER_UNALLOCATED && !bs->backing)) { qemu_iovec_memset(qiov, qiov_offset, 0, cur_bytes); } else { if (!aio && cur_bytes !=3D bytes) { aio =3D aio_task_pool_new(QCOW2_MAX_WORKERS); } - ret =3D qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, re= t, + ret =3D qcow2_add_task(bs, aio, qcow2_co_preadv_task_entry, ty= pe, host_offset, offset, cur_bytes, qiov, qiov_offset, NULL); if (ret < 0) { @@ -3716,6 +3719,7 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(BlockD= riverState *bs, if (head || tail) { uint64_t off; unsigned int nr; + QCow2ClusterType type; =20 assert(head + bytes <=3D s->cluster_size); =20 @@ -3731,10 +3735,11 @@ static coroutine_fn int qcow2_co_pwrite_zeroes(Bloc= kDriverState *bs, offset =3D QEMU_ALIGN_DOWN(offset, s->cluster_size); bytes =3D s->cluster_size; nr =3D s->cluster_size; - ret =3D qcow2_get_host_offset(bs, offset, &nr, &off); - if (ret !=3D QCOW2_CLUSTER_UNALLOCATED && - ret !=3D QCOW2_CLUSTER_ZERO_PLAIN && - ret !=3D QCOW2_CLUSTER_ZERO_ALLOC) { + ret =3D qcow2_get_host_offset(bs, offset, &nr, &off, &type); + if (ret < 0 || + (type !=3D QCOW2_CLUSTER_UNALLOCATED && + type !=3D QCOW2_CLUSTER_ZERO_PLAIN && + type !=3D QCOW2_CLUSTER_ZERO_ALLOC)) { qemu_co_mutex_unlock(&s->lock); return -ENOTSUP; } @@ -3792,16 +3797,18 @@ qcow2_co_copy_range_from(BlockDriverState *bs, =20 while (bytes !=3D 0) { uint64_t copy_offset =3D 0; + QCow2ClusterType type; /* prepare next request */ cur_bytes =3D MIN(bytes, INT_MAX); cur_write_flags =3D write_flags; =20 - ret =3D qcow2_get_host_offset(bs, src_offset, &cur_bytes, ©_of= fset); + ret =3D qcow2_get_host_offset(bs, src_offset, &cur_bytes, + ©_offset, &type); if (ret < 0) { goto out; } =20 - switch (ret) { + switch (type) { case QCOW2_CLUSTER_UNALLOCATED: if (bs->backing && bs->backing->bs) { int64_t backing_length =3D bdrv_getlength(bs->backing->bs); --=20 2.20.1