summaryrefslogtreecommitdiffstats
path: root/block/vmdk.c
diff options
context:
space:
mode:
authorFam Zheng <famcool@gmail.com>2011-07-12 19:56:39 +0800
committerKevin Wolf <kwolf@redhat.com>2011-07-19 15:39:08 +0200
commit4a1d5e1fded54358ddc4d8cbd53388ca7c93499b (patch)
treee317502ecc47e7cf31ab53bbc3f4dd2c9b92c7f0 /block/vmdk.c
parentae261c86aaed62e7acddafab8262a2bf286d40b7 (diff)
downloadhqemu-4a1d5e1fded54358ddc4d8cbd53388ca7c93499b.zip
hqemu-4a1d5e1fded54358ddc4d8cbd53388ca7c93499b.tar.gz
block: add bdrv_get_allocated_file_size() operation
qemu-img.c wants to count allocated file size of image. Previously it counts a single bs->file by 'stat' or Window API. As VMDK introduces multiple file support, the operation becomes format specific with platform specific meanwhile. The functions are moved to block/raw-{posix,win32}.c and qemu-img.c calls bdrv_get_allocated_file_size to count the bs. And also added VMDK code to count his own extents. Signed-off-by: Fam Zheng <famcool@gmail.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/vmdk.c')
-rw-r--r--block/vmdk.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/block/vmdk.c b/block/vmdk.c
index de08d0c..37478d2 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1289,6 +1289,29 @@ static int vmdk_flush(BlockDriverState *bs)
return ret;
}
+static int64_t vmdk_get_allocated_file_size(BlockDriverState *bs)
+{
+ int i;
+ int64_t ret = 0;
+ int64_t r;
+ BDRVVmdkState *s = bs->opaque;
+
+ ret = bdrv_get_allocated_file_size(bs->file);
+ if (ret < 0) {
+ return ret;
+ }
+ for (i = 0; i < s->num_extents; i++) {
+ if (s->extents[i].file == bs->file) {
+ continue;
+ }
+ r = bdrv_get_allocated_file_size(s->extents[i].file);
+ if (r < 0) {
+ return r;
+ }
+ ret += r;
+ }
+ return ret;
+}
static QEMUOptionParameter vmdk_create_options[] = {
{
@@ -1327,6 +1350,7 @@ static BlockDriver bdrv_vmdk = {
.bdrv_create = vmdk_create,
.bdrv_flush = vmdk_flush,
.bdrv_is_allocated = vmdk_is_allocated,
+ .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
.create_options = vmdk_create_options,
};
OpenPOWER on IntegriCloud