qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@parallels.com>
To: John Snow <jsnow@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, armbru@redhat.com,
	mreitz@redhat.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v10 06/13] block: Add bdrv_copy_dirty_bitmap and bdrv_clear_dirty_bitmap
Date: Tue, 30 Dec 2014 16:47:35 +0300	[thread overview]
Message-ID: <54A2ACF7.2020302@parallels.com> (raw)
In-Reply-To: <1419297142-24282-7-git-send-email-jsnow@redhat.com>

I'm sorry if it was already discussed, but I think it is inconsistent to 
have "size" in sectors and "granularity" in bytes in one structure. I've 
misused these fields because of this in my current work.

At least, I think there should be comments about this.

Best regards,
Vladimir

On 23.12.2014 04:12, John Snow wrote:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>   block.c               | 39 +++++++++++++++++++++++++++++++++++----
>   include/block/block.h |  4 ++++
>   2 files changed, 39 insertions(+), 4 deletions(-)
>
> diff --git a/block.c b/block.c
> index a1d9e88..f9e0767 100644
> --- a/block.c
> +++ b/block.c
> @@ -53,6 +53,8 @@
>   
>   struct BdrvDirtyBitmap {
>       HBitmap *bitmap;
> +    int64_t size;
> +    int64_t granularity;
>       char *name;
>       QLIST_ENTRY(BdrvDirtyBitmap) list;
>   };
> @@ -5343,6 +5345,21 @@ void bdrv_dirty_bitmap_make_anon(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
>       bitmap->name = NULL;
>   }
>   
> +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BlockDriverState *bs,
> +                                        BdrvDirtyBitmap *bitmap,
> +                                        const char *name)
> +{
> +    BdrvDirtyBitmap *new_bitmap;
> +
> +    new_bitmap = g_malloc0(sizeof(BdrvDirtyBitmap));
> +    new_bitmap->bitmap = hbitmap_copy(bitmap->bitmap);
> +    new_bitmap->size = bitmap->size;
> +    new_bitmap->granularity = bitmap->granularity;
> +    new_bitmap->name = g_strdup(name);
> +    QLIST_INSERT_HEAD(&bs->dirty_bitmaps, new_bitmap, list);
> +    return new_bitmap;
> +}
> +
>   BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
>                                             int granularity,
>                                             const char *name,
> @@ -5350,6 +5367,7 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
>   {
>       int64_t bitmap_size;
>       BdrvDirtyBitmap *bitmap;
> +    int sector_granularity;
>   
>       assert((granularity & (granularity - 1)) == 0);
>   
> @@ -5357,8 +5375,8 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
>           error_setg(errp, "Bitmap already exists: %s", name);
>           return NULL;
>       }
> -    granularity >>= BDRV_SECTOR_BITS;
> -    assert(granularity);
> +    sector_granularity = granularity >> BDRV_SECTOR_BITS;
> +    assert(sector_granularity);
>       bitmap_size = bdrv_nb_sectors(bs);
>       if (bitmap_size < 0) {
>           error_setg_errno(errp, -bitmap_size, "could not get length of device");
> @@ -5366,7 +5384,9 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
>           return NULL;
>       }
>       bitmap = g_new0(BdrvDirtyBitmap, 1);
> -    bitmap->bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1);
> +    bitmap->size = bitmap_size;
> +    bitmap->granularity = granularity;
> +    bitmap->bitmap = hbitmap_alloc(bitmap->size, ffs(sector_granularity) - 1);
>       bitmap->name = g_strdup(name);
>       QLIST_INSERT_HEAD(&bs->dirty_bitmaps, bitmap, list);
>       return bitmap;
> @@ -5439,7 +5459,9 @@ uint64_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs)
>   uint64_t bdrv_dirty_bitmap_granularity(BlockDriverState *bs,
>                                          BdrvDirtyBitmap *bitmap)
>   {
> -    return BDRV_SECTOR_SIZE << hbitmap_granularity(bitmap->bitmap);
> +    g_assert(BDRV_SECTOR_SIZE << hbitmap_granularity(bitmap->bitmap) ==
> +             bitmap->granularity);
> +    return bitmap->granularity;
>   }
>   
>   void bdrv_dirty_iter_init(BlockDriverState *bs,
> @@ -5460,6 +5482,15 @@ void bdrv_reset_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
>       hbitmap_reset(bitmap->bitmap, cur_sector, nr_sectors);
>   }
>   
> +/**
> + * Effectively, reset the hbitmap from bits [0, size)
> + * Synonymous with bdrv_reset_dirty_bitmap(bs, bitmap, 0, bitmap->size)
> + */
> +void bdrv_clear_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
> +{
> +    hbitmap_reset(bitmap->bitmap, 0, bitmap->size);
> +}
> +
>   static void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector,
>                              int nr_sectors)
>   {
> diff --git a/include/block/block.h b/include/block/block.h
> index c7402e7..e964abd 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -436,6 +436,9 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
>   BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
>                                           const char *name);
>   void bdrv_dirty_bitmap_make_anon(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
> +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BlockDriverState *bs,
> +                                        BdrvDirtyBitmap *bitmap,
> +                                        const char *name);
>   void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
>   BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
>   uint64_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
> @@ -446,6 +449,7 @@ void bdrv_set_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
>                              int64_t cur_sector, int nr_sectors);
>   void bdrv_reset_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
>                                int64_t cur_sector, int nr_sectors);
> +void bdrv_clear_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
>   void bdrv_dirty_iter_init(BlockDriverState *bs,
>                             BdrvDirtyBitmap *bitmap, struct HBitmapIter *hbi);
>   int64_t bdrv_get_dirty_count(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);

  reply	other threads:[~2014-12-30 13:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-23  1:12 [Qemu-devel] [PATCH v10 00/13] block: Incremental backup series (RFC) John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 01/13] block: fix spoiling all dirty bitmaps by mirror and migration John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 02/13] qapi: Add optional field "name" to block dirty bitmap John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 03/13] qmp: Add block-dirty-bitmap-add and block-dirty-bitmap-remove John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 04/13] block: Introduce bdrv_dirty_bitmap_granularity() John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 05/13] hbitmap: Add hbitmap_copy John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 06/13] block: Add bdrv_copy_dirty_bitmap and bdrv_clear_dirty_bitmap John Snow
