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 BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, 18 uint32_t granularity, 19 const char *name, 20 Error **errp); 21 void bdrv_create_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap, 22 int chunk_size); 23 void bdrv_release_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap); 24 int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs, 25 BdrvDirtyBitmap *bitmap, 26 Error **errp); 27 BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs, 28 BdrvDirtyBitmap *bitmap, 29 Error **errp); 30 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, 31 BdrvDirtyBitmap *bitmap, 32 Error **errp); 33 void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap); 34 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, 35 const char *name); 36 int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags, 37 Error **errp); 38 void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); 39 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); 40 void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, 41 const char *name, 42 Error **errp); 43 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); 44 void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); 45 void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap); 46 BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs); 47 uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs); 48 uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap); 49 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap); 50 bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap); 51 const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap); 52 int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap); 53 DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap); 54 void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, 55 int64_t offset, int64_t bytes); 56 void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, 57 int64_t offset, int64_t bytes); 58 BdrvDirtyBitmapIter *bdrv_dirty_meta_iter_new(BdrvDirtyBitmap *bitmap); 59 BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap); 60 void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter); 61 62 uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap, 63 uint64_t offset, uint64_t bytes); 64 uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap); 65 void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap, 66 uint8_t *buf, uint64_t offset, 67 uint64_t bytes); 68 void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap, 69 uint8_t *buf, uint64_t offset, 70 uint64_t bytes, bool finish); 71 void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, 72 uint64_t offset, uint64_t bytes, 73 bool finish); 74 void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, 75 uint64_t offset, uint64_t bytes, 76 bool finish); 77 void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); 78 79 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value); 80 void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap, 81 bool persistent); 82 void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap); 83 void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy); 84 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, 85 HBitmap **backup, Error **errp); 86 void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migration); 87 88 /* Functions that require manual locking. */ 89 void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); 90 void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap); 91 bool bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, 92 int64_t offset); 93 void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, 94 int64_t offset, int64_t bytes); 95 void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, 96 int64_t offset, int64_t bytes); 97 int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); 98 void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset); 99 int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); 100 int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap); 101 void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes); 102 bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap); 103 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); 104 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); 105 bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap); 106 bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap); 107 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); 108 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, 109 BdrvDirtyBitmap *bitmap); 110 char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp); 111 int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offset, 112 uint64_t bytes); 113 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, 114 uint64_t *offset, uint64_t *bytes); 115 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs, 116 BdrvDirtyBitmap *bitmap, 117 Error **errp); 118 119 #endif 120