1 #ifndef BLOCK_DIRTY_BITMAP_H 2 #define BLOCK_DIRTY_BITMAP_H 3 4 #include "qapi/qapi-types-block-core.h" 5 #include "qemu/hbitmap.h" 6 7 typedef enum BitmapCheckFlags { 8 BDRV_BITMAP_BUSY = 1, 9 BDRV_BITMAP_RO = 2, 10 BDRV_BITMAP_INCONSISTENT = 4, 11 } BitmapCheckFlags; 12 13 #define BDRV_BITMAP_DEFAULT (BDRV_BITMAP_BUSY | BDRV_BITMAP_RO | \ 14 BDRV_BITMAP_INCONSISTENT) 15 #define BDRV_BITMAP_ALLOW_RO (BDRV_BITMAP_BUSY | BDRV_BITMAP_INCONSISTENT) 16 17 #define BDRV_BITMAP_MAX_NAME_SIZE 1023 18 19 BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, 20 uint32_t granularity, 21 const char *name, 22 Error **errp); 23 int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap, 24 Error **errp); 25 BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap, 26 Error **errp); 27 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *bitmap, 28 Error **errp); 29 void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap); 30 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, 31 const char *name); 32 int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags, 33 Error **errp); 34 void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap); 35 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); 36 int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, 37 Error **errp); 38 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); 39 void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); 40 void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap); 41 BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs); 42 uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs); 43 uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap); 44 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap); 45 bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap); 46 const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap); 47 int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap); 48 DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap); 49 void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, 50 int64_t offset, int64_t bytes); 51 void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, 52 int64_t offset, int64_t bytes); 53 BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap); 54 void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter); 55 56 uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap, 57 uint64_t offset, uint64_t bytes); 58 uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap); 59 void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap, 60 uint8_t *buf, uint64_t offset, 61 uint64_t bytes); 62 void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap, 63 uint8_t *buf, uint64_t offset, 64 uint64_t bytes, bool finish); 65 void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, 66 uint64_t offset, uint64_t bytes, 67 bool finish); 68 void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, 69 uint64_t offset, uint64_t bytes, 70 bool finish); 71 void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); 72 73 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value); 74 void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap, 75 bool persistent); 76 void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap); 77 void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy); 78 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, 79 HBitmap **backup, Error **errp); 80 void bdrv_dirty_bitmap_skip_store(BdrvDirtyBitmap *bitmap, bool skip); 81 bool bdrv_dirty_bitmap_get(BdrvDirtyBitmap *bitmap, int64_t offset); 82 83 /* Functions that require manual locking. */ 84 void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); 85 void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap); 86 bool bdrv_dirty_bitmap_get_locked(BdrvDirtyBitmap *bitmap, int64_t offset); 87 void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, 88 int64_t offset, int64_t bytes); 89 void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, 90 int64_t offset, int64_t bytes); 91 int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); 92 void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset); 93 int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); 94 void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes); 95 bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap); 96 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); 97 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); 98 bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap); 99 bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap); 100 101 BdrvDirtyBitmap *bdrv_dirty_bitmap_first(BlockDriverState *bs); 102 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BdrvDirtyBitmap *bitmap); 103 #define FOR_EACH_DIRTY_BITMAP(bs, bitmap) \ 104 for (bitmap = bdrv_dirty_bitmap_first(bs); bitmap; \ 105 bitmap = bdrv_dirty_bitmap_next(bitmap)) 106 107 char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp); 108 int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offset, 109 uint64_t bytes); 110 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, 111 uint64_t *offset, uint64_t *bytes); 112 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, 113 Error **errp); 114 115 #endif 116