From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEEd1-0004N0-Tv for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:32:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEEcw-0004m8-4l for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:32:27 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:44295 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEEcv-0004m4-QK for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:32:22 -0400 Date: Mon, 4 Aug 2014 11:31:38 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140804093138.GD17835@irqsave.net> References: <1406936961-20356-1-git-send-email-mreitz@redhat.com> <1406936961-20356-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: <1406936961-20356-6-git-send-email-mreitz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 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 02 Aug 2014 =E0 01:49:19 (+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 > While touching this function, amend the comment describing the "addend" > parameter: It is (no longer, if it ever was) necessary to have it set t= o > -1 or 1; any value is fine. >=20 > Signed-off-by: Max Reitz > --- > block/qcow2-refcount.c | 26 +++++++++++++------------- > block/qcow2.h | 2 ++ > 2 files changed, 15 insertions(+), 13 deletions(-) >=20 > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index cc6cf74..1c2ab8c 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; > @@ -605,8 +605,7 @@ fail: > } > =20 > /* > - * Increases or decreases the refcount of a given cluster by one. > - * addend must be 1 or -1. > + * Increases or decreases the refcount of a given cluster. > * > * If the return value is non-negative, it is the new refcount of the = cluster. > * If it is negative, it is -errno and indicates an error. > @@ -625,7 +624,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 +645,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 +709,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 +926,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 +966,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 +1242,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 +1264,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 +1306,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 +1597,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