qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Nir Soffer <nsoffer@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Maor Lipchuk <mlipchuk@redhat.com>,
	"Daniel P. Berrange" <berrange@redhat.com>,
	Eric Blake <eblake@redhat.com>, Alberto Garcia <berto@igalia.com>,
	John Snow <jsnow@redhat.com>
Subject: Re: [Qemu-devel] [RFC v2 1/8] block: add bdrv_measure() API
Date: Sat, 18 Mar 2017 01:28:04 +0000	[thread overview]
Message-ID: <CAMRbyyt8DHj_-7MapWVC9G7+yOGtDra4gRiJDui68mqT9PanpQ@mail.gmail.com> (raw)
In-Reply-To: <20170315092940.1367-2-stefanha@redhat.com>

On Wed, Mar 15, 2017 at 11:29 AM Stefan Hajnoczi <stefanha@redhat.com>
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 <stefanha@redhat.com>
> ---
>  qapi/block-core.json      | 19 +++++++++++++++++++
>  include/block/block.h     |  4 ++++
>  include/block/block_int.h |  2 ++
>  block.c                   | 33 +++++++++++++++++++++++++++++++++
>  4 files changed, 58 insertions(+)
>
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index 786b39e..673569d 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -463,6 +463,25 @@
>             '*dirty-bitmaps': ['BlockDirtyInfo'] } }
>
>  ##
> +# @BlockMeasureInfo:
> +#
> +# Image size calculation information.  This structure describes the size
> +# requirements for creating a new image.
> +#
> +# @required-bytes: Amount of space required for image creation.  This
> value is
> +#                  the host file size including sparse file regions.  A
> new 5
> +#                  GB raw file therefore has a required size of 5 GB, not
> 0
> +#                  bytes.
> +#
> +# @fully-allocated-bytes: Space required once data has been written to all
> +#                         sectors
> +#
> +# Since: 2.10
> +##
> +{ 'struct': 'BlockMeasureInfo',
> +  'data': {'required-bytes': 'int', 'fully-allocated-bytes': 'int'} }
> +
> +##
>  # @query-block:
>  #
>  # Get a list of BlockInfo for all virtual block devices.
> diff --git a/include/block/block.h b/include/block/block.h
> index 5149260..43c789f 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -298,6 +298,10 @@ int bdrv_truncate(BdrvChild *child, int64_t offset);
>  int64_t bdrv_nb_sectors(BlockDriverState *bs);
>  int64_t bdrv_getlength(BlockDriverState *bs);
>  int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
> +void bdrv_measure(BlockDriver *drv, QemuOpts *opts,
> +                  BlockDriverState *in_bs,
> +                  BlockMeasureInfo *info,
>

The struct declaration is missing in this patch, right?


> +                  Error **errp);
>  void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
>  void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
>  int bdrv_commit(BlockDriverState *bs);
> diff --git a/include/block/block_int.h b/include/block/block_int.h
> index 6c699ac..45a7fbe 100644
> --- a/include/block/block_int.h
> +++ b/include/block/block_int.h
> @@ -201,6 +201,8 @@ struct BlockDriver {
>      int64_t (*bdrv_getlength)(BlockDriverState *bs);
>      bool has_variable_length;
>      int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
> +    void (*bdrv_measure)(QemuOpts *opts, BlockDriverState *in_bs,
> +                         BlockMeasureInfo *info, Error **errp);
>
>      int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs,
>          uint64_t offset, uint64_t bytes, QEMUIOVector *qiov);
> diff --git a/block.c b/block.c
> index cb57370..532a4d1 100644
> --- a/block.c
> +++ b/block.c
> @@ -3260,6 +3260,39 @@ int64_t
> bdrv_get_allocated_file_size(BlockDriverState *bs)
>      return -ENOTSUP;
>  }
>
> +/*
> + * bdrv_measure:
> + * @drv: Format driver
> + * @opts: Creation options
> + * @in_bs: Existing image containing data for new image (may be NULL)
> + * @info: Result object
> + * @errp: Error object
> + *
> + * 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.
> + *
> + * 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.
> + */
> +void bdrv_measure(BlockDriver *drv, QemuOpts *opts,
> +                  BlockDriverState *in_bs, BlockMeasureInfo *info,
> +                  Error **errp)
> +{
> +    if (!drv->bdrv_measure) {
> +        error_setg(errp, "Block driver '%s' does not support size
> measurement",
> +                   drv->format_name);
> +        return;
> +    }
> +
> +    drv->bdrv_measure(opts, in_bs, info, errp);
> +}
> +
>  /**
>   * Return number of sectors on success, -errno on error.
>   */
> --
> 2.9.3
>
>

  parent reply	other threads:[~2017-03-18  1:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15  9:29 [Qemu-devel] [RFC v2 0/8] qemu-img: add measure sub-command Stefan Hajnoczi
2017-03-15  9:29 ` [Qemu-devel] [RFC v2 1/8] block: add bdrv_measure() API Stefan Hajnoczi
2017-03-16  1:01   ` Max Reitz
2017-03-16  3:38     ` Stefan Hajnoczi
2017-03-16  4:02       ` Max Reitz
2017-03-18  0:51   ` Nir Soffer
2017-03-20 15:37     ` Stefan Hajnoczi
2017-03-18  1:28   ` Nir Soffer [this message]
2017-03-20 15:34     ` Stefan Hajnoczi
2017-03-15  9:29 ` [Qemu-devel] [RFC v2 2/8] raw-format: add bdrv_measure() support Stefan Hajnoczi
2017-03-18  1:11   ` Nir Soffer
2017-03-15  9:29 ` [Qemu-devel] [RFC v2 3/8] qcow2: extract preallocation calculation function Stefan Hajnoczi
2017-03-16  1:18   ` Max Reitz
2017-03-16  3:40     ` Stefan Hajnoczi
2017-03-15  9:29 ` [Qemu-devel] [RFC v2 4/8] qcow2: extract image creation option parsing Stefan Hajnoczi
2017-03-18 20:14   ` Nir Soffer
2017-03-20 15:40     ` Stefan Hajnoczi
2017-03-15  9:29 ` [Qemu-devel] [RFC v2 5/8] qcow2: add bdrv_measure() support Stefan Hajnoczi
2017-03-16  1:57   ` Max Reitz
2017-03-16  3:41     ` Stefan Hajnoczi
2017-03-15  9:29 ` [Qemu-devel] [RFC v2 6/8] qemu-img: add measure subcommand Stefan Hajnoczi
2017-03-16  1:46   ` Max Reitz
2017-03-16  3:45     ` Stefan Hajnoczi
2017-03-15  9:29 ` [Qemu-devel] [RFC v2 7/8] qemu-iotests: support per-format golden output files Stefan Hajnoczi
2017-03-16  1:51   ` Max Reitz
2017-03-15  9:29 ` [Qemu-devel] [RFC v2 8/8] iotests: add test 178 for qemu-img measure Stefan Hajnoczi
2017-03-18 21:04   ` Nir Soffer
2017-03-20 15:43     ` Stefan Hajnoczi
2017-03-17 23:45 ` [Qemu-devel] [RFC v2 0/8] qemu-img: add measure sub-command Nir Soffer
2017-03-20 15:51   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMRbyyt8DHj_-7MapWVC9G7+yOGtDra4gRiJDui68mqT9PanpQ@mail.gmail.com \
    --to=nsoffer@redhat.com \
    --cc=berrange@redhat.com \
    --cc=berto@igalia.com \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mlipchuk@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).