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