[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 5/9] hbitmap: Add hbitmap_copy
From: |
Benoît Canet |
Subject: |
Re: [Qemu-devel] [PATCH v2 5/9] hbitmap: Add hbitmap_copy |
Date: |
Thu, 13 Mar 2014 14:45:36 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
The Wednesday 12 Mar 2014 à 14:31:00 (+0800), Fam Zheng wrote :
> This makes a deep copy of an HBitmap.
>
> Signed-off-by: Fam Zheng <address@hidden>
> ---
> include/qemu/hbitmap.h | 8 ++++++++
> util/hbitmap.c | 13 +++++++++++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
> index 550d7ce..b645cfc 100644
> --- a/include/qemu/hbitmap.h
> +++ b/include/qemu/hbitmap.h
> @@ -65,6 +65,14 @@ struct HBitmapIter {
> HBitmap *hbitmap_alloc(uint64_t size, int granularity);
>
> /**
> + * hbitmap_copy:
> + * @bitmap: The original bitmap to copy.
> + *
> + * Copy a HBitmap.
> + */
> +HBitmap *hbitmap_copy(const HBitmap *bitmap);
> +
> +/**
> * hbitmap_empty:
> * @hb: HBitmap to operate on.
> *
> diff --git a/util/hbitmap.c b/util/hbitmap.c
> index d936831..cf670c7 100644
> --- a/util/hbitmap.c
> +++ b/util/hbitmap.c
> @@ -400,3 +400,16 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity)
> hb->levels[0][0] |= 1UL << (BITS_PER_LONG - 1);
> return hb;
> }
> +
> +HBitmap *hbitmap_copy(const HBitmap *bitmap)
> +{
> + int i;
> + HBitmap *hb = g_memdup(bitmap, sizeof(struct HBitmap));
> +
> + for (i = HBITMAP_LEVELS; i-- > 0; ) {
> + hb->levels[i] = g_memdup(bitmap->levels[i],
> + bitmap->size * sizeof(unsigned long));
This feel wrong:
struct HBitmap {
/* Number of total bits in the bottom level. */
uint64_t size;
The comment about size imply that size apply only to the bottom level.
Moreover the bitmaps are progressivelly less coarse so I think the size you use
should goes down as you go up to the top.
Best regards
Benoît
> + }
> +
> + return hb;
> +}
> --
> 1.9.0
>
>
- Re: [Qemu-devel] [PATCH v2 2/9] qmp: Add dirty-bitmap-add and dirty-bitmap-remove, (continued)
[Qemu-devel] [PATCH v2 3/9] block: Handle error of bdrv_getlength in bdrv_create_dirty_bitmap, Fam Zheng, 2014/03/12
[Qemu-devel] [PATCH v2 1/9] qapi: Add optional field "name" to block dirty bitmap, Fam Zheng, 2014/03/12
[Qemu-devel] [PATCH v2 4/9] block: Introduce bdrv_dirty_bitmap_granularity(), Fam Zheng, 2014/03/12
[Qemu-devel] [PATCH v2 5/9] hbitmap: Add hbitmap_copy, Fam Zheng, 2014/03/12
[Qemu-devel] [PATCH v2 6/9] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap, Fam Zheng, 2014/03/12
[Qemu-devel] [PATCH v2 7/9] qmp: Add dirty-bitmap-enable and dirty-bitmap-disable, Fam Zheng, 2014/03/12
[Qemu-devel] [PATCH v2 8/9] qmp: Add support of "dirty-bitmap" sync mode for drive-backup, Fam Zheng, 2014/03/12