2014-12-30 13:47   ` Vladimir Sementsov-Ogievskiy [this message]
2015-01-10  3:25     ` John Snow
2015-01-13  9:54       ` Vladimir Sementsov-Ogievskiy
2015-01-13 16:37         ` John Snow
2015-01-13 16:43           ` Vladimir Sementsov-Ogievskiy
2015-01-13 16:45             ` John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 07/13] hbitmap: add hbitmap_merge John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 08/13] block: add bdrv_reclaim_dirty_bitmap John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 09/13] qmp: Add block-dirty-bitmap-enable and block-dirty-bitmap-disable John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 10/13] qmp: Add support of "dirty-bitmap" sync mode for drive-backup John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 11/13] qapi: Add transaction support to block-dirty-bitmap-{add, enable, disable} John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 12/13] qmp: Add dirty bitmap 'enabled' field in query-block John Snow
2014-12-23  1:12 ` [Qemu-devel] [PATCH v10 13/13] qemu-iotests: Add tests for drive-backup sync=dirty-bitmap John Snow
2014-12-23 11:48 ` [Qemu-devel] [PATCH v10 00/13] block: Incremental backup series (RFC) Vladimir Sementsov-Ogievskiy
2014-12-23 16:23   ` John Snow

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=54A2ACF7.2020302@parallels.com \
    --to=vsementsov@parallels.com \
    --cc=armbru@redhat.com \
    --cc=famz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@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).