From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XClQx-0005ag-Ka for qemu-devel@nongnu.org; Thu, 31 Jul 2014 04:10:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XClQs-0005Xo-DX for qemu-devel@nongnu.org; Thu, 31 Jul 2014 04:09:55 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:56507 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XClQs-0005Xh-41 for qemu-devel@nongnu.org; Thu, 31 Jul 2014 04:09:50 -0400 Date: Thu, 31 Jul 2014 10:09:05 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140731080904.GJ707@irqsave.net> References: <1406402531-9278-1-git-send-email-mreitz@redhat.com> <1406402531-9278-6-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1406402531-9278-6-git-send-email-mreitz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH alt 5/7] block/qcow2: Make get_refcount() global List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi The Saturday 26 Jul 2014 =E0 21:22:09 (+0200), Max Reitz wrote : > Reading the refcount of a cluster is an operation which can be useful i= n > all of the qcow2 code, so make that function globally available. >=20 > Signed-off-by: Max Reitz > --- > block/qcow2-refcount.c | 23 ++++++++++++----------- > block/qcow2.h | 2 ++ > 2 files changed, 14 insertions(+), 11 deletions(-) >=20 > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index cc6cf74..0c9887b 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -87,7 +87,7 @@ static int load_refcount_block(BlockDriverState *bs, > * return value is the refcount of the cluster, negative values are -e= rrno > * and indicate an error. > */ > -static int get_refcount(BlockDriverState *bs, int64_t cluster_index) > +int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index) > { > BDRVQcowState *s =3D bs->opaque; > uint64_t refcount_table_index, block_index; > @@ -625,7 +625,7 @@ int qcow2_update_cluster_refcount(BlockDriverState = *bs, > return ret; > } > =20 > - return get_refcount(bs, cluster_index); > + return qcow2_get_refcount(bs, cluster_index); > } > =20 > =20 > @@ -646,7 +646,7 @@ static int64_t alloc_clusters_noref(BlockDriverStat= e *bs, uint64_t size) > retry: > for(i =3D 0; i < nb_clusters; i++) { > uint64_t next_cluster_index =3D s->free_cluster_index++; > - refcount =3D get_refcount(bs, next_cluster_index); > + refcount =3D qcow2_get_refcount(bs, next_cluster_index); > =20 > if (refcount < 0) { > return refcount; > @@ -710,7 +710,7 @@ int qcow2_alloc_clusters_at(BlockDriverState *bs, u= int64_t offset, > /* Check how many clusters there are free */ > cluster_index =3D offset >> s->cluster_bits; > for(i =3D 0; i < nb_clusters; i++) { > - refcount =3D get_refcount(bs, cluster_index++); > + refcount =3D qcow2_get_refcount(bs, cluster_index++); > =20 > if (refcount < 0) { > return refcount; > @@ -927,7 +927,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, > cluster_index, addend, > QCOW2_DISCARD_SNAPSHOT); > } else { > - refcount =3D get_refcount(bs, cluster_inde= x); > + refcount =3D qcow2_get_refcount(bs, cluste= r_index); > } > =20 > if (refcount < 0) { > @@ -967,7 +967,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, > refcount =3D qcow2_update_cluster_refcount(bs, l2_offs= et >> > s->cluster_bits, addend, QCOW2_DISCARD_SNAPSHO= T); > } else { > - refcount =3D get_refcount(bs, l2_offset >> s->cluster_= bits); > + refcount =3D qcow2_get_refcount(bs, l2_offset >> s->cl= uster_bits); > } > if (refcount < 0) { > ret =3D refcount; > @@ -1243,8 +1243,8 @@ fail: > * Checks the OFLAG_COPIED flag for all L1 and L2 entries. > * > * This function does not print an error message nor does it increment > - * check_errors if get_refcount fails (this is because such an error w= ill have > - * been already detected and sufficiently signaled by the calling func= tion > + * check_errors if qcow2_get_refcount fails (this is because such an e= rror will > + * have been already detected and sufficiently signaled by the calling= function > * (qcow2_check_refcounts) by the time this function is called). > */ > static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *r= es, > @@ -1265,7 +1265,7 @@ static int check_oflag_copied(BlockDriverState *b= s, BdrvCheckResult *res, > continue; > } > =20 > - refcount =3D get_refcount(bs, l2_offset >> s->cluster_bits); > + refcount =3D qcow2_get_refcount(bs, l2_offset >> s->cluster_bi= ts); > if (refcount < 0) { > /* don't print message nor increment check_errors */ > continue; > @@ -1307,7 +1307,8 @@ static int check_oflag_copied(BlockDriverState *b= s, BdrvCheckResult *res, > =20 > if ((cluster_type =3D=3D QCOW2_CLUSTER_NORMAL) || > ((cluster_type =3D=3D QCOW2_CLUSTER_ZERO) && (data_off= set !=3D 0))) { > - refcount =3D get_refcount(bs, data_offset >> s->cluste= r_bits); > + refcount =3D qcow2_get_refcount(bs, > + data_offset >> s->cluste= r_bits); > if (refcount < 0) { > /* don't print message nor increment check_errors = */ > continue; > @@ -1597,7 +1598,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, B= drvCheckResult *res, > =20 > /* compare ref counts */ > for (i =3D 0, highest_cluster =3D 0; i < nb_clusters; i++) { > - refcount1 =3D get_refcount(bs, i); > + refcount1 =3D qcow2_get_refcount(bs, i); > if (refcount1 < 0) { > fprintf(stderr, "Can't get refcount for cluster %" PRId64 = ": %s\n", > i, strerror(-refcount1)); > diff --git a/block/qcow2.h b/block/qcow2.h > index 1c4f9bf..c0e1b7b 100644 > --- a/block/qcow2.h > +++ b/block/qcow2.h > @@ -472,6 +472,8 @@ int qcow2_update_header(BlockDriverState *bs); > int qcow2_refcount_init(BlockDriverState *bs); > void qcow2_refcount_close(BlockDriverState *bs); > =20 > +int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index); > + > int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluste= r_index, > int addend, enum qcow2_discard_type = type); > =20 > --=20 > 2.0.3 >=20 >=20 Reviewed-by: Benoit Canet