On 2017-06-14 17:35, Stefan Hajnoczi wrote: > bdrv_measure() provides a conservative maximum for the size of a new > image. This information is handy if storage needs to be allocated (e.g. > a SAN or an LVM volume) ahead of time. > > Signed-off-by: Stefan Hajnoczi <[email protected]> > Reviewed-by: Alberto Garcia <[email protected]> > --- > v6: > * Change bdrv_measure() return type to BlockMeasureInfo * [Eric] > * Clarify that holes in sparse POSIX files are still counted [Eric] > --- > qapi/block-core.json | 25 +++++++++++++++++++++++++ > include/block/block.h | 2 ++ > include/block/block_int.h | 2 ++ > block.c | 35 +++++++++++++++++++++++++++++++++++ > 4 files changed, 64 insertions(+)
[...]
> diff --git a/block.c b/block.c
> index fa1d06d..056400a 100644
> --- a/block.c
> +++ b/block.c
> @@ -3446,6 +3446,41 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState
> *bs)
> return -ENOTSUP;
> }
>
> +/*
> + * bdrv_measure:
> + * @drv: Format driver
> + * @opts: Creation options for new image
> + * @in_bs: Existing image containing data for new image (may be NULL)
> + * @errp: Error object
> + * Returns: A #BlockMeasureInfo (free using qapi_free_BlockMeasureInfo())
> + * or NULL on error
> + *
> + * Calculate file size required to create a new image.
> + *
> + * If @in_bs is given then space for allocated clusters and zero clusters
> + * from that image are included in the calculation. If @opts contains a
> + * backing file that is shared by @in_bs then backing clusters are omitted
> + * from the calculation.
Well, it's a bit weird that qcow2 just doesn't do this, then. :-)
I'm not really complaining (I think it's the best for qcow2 to ignore
this, at least for now), but maybe an s/are/may be/ would be more
appropriate...
(I wouldn't have complained if I hadn't replied to patch 7 anyway.)
Max
> + *
> + * If @in_bs is NULL then the calculation includes no allocated clusters
> + * unless a preallocation option is given in @opts.
> + *
> + * Note that @in_bs may use a different BlockDriver from @drv.
> + *
> + * If an error occurs the @errp pointer is set.
> + */
> +BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts,
> + BlockDriverState *in_bs, Error **errp)
> +{
> + if (!drv->bdrv_measure) {
> + error_setg(errp, "Block driver '%s' does not support size
> measurement",
> + drv->format_name);
> + return NULL;
> + }
> +
> + return drv->bdrv_measure(opts, in_bs, errp);
> +}
> +
> /**
> * Return number of sectors on success, -errno on error.
> */
>
signature.asc
Description: OpenPGP digital signature
