Skip to content

Commit

Permalink
qemu-img: add image fragmentation statistics
Browse files Browse the repository at this point in the history
Discussion can be found at:
http://patchwork.ozlabs.org/patch/128730/

This patch add image fragmentation statistics while using qemu-img check.

Signed-off-by: Dong Xu Wang <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
pickick authored and kevmw committed Apr 5, 2012
1 parent dc534f8 commit f8111c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions block.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ typedef struct BlockDriverInfo {
int64_t vm_state_offset;
} BlockDriverInfo;

typedef struct BlockFragInfo {
uint64_t allocated_clusters;
uint64_t total_clusters;
uint64_t fragmented_clusters;
} BlockFragInfo;

typedef struct QEMUSnapshotInfo {
char id_str[128]; /* unique snapshot id */
/* the following fields are informative. They are not needed for
Expand Down Expand Up @@ -175,6 +181,7 @@ typedef struct BdrvCheckResult {
int corruptions;
int leaks;
int check_errors;
BlockFragInfo bfi;
} BdrvCheckResult;

int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res);
Expand Down
9 changes: 8 additions & 1 deletion qemu-img.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ static int img_check(int argc, char **argv)
}
}

if (result.bfi.total_clusters != 0 && result.bfi.allocated_clusters != 0) {
printf("%" PRId64 "/%" PRId64 "= %0.2f%% allocated, %0.2f%% fragmented\n",
result.bfi.allocated_clusters, result.bfi.total_clusters,
result.bfi.allocated_clusters * 100.0 / result.bfi.total_clusters,
result.bfi.fragmented_clusters * 100.0 / result.bfi.allocated_clusters);
}

bdrv_delete(bs);

if (ret < 0 || result.check_errors) {
Expand Down Expand Up @@ -716,7 +723,7 @@ static int img_convert(int argc, char **argv)
ret = -1;
goto out;
}

qemu_progress_init(progress, 2.0);
qemu_progress_print(0, 100);

Expand Down

0 comments on commit f8111c2

Please sign in to comment.