From: Vladimir Sementsov-Ogievskiy <vsement...@parallels.com> The funcion loads dirty bitmap from file, using underlying driver function.
Note: the function doesn't change BdrvDirtyBitmap.file field. This field is only used by bdrv_store_dirty_bitmap() function and is ONLY written by bdrv_dirty_bitmap_set_file() function. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> --- block.c | 37 +++++++++++++++++++++++++++++++++++++ include/block/block.h | 5 +++++ 2 files changed, 42 insertions(+) diff --git a/block.c b/block.c index 74d4edc..6230717 100644 --- a/block.c +++ b/block.c @@ -3109,6 +3109,43 @@ void bdrv_release_meta_bitmap(BdrvDirtyBitmap *bitmap) } } +BdrvDirtyBitmap *bdrv_load_dirty_bitmap(BlockDriverState *bs, + BlockDriverState *file, + int granularity, + const char *name, + Error **errp) +{ + BlockDriver *drv = file->drv; + if (!drv) { + return NULL; + } + if (drv->bdrv_dirty_bitmap_load) { + BdrvDirtyBitmap *bitmap; + uint64_t bitmap_size = bdrv_nb_sectors(bs); + uint8_t *buf = drv->bdrv_dirty_bitmap_load(file, name, bitmap_size, + granularity); + if (buf == NULL) { + return NULL; + } + + bitmap = bdrv_create_dirty_bitmap(bs, granularity, name, errp); + if (bitmap == NULL) { + g_free(buf); + return NULL; + } + + hbitmap_deserialize_part(bitmap->bitmap, buf, 0, bitmap_size); + hbitmap_deserialize_finish(bitmap->bitmap); + + return bitmap; + } + if (file->file) { + return bdrv_load_dirty_bitmap(bs, file->file, granularity, name, + errp); + } + return NULL; +} + int bdrv_store_dirty_bitmap(BdrvDirtyBitmap *bitmap) { BlockDriverState *bs = bitmap->file; diff --git a/include/block/block.h b/include/block/block.h index 6e82597..fcdb0f3 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -508,6 +508,11 @@ HBitmap *bdrv_create_meta_bitmap(BdrvDirtyBitmap *bitmap, uint64_t granularity); void bdrv_release_meta_bitmap(BdrvDirtyBitmap *bitmap); +BdrvDirtyBitmap *bdrv_load_dirty_bitmap(BlockDriverState *bs, + BlockDriverState *file, + int granularity, + const char *name, + Error **errp); int bdrv_store_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_copy_on_read(BlockDriverState *bs); -- 1.9.1