From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGBl-0006Gf-MX for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:52:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlGBf-0000pP-62 for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:52:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37100) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGBe-0000pB-En for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:52:43 -0500 From: Stefan Hajnoczi Date: Mon, 3 Nov 2014 11:50:43 +0000 Message-Id: <1415015456-25086-41-git-send-email-stefanha@redhat.com> In-Reply-To: <1415015456-25086-1-git-send-email-stefanha@redhat.com> References: <1415015456-25086-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 40/53] block/qcow2: Make get_refcount() global List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi , Max Reitz From: Max Reitz Reading the refcount of a cluster is an operation which can be useful in all of the qcow2 code, so make that function globally available. While touching this function, amend the comment describing the "addend" parameter: It is (no longer, if it ever was) necessary to have it set to -1 or 1; any value is fine. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Beno=C3=AEt Canet Reviewed-by: Kevin Wolf Reviewed-by: Benoit Canet Message-id: 1414404776-4919-6-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi --- block/qcow2-refcount.c | 26 +++++++++++++------------- block/qcow2.h | 2 ++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 1477031..9afdb40 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -91,7 +91,7 @@ static int load_refcount_block(BlockDriverState *bs, * return value is the refcount of the cluster, negative values are -err= no * 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; @@ -629,8 +629,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 cl= uster. * If it is negative, it is -errno and indicates an error. @@ -649,7 +648,7 @@ int qcow2_update_cluster_refcount(BlockDriverState *b= s, return ret; } =20 - return get_refcount(bs, cluster_index); + return qcow2_get_refcount(bs, cluster_index); } =20 =20 @@ -670,7 +669,7 @@ static int64_t alloc_clusters_noref(BlockDriverState = *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; @@ -734,7 +733,7 @@ int qcow2_alloc_clusters_at(BlockDriverState *bs, uin= t64_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; @@ -981,7 +980,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *= bs, cluster_index, addend, QCOW2_DISCARD_SNAPSHOT); } else { - refcount =3D get_refcount(bs, cluster_index)= ; + refcount =3D qcow2_get_refcount(bs, cluster_= index); } =20 if (refcount < 0) { @@ -1021,7 +1020,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState= *bs, refcount =3D qcow2_update_cluster_refcount(bs, l2_offset= >> s->cluster_bits, addend, QCOW2_DISCARD_SNAPSHOT)= ; } else { - refcount =3D get_refcount(bs, l2_offset >> s->cluster_bi= ts); + refcount =3D qcow2_get_refcount(bs, l2_offset >> s->clus= ter_bits); } if (refcount < 0) { ret =3D refcount; @@ -1332,8 +1331,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 wil= l have - * been already detected and sufficiently signaled by the calling functi= on + * check_errors if qcow2_get_refcount fails (this is because such an err= or will + * have been already detected and sufficiently signaled by the calling f= unction * (qcow2_check_refcounts) by the time this function is called). */ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res= , @@ -1354,7 +1353,7 @@ static int check_oflag_copied(BlockDriverState *bs,= BdrvCheckResult *res, continue; } =20 - refcount =3D get_refcount(bs, l2_offset >> s->cluster_bits); + refcount =3D qcow2_get_refcount(bs, l2_offset >> s->cluster_bits= ); if (refcount < 0) { /* don't print message nor increment check_errors */ continue; @@ -1396,7 +1395,8 @@ static int check_oflag_copied(BlockDriverState *bs,= BdrvCheckResult *res, =20 if ((cluster_type =3D=3D QCOW2_CLUSTER_NORMAL) || ((cluster_type =3D=3D QCOW2_CLUSTER_ZERO) && (data_offse= t !=3D 0))) { - refcount =3D get_refcount(bs, data_offset >> s->cluster_= bits); + refcount =3D qcow2_get_refcount(bs, + data_offset >> s->cluster_= bits); if (refcount < 0) { /* don't print message nor increment check_errors */ continue; @@ -1632,7 +1632,7 @@ static void compare_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, int refcount1, refcount2, ret; =20 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 21ac8ce..6e39a1b 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -487,6 +487,8 @@ void qcow2_signal_corruption(BlockDriverState *bs, bo= ol fatal, int64_t offset, 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 cluster_= index, int addend, enum qcow2_discard_type ty= pe); =20 --=20 1.9.3