summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorFederico Simoncelli <fsimonce@redhat.com>2013-01-28 06:59:46 -0500
committerKevin Wolf <kwolf@redhat.com>2013-02-22 21:21:08 +0100
commitc6bb9ad198c2caa9c7c8ba360a07630b5c10e4a8 (patch)
treefb7d050ec41a145e93d9a677c4136e880879fc59 /block
parent5cbb08283789caf7dbfd0890dcff47124ad766c2 (diff)
downloadqemu-c6bb9ad198c2caa9c7c8ba360a07630b5c10e4a8.tar.gz
qemu-c6bb9ad198c2caa9c7c8ba360a07630b5c10e4a8.tar.bz2
qemu-c6bb9ad198c2caa9c7c8ba360a07630b5c10e4a8.zip
qemu-img: find the image end offset during check
This patch adds the support for reporting the image end offset (in bytes). This is particularly useful after a conversion (or a rebase) where the destination is a block device in order to find the first unused byte at the end of the image. Signed-off-by: Federico Simoncelli <fsimonce@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/qcow2-refcount.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index bc1784c30e..d36cb4dd2f 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -1112,7 +1112,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
BdrvCheckMode fix)
{
BDRVQcowState *s = bs->opaque;
- int64_t size, i;
+ int64_t size, i, highest_cluster;
int nb_clusters, refcount1, refcount2;
QCowSnapshot *sn;
uint16_t *refcount_table;
@@ -1183,7 +1183,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
}
/* compare ref counts */
- for(i = 0; i < nb_clusters; i++) {
+ for (i = 0, highest_cluster = 0; i < nb_clusters; i++) {
refcount1 = get_refcount(bs, i);
if (refcount1 < 0) {
fprintf(stderr, "Can't get refcount for cluster %" PRId64 ": %s\n",
@@ -1193,6 +1193,11 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
}
refcount2 = refcount_table[i];
+
+ if (refcount1 > 0 || refcount2 > 0) {
+ highest_cluster = i;
+ }
+
if (refcount1 != refcount2) {
/* Check if we're allowed to fix the mismatch */
@@ -1227,6 +1232,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
}
}
+ res->image_end_offset = (highest_cluster + 1) * s->cluster_size;
ret = 0;
fail: