On 19/07/2015 11:15, Taeha Kim wrote:
> However, the "ls", “stat”, and “du” utility still don't know how many
> change size of image is changed.

That's not a bug.  qcow2 images only need as much space as required,
plus some for the metadata.  This lets you use small files, and copy
them around without relying on the filesystem's support for sparse files.

> In addtion, "file" utility sometimes don't know qcow2 image format's
> version as follows.
> 
> $ file 100G.qcow2
> 100G.qcow2: QEMU QCOW Image (Unknown)

Use qemu-img info instead, or report a bug for the file utility.

The patch below does not work correctly because:

1) bs->filename is not always valid;

2) even if bs->filename is valid, truncate() does not apply to all
backends, for example it cannot be applied to the backends where
bs->filename is a URL;

3) it can corrupt the image if it is larger than the requested size (for
example because of the metadata).

Paolo

> diff --git a/block.c b/block.c
> index d088ee0..93427f8 100644
> --- a/block.c
> +++ b/block.c
> @@ -2529,6 +2529,9 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
>         if (bs->blk) {
>             blk_dev_resize_cb(bs->blk);
>         }
> +       if (ret == 0) {
> +           ret = truncate(bs->filename, offset);
> +       }
>     }
>     return ret;
> }

Reply via email to