On Sat, Jun 4, 2011 at 1:44 AM, Fam Zheng <famc...@gmail.com> wrote: > The `qemu-img info` results for mono flat image are no longer > accurate, as the "disk size" was the length of bs->file, which is not > the case for multi file images (such as vmdk images with multiple > files). > The new field disk_size in BlockDriverState can be used by block > driver to tell the exact disk size of block image (only valid if the > field is set to non-zero). > > Signed-off-by: Fam Zheng <famc...@gmail.com> > --- > block/vmdk.c | 1 + > block_int.h | 1 + > qemu-img.c | 6 +++++- > 3 files changed, 7 insertions(+), 1 deletions(-)
Instead of introducing a variable please add a new BlockDriver .bdrv_get_allocated_file_size() function pointer and move get_allocated_file_size() from qemu-img.c into block/raw-posix.c and block/raw-win32.c. qemu-img.c should call bdrv_get_allocated_file_size() and bdrv_get_allocated_file_size() could look like this: int bdrv_get_allocated_file_size(BlockDriverState *bs, int64_t *size) { BlockDriver *drv = bs->drv; if (!drv) { return -ENOMEDIUM; } if (drv->bdrv_get_allocated_file_size) { return drv->bdrv_get_allocated_file_size(bs, size); } if (bs->file) { return bdrv_get_allocated_file_size(bs->file, size); } return -ENOTSUP; } > @@ -607,6 +607,7 @@ static int vmdk_open_desc_file(BlockDriverState > *bs, int flags) > extent = s->extents; > vmdk_parse_extents(buf, s->extents, bs->file->filename); > bs->total_sectors = extent->sectors; > + bs->disk_size = bdrv_getlength(bs->file) + bdrv_getlength(extent->file); This should call bdrv_get_allocated_file_size() so add together the actually allocated amount, not what bdrv_getlength() returns. Stefan