qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: John Snow <jsnow@redhat.com>, qemu-block@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org,
	armbru@redhat.com, vsementsov@parallels.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4 04/20] qmp: Add block-dirty-bitmap-add and block-dirty-bitmap-remove
Date: Fri, 20 Mar 2015 15:39:43 -0400	[thread overview]
Message-ID: <550C777F.8050707@redhat.com> (raw)
In-Reply-To: <1426879023-18151-5-git-send-email-jsnow@redhat.com>

On 2015-03-20 at 15:16, John Snow wrote:
> The new command pair is added to manage a user created dirty bitmap. The
> dirty bitmap's name is mandatory and must be unique for the same device,
> but different devices can have bitmaps with the same names.
>
> The granularity is an optional field. If it is not specified, we will
> choose a default granularity based on the cluster size if available,
> clamped to between 4K and 64K to mirror how the 'mirror' code was
> already choosing granularity. If we do not have cluster size info
> available, we choose 64K. This code has been factored out into a helper
> shared with block/mirror.
>
> This patch also introduces the 'block_dirty_bitmap_lookup' helper,
> which takes a device name and a dirty bitmap name and validates the
> lookup, returning NULL and setting errp if there is a problem with
> either field. This helper will be re-used in future patches in this
> series.
>
> The types added to block-core.json will be re-used in future patches
> in this series, see:
> 'qapi: Add transaction support to block-dirty-bitmap-{add, enable, disable}'
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>   block.c               |  20 +++++++++
>   block/mirror.c        |  10 +----
>   blockdev.c            | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   include/block/block.h |   1 +
>   qapi/block-core.json  |  55 ++++++++++++++++++++++++
>   qmp-commands.hx       |  56 ++++++++++++++++++++++++
>   6 files changed, 250 insertions(+), 9 deletions(-)
>
> diff --git a/block.c b/block.c
> index a05971a..c5d68ff 100644
> --- a/block.c
> +++ b/block.c
> @@ -5497,6 +5497,26 @@ int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector
>       }
>   }
>   
> +/**
> + * Chooses a default granularity based on the existing cluster size,
> + * but clamped between [4K, 64K]. Defaults to 64K in the case that there
> + * is no cluster size information available.
> + */
> +uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs)
> +{
> +    BlockDriverInfo bdi;
> +    uint32_t granularity;
> +
> +    if (bdrv_get_info(bs, &bdi) >= 0 && bdi.cluster_size > 0) {
> +        granularity = MAX(4096, bdi.cluster_size);
> +        granularity = MIN(65536, granularity);
> +    } else {
> +        granularity = 65536;
> +    }
> +
> +    return granularity;
> +}
> +
>   void bdrv_dirty_iter_init(BlockDriverState *bs,
>                             BdrvDirtyBitmap *bitmap, HBitmapIter *hbi)
>   {
> diff --git a/block/mirror.c b/block/mirror.c
> index f8aac33..1cb700e 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -668,15 +668,7 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
>       MirrorBlockJob *s;
>   
>       if (granularity == 0) {
> -        /* Choose the default granularity based on the target file's cluster
> -         * size, clamped between 4k and 64k.  */
> -        BlockDriverInfo bdi;
> -        if (bdrv_get_info(target, &bdi) >= 0 && bdi.cluster_size != 0) {
> -            granularity = MAX(4096, bdi.cluster_size);
> -            granularity = MIN(65536, granularity);
> -        } else {
> -            granularity = 65536;
> -        }
> +        granularity = bdrv_get_default_bitmap_granularity(target);
>       }
>   
>       assert ((granularity & (granularity - 1)) == 0);
> diff --git a/blockdev.c b/blockdev.c
> index fbb3a79..7d71b81 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -1164,6 +1164,68 @@ out_aio_context:
>       return NULL;
>   }
>   
> +/**
> + * block_dirty_bitmap_lookup:
> + * Return a dirty bitmap (if present), after validating
> + * the node reference and bitmap names.
> + *
> + * @node: The name of the BDS node to search for bitmaps
> + * @name: The name of the bitmap to search for
> + * @pbs: Output pointer for BDS lookup, if desired. Can be NULL.
> + * @paio: Output pointer for aio_context acquisition, if desired. Can be NULL.
> + * @errp: Output pointer for error information. Can be NULL.
> + *
> + * @return: A bitmap object on success, or NULL on failure.
> + */
> +static BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node,
> +                                                  const char *name,
> +                                                  BlockDriverState **pbs,
> +                                                  AioContext **paio,
> +                                                  Error **errp)
> +{
> +    BlockDriverState *bs;
> +    BdrvDirtyBitmap *bitmap;
> +    AioContext *aio_context;
> +
> +    if (!node) {
> +        error_setg(errp, "Node cannot be NULL");
> +        return NULL;
> +    }
> +    if (!name) {
> +        error_setg(errp, "Bitmap name cannot be NULL");
> +        return NULL;
> +    }
> +    bs = bdrv_lookup_bs(node, node, NULL);
> +    if (!bs) {
> +        error_setg(errp, "Node '%s' not found", node);
> +        return NULL;
> +    }
> +
> +    aio_context = bdrv_get_aio_context(bs);
> +    aio_context_acquire(aio_context);
> +
> +    bitmap = bdrv_find_dirty_bitmap(bs, name);
> +    if (!bitmap) {
> +        error_setg(errp, "Dirty bitmap '%s' not found", name);
> +        goto fail;
> +    }
> +
> +    if (pbs) {
> +        *pbs = bs;
> +    }
> +    if (paio) {
> +        *paio = aio_context;
> +    } else {
> +        aio_context_release(aio_context);
> +    }
> +
> +    return bitmap;
> +
> + fail:
> +    aio_context_release(aio_context);
> +    return NULL;
> +}
> +
>   /* New and old BlockDriverState structs for atomic group operations */
>   
>   typedef struct BlkTransactionState BlkTransactionState;
> @@ -1953,6 +2015,61 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
>       aio_context_release(aio_context);
>   }
>   
> +void qmp_block_dirty_bitmap_add(const char *node, const char *name,
> +                                bool has_granularity, uint32_t granularity,
> +                                Error **errp)
> +{
> +    AioContext *aio_context;
> +    BlockDriverState *bs;
> +
> +    if (!name || name[0] == '\0') {
> +        error_setg(errp, "Bitmap name cannot be empty");
> +        return;
> +    }
> +
> +    bs = bdrv_lookup_bs(node, node, errp);
> +    if (!bs) {
> +        return;
> +    }
> +
> +    aio_context = bdrv_get_aio_context(bs);
> +    aio_context_acquire(aio_context);
> +
> +    if (has_granularity) {
> +        if (granularity < 512 || !is_power_of_2(granularity)) {
> +            error_setg(errp, "Granularity must be power of 2 "
> +                             "and at least 512");
> +            goto out;
> +        }
> +    } else {
> +        /* Default to cluster size, if available: */
> +        granularity = bdrv_get_default_bitmap_granularity(bs);
> +    }
> +
> +    bdrv_create_dirty_bitmap(bs, granularity, name, errp);
> +
> + out:
> +    aio_context_release(aio_context);
> +}
> +
> +void qmp_block_dirty_bitmap_remove(const char *node, const char *name,
> +                                   Error **errp)
> +{
> +    AioContext *aio_context;
> +    BlockDriverState *bs;
> +    BdrvDirtyBitmap *bitmap;
> +
> +    bitmap = block_dirty_bitmap_lookup(node, name, &bs, &aio_context, errp);
> +    if (!bitmap || !bs) {

Is there actually a way for bs to be NULL if bitmap is non-NULL? In 
fact, bs is never set to NULL by block_dirty_bitmap_lookup(), so it's 
either uninitialized or valid. If you have to respin for some reason or 
another, I think it would be nice to drop the !bs part.

Because bitmap != NULL always means bs is valid, though, this is not 
wrong, and thus with or without it:

Reviewed-by: Max Reitz <mreitz@redhat.com>

> +        return;
> +    }
> +
> +    bdrv_dirty_bitmap_make_anon(bs, bitmap);
> +    bdrv_release_dirty_bitmap(bs, bitmap);
> +
> +    aio_context_release(aio_context);
> +}
> +
>   int hmp_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
>   {
>       const char *id = qdict_get_str(qdict, "id");
> diff --git a/include/block/block.h b/include/block/block.h
> index 5235086..0f014a3 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -458,6 +458,7 @@ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
>   void bdrv_dirty_bitmap_make_anon(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
>   void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
>   BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
> +uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
>   int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector);
>   void bdrv_set_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
>                              int64_t cur_sector, int nr_sectors);
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index 42c9d75..faadd10 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -960,6 +960,61 @@
>               '*on-target-error': 'BlockdevOnError' } }
>   
>   ##
> +# @BlockDirtyBitmap
> +#
> +# @node: name of device/node which the bitmap is tracking
> +#
> +# @name: name of the dirty bitmap
> +#
> +# Since 2.4
> +##
> +{ 'type': 'BlockDirtyBitmap',
> +  'data': { 'node': 'str', 'name': 'str' } }
> +
> +##
> +# @BlockDirtyBitmapAdd
> +#
> +# @node: name of device/node which the bitmap is tracking
> +#
> +# @name: name of the dirty bitmap
> +#
> +# @granularity: #optional the bitmap granularity, default is 64k for
> +#               block-dirty-bitmap-add
> +#
> +# Since 2.4
> +##
> +{ 'type': 'BlockDirtyBitmapAdd',
> +  'data': { 'node': 'str', 'name': 'str', '*granularity': 'uint32' } }
> +
> +##
> +# @block-dirty-bitmap-add
> +#
> +# Create a dirty bitmap with a name on the node
> +#
> +# Returns: nothing on success
> +#          If @node is not a valid block device or node, DeviceNotFound
> +#          If @name is already taken, GenericError with an explanation
> +#
> +# Since 2.4
> +##
> +{ 'command': 'block-dirty-bitmap-add',
> +  'data': 'BlockDirtyBitmapAdd' }
> +
> +##
> +# @block-dirty-bitmap-remove
> +#
> +# Remove a dirty bitmap on the node
> +#
> +# Returns: nothing on success
> +#          If @node is not a valid block device or node, DeviceNotFound
> +#          If @name is not found, GenericError with an explanation
> +#
> +# Since 2.4
> +##
> +{ 'command': 'block-dirty-bitmap-remove',
> +  'data': 'BlockDirtyBitmap' }
> +
> +##
>   # @block_set_io_throttle:
>   #
>   # Change I/O throttle limits for a block drive.
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 7f68760..e9f2eb1 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -1270,6 +1270,62 @@ Example:
>   EQMP
>   
>       {
> +        .name       = "block-dirty-bitmap-add",
> +        .args_type  = "node:B,name:s,granularity:i?",
> +        .mhandler.cmd_new = qmp_marshal_input_block_dirty_bitmap_add,
> +    },
> +
> +SQMP
> +
> +block-dirty-bitmap-add
> +----------------------
> +Since 2.4
> +
> +Create a dirty bitmap with a name on the device, and start tracking the writes.
> +
> +Arguments:
> +
> +- "node": device/node on which to create dirty bitmap (json-string)
> +- "name": name of the new dirty bitmap (json-string)
> +- "granularity": granularity to track writes with (int, optional)
> +
> +Example:
> +
> +-> { "execute": "block-dirty-bitmap-add", "arguments": { "node": "drive0",
> +                                                   "name": "bitmap0" } }
> +<- { "return": {} }
> +
> +EQMP
> +
> +    {
> +        .name       = "block-dirty-bitmap-remove",
> +        .args_type  = "node:B,name:s",
> +        .mhandler.cmd_new = qmp_marshal_input_block_dirty_bitmap_remove,
> +    },
> +
> +SQMP
> +
> +block-dirty-bitmap-remove
> +-------------------------
> +Since 2.4
> +
> +Stop write tracking and remove the dirty bitmap that was created with
> +block-dirty-bitmap-add.
> +
> +Arguments:
> +
> +- "node": device/node on which to remove dirty bitmap (json-string)
> +- "name": name of the dirty bitmap to remove (json-string)
> +
> +Example:
> +
> +-> { "execute": "block-dirty-bitmap-remove", "arguments": { "node": "drive0",
> +                                                      "name": "bitmap0" } }
> +<- { "return": {} }
> +
> +EQMP
> +
> +    {
>           .name       = "blockdev-snapshot-sync",
>           .args_type  = "device:s?,node-name:s?,snapshot-file:s,snapshot-node-name:s?,format:s?,mode:s?",
>           .mhandler.cmd_new = qmp_marshal_input_blockdev_snapshot_sync,

  reply	other threads:[~2015-03-20 19:39 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-20 19:16 [Qemu-devel] [PATCH v4 00/20] block: transactionless incremental backup series John Snow
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 01/20] docs: incremental backup documentation John Snow
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 02/20] qapi: Add optional field "name" to block dirty bitmap John Snow
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 03/20] qmp: Ensure consistent granularity type John Snow
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 04/20] qmp: Add block-dirty-bitmap-add and block-dirty-bitmap-remove John Snow
2015-03-20 19:39   ` Max Reitz [this message]
2015-04-02  9:57   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 05/20] block: Introduce bdrv_dirty_bitmap_granularity() John Snow
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 06/20] hbitmap: cache array lengths John Snow
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 07/20] hbitmap: add hbitmap_merge John Snow
2015-04-02 12:19   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 08/20] block: Add bitmap disabled status John Snow
2015-04-02 12:21   ` Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 09/20] block: Add bitmap successors John Snow
2015-04-02 12:23   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 10/20] qmp: Add support of "dirty-bitmap" sync mode for drive-backup John Snow
2015-04-02 12:44   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-04-02 16:55     ` John Snow
2015-04-08  2:15     ` John Snow
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 11/20] qmp: add block-dirty-bitmap-clear John Snow
2015-04-02 12:49   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 12/20] qmp: Add dirty bitmap status field in query-block John Snow
2015-04-02 12:49   ` Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 13/20] block: add BdrvDirtyBitmap documentation John Snow
2015-04-02 12:50   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 14/20] block: Ensure consistent bitmap function prototypes John Snow
2015-04-02 12:50   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 15/20] block: Resize bitmaps on bdrv_truncate John Snow
2015-04-02 13:37   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-04-02 15:57     ` John Snow
2015-04-07 12:57       ` Stefan Hajnoczi
2015-04-07 16:45         ` John Snow
2015-04-08  8:44           ` Stefan Hajnoczi
2015-03-20 19:16 ` [Qemu-devel] [PATCH v4 16/20] hbitmap: truncate tests John Snow
2015-03-20 19:43   ` Max Reitz
2015-04-02 13:43   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:17 ` [Qemu-devel] [PATCH v4 17/20] iotests: add invalid input incremental backup tests John Snow
2015-03-20 19:49   ` Max Reitz
2015-04-02 13:44   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:17 ` [Qemu-devel] [PATCH v4 18/20] iotests: add QMP event waiting queue John Snow
2015-04-02 13:57   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-04-02 17:19     ` John Snow
2015-03-20 19:17 ` [Qemu-devel] [PATCH v4 19/20] iotests: add simple incremental backup case John Snow
2015-03-20 19:50   ` Max Reitz
2015-04-02 14:27   ` Stefan Hajnoczi
2015-04-06 21:49     ` John Snow
2015-04-07 13:00       ` Stefan Hajnoczi
2015-04-13 16:51       ` Max Reitz
2015-03-20 19:17 ` [Qemu-devel] [PATCH v4 20/20] iotests: add incremental backup failure recovery test John Snow
2015-03-20 19:51   ` Max Reitz
2015-04-02 14:52   ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2015-03-20 19:52 ` [Qemu-devel] [PATCH v4 00/20] block: transactionless incremental backup series Max Reitz
2015-03-20 19:57   ` John Snow
2015-04-02 14:53 ` [Qemu-devel] [Qemu-block] " 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=550C777F.8050707@redhat.com \
    --to=mreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=famz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vsementsov@parallels.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).