[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
signature.asc
Description: PGP signature
- Re: [Qemu-devel] [RFC v2 1/8] block: add bdrv_measure() API, (continued)
- [Qemu-devel] [RFC v2 2/8] raw-format: add bdrv_measure() support, Stefan Hajnoczi, 2017/03/15
- [Qemu-devel] [RFC v2 3/8] qcow2: extract preallocation calculation function, Stefan Hajnoczi, 2017/03/15
- [Qemu-devel] [RFC v2 5/8] qcow2: add bdrv_measure() support, Stefan Hajnoczi, 2017/03/15
- [Qemu-devel] [RFC v2 4/8] qcow2: extract image creation option parsing, Stefan Hajnoczi, 2017/03/15
- [Qemu-devel] [RFC v2 6/8] qemu-img: add measure subcommand, Stefan Hajnoczi, 2017/03/15
- [Qemu-devel] [RFC v2 7/8] qemu-iotests: support per-format golden output files, Stefan Hajnoczi, 2017/03/15
- [Qemu-devel] [RFC v2 8/8] iotests: add test 178 for qemu-img measure, Stefan Hajnoczi, 2017/03/15