[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 40/53] block/qcow2: Make get_refcount() global
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 40/53] block/qcow2: Make get_refcount() global |
Date: |
Mon, 3 Nov 2014 11:50:43 +0000 |
From: Max Reitz <address@hidden>
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: BenoƮt Canet <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Reviewed-by: Benoit Canet <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
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 -errno
* 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 = bs->opaque;
uint64_t refcount_table_index, block_index;
@@ -629,8 +629,7 @@ fail:
}
/*
- * 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.
@@ -649,7 +648,7 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs,
return ret;
}
- return get_refcount(bs, cluster_index);
+ return qcow2_get_refcount(bs, cluster_index);
}
@@ -670,7 +669,7 @@ static int64_t alloc_clusters_noref(BlockDriverState *bs,
uint64_t size)
retry:
for(i = 0; i < nb_clusters; i++) {
uint64_t next_cluster_index = s->free_cluster_index++;
- refcount = get_refcount(bs, next_cluster_index);
+ refcount = qcow2_get_refcount(bs, next_cluster_index);
if (refcount < 0) {
return refcount;
@@ -734,7 +733,7 @@ int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t
offset,
/* Check how many clusters there are free */
cluster_index = offset >> s->cluster_bits;
for(i = 0; i < nb_clusters; i++) {
- refcount = get_refcount(bs, cluster_index++);
+ refcount = qcow2_get_refcount(bs, cluster_index++);
if (refcount < 0) {
return refcount;
@@ -981,7 +980,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
cluster_index, addend,
QCOW2_DISCARD_SNAPSHOT);
} else {
- refcount = get_refcount(bs, cluster_index);
+ refcount = qcow2_get_refcount(bs, cluster_index);
}
if (refcount < 0) {
@@ -1021,7 +1020,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
refcount = qcow2_update_cluster_refcount(bs, l2_offset >>
s->cluster_bits, addend, QCOW2_DISCARD_SNAPSHOT);
} else {
- refcount = get_refcount(bs, l2_offset >> s->cluster_bits);
+ refcount = qcow2_get_refcount(bs, l2_offset >>
s->cluster_bits);
}
if (refcount < 0) {
ret = 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 will have
- * been already detected and sufficiently signaled by the calling function
+ * check_errors if qcow2_get_refcount fails (this is because such an error 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 *res,
@@ -1354,7 +1353,7 @@ static int check_oflag_copied(BlockDriverState *bs,
BdrvCheckResult *res,
continue;
}
- refcount = get_refcount(bs, l2_offset >> s->cluster_bits);
+ refcount = 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,
if ((cluster_type == QCOW2_CLUSTER_NORMAL) ||
((cluster_type == QCOW2_CLUSTER_ZERO) && (data_offset != 0))) {
- refcount = get_refcount(bs, data_offset >> s->cluster_bits);
+ refcount = 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;
for (i = 0, *highest_cluster = 0; i < nb_clusters; i++) {
- refcount1 = get_refcount(bs, i);
+ refcount1 = 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, bool
fatal, int64_t offset,
int qcow2_refcount_init(BlockDriverState *bs);
void qcow2_refcount_close(BlockDriverState *bs);
+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 type);
--
1.9.3
- [Qemu-devel] [PULL 30/53] qemu-img: Enable progress output for commit, (continued)
- [Qemu-devel] [PULL 30/53] qemu-img: Enable progress output for commit, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 31/53] qemu-img: Specify backing file for commit, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 32/53] iotests: Add _filter_qemu_img_map, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 33/53] iotests: Add test for backing-chain commits, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 34/53] iotests: Add test for qcow2's bdrv_make_empty, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 36/53] block: Add status callback to bdrv_amend_options(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 35/53] block: qemu-iotest 107 supports NFS, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 37/53] qemu-img: Add progress output for amend, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 38/53] qemu-img: Fix insignificant memleak, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 39/53] block/qcow2: Implement status CB for amend, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 40/53] block/qcow2: Make get_refcount() global,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 41/53] block/qcow2: Simplify shared L2 handling in amend, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 42/53] iotests: Expand test 061, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 43/53] block: acquire AioContext in generic blockjob QMP commands, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 44/53] blockdev: acquire AioContext in do_qmp_query_block_jobs_one(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 45/53] blockdev: acquire AioContext in blockdev_mark_auto_del(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 46/53] blockdev: add note that block_job_cb() must be thread-safe, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 47/53] blockjob: add block_job_defer_to_main_loop(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 48/53] block: add bdrv_drain(), Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 49/53] block: let backup blockjob run in BDS AioContext, Stefan Hajnoczi, 2014/11/03
- [Qemu-devel] [PULL 50/53] block: let stream blockjob run in BDS AioContext, Stefan Hajnoczi, 2014/11/03