On 2015-03-02 at 18:20, John Snow wrote:
Signed-off-by: John Snow <address@hidden>
---
block.c | 22 ++++++++++++++++++++
include/block/block.h | 1 +
include/qemu/hbitmap.h | 10 +++++++++
util/hbitmap.c | 55
++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 88 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;
+ }
Hm!
The assert() above doesn't do anything because this condition will just
skip over frozen bitmaps. Maybe we should drop it?
I guess my R-b stands since bdrv_dirty_bitmap_frozen(bitmap) will always
be false anyway (hence the assertion), but it would stand with this
block dropped, too.
Max