From nobody Mon Feb 9 21:19:29 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.zoho.com; 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 1494115996564933.5740426230441; Sat, 6 May 2017 17:13:16 -0700 (PDT) Received: from localhost ([::1]:53117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d79p5-0000Ug-5Z for importer@patchew.org; Sat, 06 May 2017 20:13:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d79iC-0002eT-UH for qemu-devel@nongnu.org; Sat, 06 May 2017 20:06:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d79iB-0007jy-R0 for qemu-devel@nongnu.org; Sat, 06 May 2017 20:06:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53102) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d79i8-0007hi-TA; Sat, 06 May 2017 20:06:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB046201FB; Sun, 7 May 2017 00:06:03 +0000 (UTC) Received: from red.redhat.com (ovpn-122-206.rdu2.redhat.com [10.10.122.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A6E718345; Sun, 7 May 2017 00:06:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DB046201FB Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DB046201FB From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 6 May 2017 19:05:45 -0500 Message-Id: <20170507000552.20847-6-eblake@redhat.com> In-Reply-To: <20170507000552.20847-1-eblake@redhat.com> References: <20170507000552.20847-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sun, 07 May 2017 00:06:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v13 05/12] qcow2: Name typedef for cluster type 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: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Although it doesn't add all that much type safety (this is C, after all), it does add a bit of legibility to use the name QCow2ClusterType instead of a plain int. In particular, qcow2_get_cluster_offset() has an overloaded return type; a QCow2ClusterType on success, and -errno on failure; keeping the cluster type in a separate variable makes it slightly easier for the next patch to make further computations based on the type. Suggested-by: Max Reitz Signed-off-by: Eric Blake --- v13: new patch --- block/qcow2.h | 6 +++--- block/qcow2-cluster.c | 17 +++++++++-------- block/qcow2-refcount.c | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 8731f24..c148bbc 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -349,12 +349,12 @@ typedef struct QCowL2Meta QLIST_ENTRY(QCowL2Meta) next_in_flight; } QCowL2Meta; -enum { +typedef enum QCow2ClusterType { QCOW2_CLUSTER_UNALLOCATED, QCOW2_CLUSTER_NORMAL, QCOW2_CLUSTER_COMPRESSED, QCOW2_CLUSTER_ZERO -}; +} QCow2ClusterType; typedef enum QCow2MetadataOverlap { QCOW2_OL_MAIN_HEADER_BITNR =3D 0, @@ -443,7 +443,7 @@ static inline uint64_t qcow2_max_refcount_clusters(BDRV= Qcow2State *s) return QCOW_MAX_REFTABLE_SIZE >> s->cluster_bits; } -static inline int qcow2_get_cluster_type(uint64_t l2_entry) +static inline QCow2ClusterType qcow2_get_cluster_type(uint64_t l2_entry) { if (l2_entry & QCOW_OFLAG_COMPRESSED) { return QCOW2_CLUSTER_COMPRESSED; diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f3bfce6..ed78a30 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -340,7 +340,7 @@ static int count_contiguous_clusters(int nb_clusters, i= nt cluster_size, */ static int count_contiguous_clusters_unallocated(int nb_clusters, uint64_t *l2_table, - int wanted_type) + QCow2ClusterType wanted_t= ype) { int i; @@ -500,6 +500,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, int l1_bits, c; unsigned int offset_in_cluster; uint64_t bytes_available, bytes_needed, nb_clusters; + QCow2ClusterType type; int ret; offset_in_cluster =3D offset_into_cluster(s, offset); @@ -522,13 +523,13 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, ui= nt64_t offset, l1_index =3D offset >> l1_bits; if (l1_index >=3D s->l1_size) { - ret =3D QCOW2_CLUSTER_UNALLOCATED; + type =3D QCOW2_CLUSTER_UNALLOCATED; goto out; } l2_offset =3D s->l1_table[l1_index] & L1E_OFFSET_MASK; if (!l2_offset) { - ret =3D QCOW2_CLUSTER_UNALLOCATED; + type =3D QCOW2_CLUSTER_UNALLOCATED; goto out; } @@ -557,8 +558,8 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint= 64_t offset, * true */ assert(nb_clusters <=3D INT_MAX); - ret =3D qcow2_get_cluster_type(*cluster_offset); - switch (ret) { + type =3D qcow2_get_cluster_type(*cluster_offset); + switch (type) { case QCOW2_CLUSTER_COMPRESSED: /* Compressed clusters can only be processed one by one */ c =3D 1; @@ -633,7 +634,7 @@ out: assert(bytes_available - offset_in_cluster <=3D UINT_MAX); *bytes =3D bytes_available - offset_in_cluster; - return ret; + return type; fail: qcow2_cache_put(bs, s->l2_table_cache, (void **)&l2_table); @@ -891,7 +892,7 @@ static int count_cow_clusters(BDRVQcow2State *s, int nb= _clusters, for (i =3D 0; i < nb_clusters; i++) { uint64_t l2_entry =3D be64_to_cpu(l2_table[l2_index + i]); - int cluster_type =3D qcow2_get_cluster_type(l2_entry); + QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(l2_entry); switch(cluster_type) { case QCOW2_CLUSTER_NORMAL: @@ -1757,7 +1758,7 @@ static int expand_zero_clusters_in_l1(BlockDriverStat= e *bs, uint64_t *l1_table, for (j =3D 0; j < s->l2_size; j++) { uint64_t l2_entry =3D be64_to_cpu(l2_table[j]); int64_t offset =3D l2_entry & L2E_OFFSET_MASK; - int cluster_type =3D qcow2_get_cluster_type(l2_entry); + QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(l2_en= try); bool preallocated =3D offset !=3D 0; if (cluster_type !=3D QCOW2_CLUSTER_ZERO) { diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 908dbe5..e639b34 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1640,7 +1640,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, for (j =3D 0; j < s->l2_size; j++) { uint64_t l2_entry =3D be64_to_cpu(l2_table[j]); uint64_t data_offset =3D l2_entry & L2E_OFFSET_MASK; - int cluster_type =3D qcow2_get_cluster_type(l2_entry); + QCow2ClusterType cluster_type =3D qcow2_get_cluster_type(l2_en= try); if ((cluster_type =3D=3D QCOW2_CLUSTER_NORMAL) || ((cluster_type =3D=3D QCOW2_CLUSTER_ZERO) && (data_offset = !=3D 0))) { --=20 2.9.3