From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: jsnow@redhat.com, qemu-block@nongnu.org,
Fam Zheng <famz@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v2 04/12] dirty-bitmap: Track size in bytes
Date: Tue, 16 May 2017 15:47:16 -0500 [thread overview]
Message-ID: <20170516204724.1617-5-eblake@redhat.com> (raw)
In-Reply-To: <20170516204724.1617-1-eblake@redhat.com>
We are still using an internal hbitmap that tracks a size in sectors,
with the granularity scaled down accordingly, because it lets us
use a shortcut for our iterators which are currently sector-based.
But there's no reason we can't track the dirty bitmap size in bytes,
since it is an internal-only variable.
Use is_power_of_2() while at it, instead of open-coding that.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
---
v2: tweak commit message, no code change
---
block/dirty-bitmap.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 32698d5..a413df1 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -41,7 +41,7 @@ struct BdrvDirtyBitmap {
HBitmap *meta; /* Meta dirty bitmap */
BdrvDirtyBitmap *successor; /* Anonymous child; implies frozen status */
char *name; /* Optional non-empty unique ID */
- int64_t size; /* Size of the bitmap (Number of sectors) */
+ int64_t size; /* Size of the bitmap, in bytes */
bool disabled; /* Bitmap is read-only */
int active_iterators; /* How many iterators are active */
QLIST_ENTRY(BdrvDirtyBitmap) list;
@@ -79,24 +79,26 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
{
int64_t bitmap_size;
BdrvDirtyBitmap *bitmap;
- uint32_t sector_granularity;
- assert((granularity & (granularity - 1)) == 0);
+ assert(is_power_of_2(granularity) && granularity >= BDRV_SECTOR_SIZE);
if (name && bdrv_find_dirty_bitmap(bs, name)) {
error_setg(errp, "Bitmap already exists: %s", name);
return NULL;
}
- sector_granularity = granularity >> BDRV_SECTOR_BITS;
- assert(sector_granularity);
- bitmap_size = bdrv_nb_sectors(bs);
+ bitmap_size = bdrv_getlength(bs);
if (bitmap_size < 0) {
error_setg_errno(errp, -bitmap_size, "could not get length of device");
errno = -bitmap_size;
return NULL;
}
bitmap = g_new0(BdrvDirtyBitmap, 1);
- bitmap->bitmap = hbitmap_alloc(bitmap_size, ctz32(sector_granularity));
+ /*
+ * TODO - let hbitmap track full granularity. For now, it is tracking
+ * only sector granularity, as a shortcut for our iterators.
+ */
+ bitmap->bitmap = hbitmap_alloc(bitmap_size >> BDRV_SECTOR_BITS,
+ ctz32(granularity) - BDRV_SECTOR_BITS);
bitmap->size = bitmap_size;
bitmap->name = g_strdup(name);
bitmap->disabled = false;
@@ -246,12 +248,13 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
void bdrv_dirty_bitmap_truncate(BlockDriverState *bs)
{
BdrvDirtyBitmap *bitmap;
- uint64_t size = bdrv_nb_sectors(bs);
+ int64_t size = bdrv_getlength(bs);
+ assert(size >= 0);
QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
assert(!bdrv_dirty_bitmap_frozen(bitmap));
assert(!bitmap->active_iterators);
- hbitmap_truncate(bitmap->bitmap, size);
+ hbitmap_truncate(bitmap->bitmap, size >> BDRV_SECTOR_BITS);
bitmap->size = size;
}
}
@@ -419,7 +422,7 @@ void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out)
hbitmap_reset_all(bitmap->bitmap);
} else {
HBitmap *backup = bitmap->bitmap;
- bitmap->bitmap = hbitmap_alloc(bitmap->size,
+ bitmap->bitmap = hbitmap_alloc(bitmap->size >> BDRV_SECTOR_BITS,
hbitmap_granularity(backup));
*out = backup;
}
--
2.9.4
next prev parent reply other threads:[~2017-05-16 20:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 20:47 [Qemu-devel] [PATCH v2 00/12] make dirty-bitmap byte-based Eric Blake
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 01/12] dirty-bitmap: Report BlockDirtyInfo.count in bytes, as documented Eric Blake
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 02/12] migration: Don't lose errno across aio context changes Eric Blake
2017-06-27 3:15 ` Eric Blake
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 03/12] dirty-bitmap: Drop unused functions Eric Blake
2017-05-16 20:47 ` Eric Blake [this message]
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 05/12] dirty-bitmap: Set iterator start by offset, not sector Eric Blake
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 06/12] dirty-bitmap: Change bdrv_dirty_iter_next() to report byte offset Eric Blake
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 07/12] dirty-bitmap: Change bdrv_get_dirty_count() to report bytes Eric Blake
2017-05-17 11:34 ` Juan Quintela
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 08/12] dirty-bitmap: Change bdrv_get_dirty() to take bytes Eric Blake
2017-05-17 11:37 ` Juan Quintela
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 09/12] dirty-bitmap: Change bdrv_[re]set_dirty_bitmap() to use bytes Eric Blake
2017-05-17 11:59 ` Juan Quintela
2017-05-17 13:40 ` Eric Blake
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 10/12] mirror: Switch mirror_dirty_init() to byte-based iteration Eric Blake
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 11/12] dirty-bitmap: Switch bdrv_set_dirty() to bytes Eric Blake
2017-05-16 20:47 ` [Qemu-devel] [PATCH v2 12/12] dirty-bitmap: Convert internal hbitmap size/granularity Eric Blake
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=20170516204724.1617-5-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).