[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v15 15/25] qcow2: add .bdrv_can_store_new_dirty_bitm
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH v15 15/25] qcow2: add .bdrv_can_store_new_dirty_bitmap |
Date: |
Wed, 15 Feb 2017 13:10:20 +0300 |
Realize .bdrv_can_store_new_dirty_bitmap interface.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
block/qcow2-bitmap.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
block/qcow2.c | 1 +
block/qcow2.h | 4 ++++
3 files changed, 57 insertions(+)
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index b177a95..1ee89e4 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -1182,3 +1182,55 @@ fail:
bitmap_list_free(bm_list);
}
+
+bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs,
+ const char *name,
+ uint32_t granularity,
+ Error **errp)
+{
+ BDRVQcow2State *s = bs->opaque;
+ bool found;
+ Qcow2BitmapList *bm_list;
+
+ if (check_constraints_on_bitmap(bs, name, granularity) != 0) {
+ error_setg(errp, "The constraints are not satisfied");
+ goto fail;
+ }
+
+ if (s->nb_bitmaps == 0) {
+ return true;
+ }
+
+ if (s->nb_bitmaps >= QCOW2_MAX_BITMAPS) {
+ error_setg(errp,
+ "Maximum number of persistent bitmaps is already reached");
+ goto fail;
+ }
+
+ if (s->bitmap_directory_size + calc_dir_entry_size(strlen(name), 0) >
+ QCOW2_MAX_BITMAP_DIRECTORY_SIZE)
+ {
+ error_setg(errp, "No enough space in the bitmap directory");
+ goto fail;
+ }
+
+ bm_list = bitmap_list_load(bs, s->bitmap_directory_offset,
+ s->bitmap_directory_size, errp);
+ if (bm_list == NULL) {
+ goto fail;
+ }
+
+ found = find_bitmap_by_name(bm_list, name);
+ bitmap_list_free(bm_list);
+ if (found) {
+ error_setg(errp, "Bitmap with the same name is already stored");
+ goto fail;
+ }
+
+ return true;
+
+fail:
+ error_prepend(errp, "Can't make bitmap '%s' persistent in '%s': ",
+ name, bdrv_get_device_or_node_name(bs));
+ return false;
+}
diff --git a/block/qcow2.c b/block/qcow2.c
index d0e41bf..6e1fe53 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3541,6 +3541,7 @@ BlockDriver bdrv_qcow2 = {
.bdrv_load_autoloading_dirty_bitmaps =
qcow2_load_autoloading_dirty_bitmaps,
.bdrv_store_persistent_dirty_bitmaps =
qcow2_store_persistent_dirty_bitmaps,
+ .bdrv_can_store_new_dirty_bitmap = qcow2_can_store_new_dirty_bitmap,
};
static void bdrv_qcow2_init(void)
diff --git a/block/qcow2.h b/block/qcow2.h
index d9a7643..749710d 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -616,5 +616,9 @@ void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c,
void **table);
/* qcow2-bitmap.c functions */
void qcow2_load_autoloading_dirty_bitmaps(BlockDriverState *bs, Error **errp);
void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp);
+bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs,
+ const char *name,
+ uint32_t granularity,
+ Error **errp);
#endif
--
1.8.3.1
- [Qemu-block] [PATCH v15 00/25] qcow2: persistent dirty bitmaps, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 04/25] tests: add hbitmap iter test, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 01/25] specs/qcow2: fix bitmap granularity qemu-specific note, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 02/25] specs/qcow2: do not use wording 'bitmap header', Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 05/25] block: fix bdrv_dirty_bitmap_granularity signature, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 15/25] qcow2: add .bdrv_can_store_new_dirty_bitmap,
Vladimir Sementsov-Ogievskiy <=
- [Qemu-block] [PATCH v15 24/25] qmp: block-dirty-bitmap-remove: remove persistent, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 11/25] block: introduce persistent dirty bitmaps, Vladimir Sementsov-Ogievskiy, 2017/02/15
- [Qemu-block] [PATCH v15 25/25] qcow2-bitmap: improve check_constraints_on_bitmap, Vladimir Sementsov-Ogievskiy, 2017/02/15
[Qemu-block] [PATCH v15 08/25] block: introduce auto-loading bitmaps, Vladimir Sementsov-Ogievskiy, 2017/02/15