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 RESEND 14/17] block: Resize bitmaps on bdrv_truncate
Date: Mon, 02 Mar 2015 12:17:28 -0500 [thread overview]
Message-ID: <54F49B28.3010909@redhat.com> (raw)
In-Reply-To: <1425084477-31602-15-git-send-email-jsnow@redhat.com>
On 2015-02-27 at 19:47, John Snow wrote:
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> block.c | 22 ++++++++++++++++++++
> include/block/block.h | 1 +
> include/qemu/hbitmap.h | 10 ++++++++++
> util/hbitmap.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 87 insertions(+)
>
> diff --git a/block.c b/block.c
> index e6b2696..5eaa874 100644
> --- a/block.c
> +++ b/block.c
> @@ -3543,6 +3543,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
> ret = drv->bdrv_truncate(bs, offset);
> if (ret == 0) {
> ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
> + bdrv_dirty_bitmap_truncate(bs);
> if (bs->blk) {
> blk_dev_resize_cb(bs->blk);
> }
> @@ -5562,6 +5563,27 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
> return parent;
> }
>
> +static void dirty_bitmap_truncate(BdrvDirtyBitmap *bitmap, uint64_t size)
> +{
> + /* Should only be frozen during a block backup job, which should have
> + * blocked any resize actions. */
> + assert(!bdrv_dirty_bitmap_frozen(bitmap));
> + hbitmap_truncate(bitmap->bitmap, size);
> +}
> +
> +void bdrv_dirty_bitmap_truncate(BlockDriverState *bs)
> +{
> + BdrvDirtyBitmap *bitmap;
> + uint64_t size = bdrv_nb_sectors(bs);
> +
> + QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
> + if (bdrv_dirty_bitmap_frozen(bitmap)) {
> + continue;
> + }
> + dirty_bitmap_truncate(bitmap, size);
> + }
> +}
> +
> void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
> {
> BdrvDirtyBitmap *bm, *next;
> diff --git a/include/block/block.h b/include/block/block.h
> index a8c6369..3a85690 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -454,6 +454,7 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
> uint32_t granularity,
> const char *name,
> Error **errp);
> +void bdrv_dirty_bitmap_truncate(BlockDriverState *bs);
> int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
> BdrvDirtyBitmap *bitmap,
> Error **errp);
> diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
> index c19c1cb..a75157e 100644
> --- a/include/qemu/hbitmap.h
> +++ b/include/qemu/hbitmap.h
> @@ -65,6 +65,16 @@ struct HBitmapIter {
> HBitmap *hbitmap_alloc(uint64_t size, int granularity);
>
> /**
> + * hbitmap_truncate:
> + * @hb: The bitmap to change the size of.
> + * @size: The number of elements to change the bitmap to accommodate.
> + *
> + * truncate or grow an existing bitmap to accommodate a new number of elements.
> + * This may invalidate existing HBitmapIterators.
> + */
> +void hbitmap_truncate(HBitmap *hb, uint64_t size);
> +
> +/**
> * hbitmap_merge:
> * @a: The bitmap to store the result in.
> * @b: The bitmap to merge into @a.
> diff --git a/util/hbitmap.c b/util/hbitmap.c
> index 962ff29..0934a61 100644
> --- a/util/hbitmap.c
> +++ b/util/hbitmap.c
> @@ -90,6 +90,9 @@ struct HBitmap {
> * bitmap will still allocate HBITMAP_LEVELS arrays.
> */
> unsigned long *levels[HBITMAP_LEVELS];
> +
> + /* The length of each levels[] array. */
> + uint64_t sizes[HBITMAP_LEVELS];
> };
>
> /* Advance hbi to the next nonzero word and return it. hbi->pos
> @@ -384,6 +387,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity)
> hb->granularity = granularity;
> for (i = HBITMAP_LEVELS; i-- > 0; ) {
> size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1);
> + hb->sizes[i] = size;
> hb->levels[i] = g_new0(unsigned long, size);
> }
>
> @@ -396,6 +400,56 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity)
> return hb;
> }
>
> +void hbitmap_truncate(HBitmap *hb, uint64_t size)
> +{
> + bool truncate;
> + unsigned i;
> + uint64_t num_elements = size;
> + uint64_t old;
> +
> + /* Size comes in as logical elements, adjust for granularity. */
> + size = (size + (1ULL << hb->granularity) - 1) >> hb->granularity;
> + assert(size <= ((uint64_t)1 << HBITMAP_LOG_MAX_SIZE));
> + truncate = size < hb->size;
> +
> + if (size == hb->size) {
> + /* A hard day's work */
> + return;
> + }
> +
> + hb->size = size;
> + for (i = HBITMAP_LEVELS; i-- > 0; ) {
> + size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1);
> + if (hb->sizes[i] == size) {
> + continue;
> + }
> + old = hb->sizes[i];
> + hb->sizes[i] = size;
> + hb->levels[i] = g_realloc_n(hb->levels[i], size, sizeof(unsigned long));
> + if (!truncate) {
> + memset(&hb->levels[i][old], 0x00, size - old);
The length should be (size - old) * sizeof(*hb->levels[i]) (that is,
(size - old) * sizeof(long)).
Max
> + }
> + }
> + assert(size == 1);
> +
> + /* Clear out any "extra space" we may have that the user didn't request:
> + * It may have garbage data in it, now. */
> + if (truncate) {
> + /* Due to granularity fuzziness, we may accidentally reset some of
> + * the last bits that are actually valid. So, record the current value,
> + * reset the "dead range," then re-set the one element we care about. */
> + uint64_t fix_count = (hb->size << hb->granularity) - num_elements;
> + if (fix_count) {
> + bool set = hbitmap_get(hb, num_elements - 1);
> + hbitmap_reset(hb, num_elements, fix_count);
> + if (set) {
> + hbitmap_set(hb, num_elements - 1, 1);
> + }
> + }
> + }
> +}
> +
> +
> /**
> * Given HBitmaps A and B, let A := A (BITOR) B.
> * Bitmap B will not be modified.
next prev parent reply other threads:[~2015-03-02 17:17 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-28 0:47 [Qemu-devel] [PATCH RESEND 00/17] block: transactionless incremental backup series John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 01/17] docs: incremental backup documentation John Snow
2015-03-02 17:49 ` Max Reitz
2015-03-02 18:48 ` John Snow
2015-03-02 19:07 ` Max Reitz
2015-03-02 21:27 ` Max Reitz
2015-03-04 10:39 ` Kevin Wolf
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 02/17] qapi: Add optional field "name" to block dirty bitmap John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 03/17] qmp: Ensure consistent granularity type John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 04/17] qmp: Add block-dirty-bitmap-add and block-dirty-bitmap-remove John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 05/17] block: Introduce bdrv_dirty_bitmap_granularity() John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 06/17] hbitmap: add hbitmap_merge John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 07/17] block: Add bitmap disabled status John Snow
2015-03-02 17:08 ` Max Reitz
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 08/17] block: Add bitmap successors John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 09/17] qmp: Add support of "dirty-bitmap" sync mode for drive-backup John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 10/17] qmp: add block-dirty-bitmap-clear John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 11/17] qmp: Add dirty bitmap status fields in query-block John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 12/17] block: add BdrvDirtyBitmap documentation John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 13/17] block: Ensure consistent bitmap function prototypes John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 14/17] block: Resize bitmaps on bdrv_truncate John Snow
2015-03-02 17:17 ` Max Reitz [this message]
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 15/17] iotests: add invalid input incremental backup tests John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 16/17] iotests: add simple incremental backup case John Snow
2015-02-28 0:47 ` [Qemu-devel] [PATCH RESEND 17/17] iotests: add incremental backup failure recovery test 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=54F49B28.3010909@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.