This flag means that the bitmap is now in use by the software or was not successfully saved. In any way, with this flag set the bitmap data must be considered inconsistent and should not be loaded. With current implementation this flag is never set, as we just remove bitmaps from the image after loading. But it defined in qcow2 spec and must be handled. Also, it can be used in future, if async schemes of bitmap loading/saving are implemented.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> --- block/qcow2-bitmap.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 43a9bb9..19f8203 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -44,7 +44,8 @@ #define BME_MAX_NAME_SIZE 1023 /* Bitmap directory entry flags */ -#define BME_RESERVED_FLAGS 0xffffffff +#define BME_RESERVED_FLAGS 0xfffffffe +#define BME_FLAG_IN_USE 1 /* bits [1, 8] U [56, 63] are reserved */ #define BME_TABLE_ENTRY_RESERVED_MASK 0xff000000000001fe @@ -487,6 +488,11 @@ static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap = NULL; char *name = g_strndup((char *)(bmh + 1), bmh->name_size); + if (bmh->flags & BME_FLAG_IN_USE) { + error_setg(errp, "Bitmap '%s' is in use", name); + goto fail; + } + ret = bitmap_table_load(bs, bmh, &bitmap_table); if (ret < 0) { error_setg_errno(errp, -ret, @@ -795,7 +801,8 @@ void qcow2_bitmap_store(BlockDriverState *bs, return; } - if (bmh->bitmap_table_offset) { + if ((bmh->bitmap_table_offset != 0) || + !(bmh->flags & BME_FLAG_IN_USE)) { error_setg(errp, "The bitmap with same name already exists, but was" "not loaded."); @@ -820,7 +827,7 @@ void qcow2_bitmap_store(BlockDriverState *bs, } } else { ret = directory_set(bs, bmh, granularity, table_offset, table_size, - bmh->flags); + bmh->flags & ~BME_FLAG_IN_USE); if (ret < 0) { error_setg_errno(errp, ret, "Can't update dirty bitmap in qcow2."); goto fail; -- 1.8.3.1