qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC v2 5/8] qcow2: add bdrv_measure() support


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [RFC v2 5/8] qcow2: add bdrv_measure() support
Date: Thu, 16 Mar 2017 11:41:07 +0800
User-agent: Mutt/1.7.1 (2016-10-04)

On Thu, Mar 16, 2017 at 02:57:13AM +0100, Max Reitz wrote:
> On 15.03.2017 10:29, Stefan Hajnoczi wrote:
> > Use qcow2_calc_prealloc_size() to get the required file size.
> > 
> > Signed-off-by: Stefan Hajnoczi <address@hidden>
> > ---
> > TODO:
> >  * Query block status and only count allocated clusters if in_bs != NULL
> >  * Exclude backing file clusters if in_bs != NULL and -o backing_file=
> >    is given
> > ---
> >  block/qcow2.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 53 insertions(+)
> > 
> > diff --git a/block/qcow2.c b/block/qcow2.c
> > index 19be468..a4caf97 100644
> > --- a/block/qcow2.c
> > +++ b/block/qcow2.c
> > @@ -2940,6 +2940,58 @@ static coroutine_fn int 
> > qcow2_co_flush_to_os(BlockDriverState *bs)
> >      return 0;
> >  }
> >  
> > +static void qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
> > +                          BlockMeasureInfo *info, Error **errp)
> > +{
> > +    Error *local_err = NULL;
> > +    uint64_t allocated_bytes = 0;
> > +    uint64_t prealloc_size;
> > +    uint64_t size;
> > +    uint64_t refcount_bits;
> > +    size_t cluster_size;
> > +    int version;
> > +
> > +    size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
> > +                    BDRV_SECTOR_SIZE);
> > +
> > +    cluster_size = qcow2_opt_get_cluster_size_del(opts, &local_err);
> > +    if (local_err) {
> > +        goto err;
> > +    }
> > +
> > +    version = qcow2_opt_get_version_del(opts, &local_err);
> > +    if (local_err) {
> > +        goto err;
> > +    }
> > +
> > +    refcount_bits = qcow2_opt_get_refcount_bits_del(opts, version, 
> > &local_err);
> > +    if (local_err) {
> > +        goto err;
> > +    }
> > +
> > +    if (in_bs) {
> > +        int64_t ssize = bdrv_getlength(in_bs);
> > +        if (ssize < 0) {
> > +            error_setg_errno(errp, -ssize, "Unable to get image size");
> > +            return;
> > +        }
> > +
> > +        size = ssize;
> > +
> > +        /* TODO How many clusters are allocated modulo backing file in 
> > opts? */
> > +    }
> > +
> > +    prealloc_size = qcow2_calc_prealloc_size(size, cluster_size,
> > +                                             ctz32(refcount_bits));
> > +    info->required_bytes = prealloc_size - (align_offset(size, 
> > cluster_size) -
> > +                                            allocated_bytes);
> 
> But what if @opts contains a preallocation option?

Will implement in the next revision.

Thanks,
Stefan

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]