Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 1 | #ifndef BLOCK_DIRTY_BITMAP_H |
| 2 | #define BLOCK_DIRTY_BITMAP_H |
| 3 | |
Markus Armbruster | 9af2398 | 2018-02-11 10:36:01 +0100 | [diff] [blame] | 4 | #include "qapi/qapi-types-block-core.h" |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 5 | #include "qemu/hbitmap.h" |
| 6 | |
John Snow | 3ae96d6 | 2019-03-12 12:05:49 -0400 | [diff] [blame] | 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 | |
Eric Blake | cf7c49c | 2019-11-13 20:46:33 -0600 | [diff] [blame] | 17 | #define BDRV_BITMAP_MAX_NAME_SIZE 1023 |
| 18 | |
Eric Blake | ef893b5 | 2020-05-12 20:16:42 -0500 | [diff] [blame] | 19 | bool bdrv_supports_persistent_dirty_bitmap(BlockDriverState *bs); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 20 | BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, |
| 21 | uint32_t granularity, |
| 22 | const char *name, |
| 23 | Error **errp); |
Vladimir Sementsov-Ogievskiy | 5deb6cb | 2019-09-16 17:19:09 +0300 | [diff] [blame] | 24 | int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap, |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 25 | Error **errp); |
Vladimir Sementsov-Ogievskiy | 5deb6cb | 2019-09-16 17:19:09 +0300 | [diff] [blame] | 26 | BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap, |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 27 | Error **errp); |
Vladimir Sementsov-Ogievskiy | 5deb6cb | 2019-09-16 17:19:09 +0300 | [diff] [blame] | 28 | BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *bitmap, |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 29 | Error **errp); |
Vladimir Sementsov-Ogievskiy | e73a265 | 2018-03-13 15:33:59 -0400 | [diff] [blame] | 30 | void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 31 | BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, |
| 32 | const char *name); |
John Snow | 3ae96d6 | 2019-03-12 12:05:49 -0400 | [diff] [blame] | 33 | int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags, |
| 34 | Error **errp); |
Vladimir Sementsov-Ogievskiy | 5deb6cb | 2019-09-16 17:19:09 +0300 | [diff] [blame] | 35 | void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 36 | void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); |
Vladimir Sementsov-Ogievskiy | b56a1e3 | 2019-09-20 11:25:42 +0300 | [diff] [blame] | 37 | int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, |
| 38 | Error **errp); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 39 | void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); |
| 40 | void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); |
Vladimir Sementsov-Ogievskiy | 92bcea4 | 2018-07-04 02:12:49 -0400 | [diff] [blame] | 41 | void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 42 | BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs); |
| 43 | uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs); |
Vladimir Sementsov-Ogievskiy | ba06ff1 | 2017-06-28 15:05:05 +0300 | [diff] [blame] | 44 | uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 45 | bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap); |
John Snow | 50a4725 | 2019-03-12 12:05:48 -0400 | [diff] [blame] | 46 | bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap); |
Fam Zheng | 15891fa | 2016-10-13 17:58:25 -0400 | [diff] [blame] | 47 | const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap); |
| 48 | int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 49 | void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, |
Eric Blake | e0d7f73 | 2017-09-25 09:55:20 -0500 | [diff] [blame] | 50 | int64_t offset, int64_t bytes); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 51 | void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, |
Eric Blake | e0d7f73 | 2017-09-25 09:55:20 -0500 | [diff] [blame] | 52 | int64_t offset, int64_t bytes); |
Eric Blake | 715a74d | 2017-09-25 09:55:16 -0500 | [diff] [blame] | 53 | BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap); |
Fam Zheng | dc162c8 | 2016-10-13 17:58:21 -0400 | [diff] [blame] | 54 | void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter); |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 55 | |
Vladimir Sementsov-Ogievskiy | 882c36f | 2016-10-13 17:58:28 -0400 | [diff] [blame] | 56 | uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap, |
Eric Blake | 86f6ae6 | 2017-09-25 09:55:14 -0500 | [diff] [blame] | 57 | uint64_t offset, uint64_t bytes); |
Vladimir Sementsov-Ogievskiy | 882c36f | 2016-10-13 17:58:28 -0400 | [diff] [blame] | 58 | uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap); |
Vladimir Sementsov-Ogievskiy | 35f428b | 2021-02-24 13:47:02 +0300 | [diff] [blame] | 59 | uint64_t bdrv_dirty_bitmap_serialization_coverage(int serialized_chunk_size, |
| 60 | const BdrvDirtyBitmap *bitmap); |
Vladimir Sementsov-Ogievskiy | 882c36f | 2016-10-13 17:58:28 -0400 | [diff] [blame] | 61 | void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap, |
Eric Blake | 86f6ae6 | 2017-09-25 09:55:14 -0500 | [diff] [blame] | 62 | uint8_t *buf, uint64_t offset, |
| 63 | uint64_t bytes); |
Vladimir Sementsov-Ogievskiy | 882c36f | 2016-10-13 17:58:28 -0400 | [diff] [blame] | 64 | void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap, |
Eric Blake | 86f6ae6 | 2017-09-25 09:55:14 -0500 | [diff] [blame] | 65 | uint8_t *buf, uint64_t offset, |
| 66 | uint64_t bytes, bool finish); |
Vladimir Sementsov-Ogievskiy | 882c36f | 2016-10-13 17:58:28 -0400 | [diff] [blame] | 67 | void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, |
Eric Blake | 86f6ae6 | 2017-09-25 09:55:14 -0500 | [diff] [blame] | 68 | uint64_t offset, uint64_t bytes, |
Vladimir Sementsov-Ogievskiy | 882c36f | 2016-10-13 17:58:28 -0400 | [diff] [blame] | 69 | bool finish); |
Vladimir Sementsov-Ogievskiy | 6bdc8b7 | 2017-06-28 15:05:06 +0300 | [diff] [blame] | 70 | void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, |
Eric Blake | 86f6ae6 | 2017-09-25 09:55:14 -0500 | [diff] [blame] | 71 | uint64_t offset, uint64_t bytes, |
Vladimir Sementsov-Ogievskiy | 6bdc8b7 | 2017-06-28 15:05:06 +0300 | [diff] [blame] | 72 | bool finish); |
Vladimir Sementsov-Ogievskiy | 882c36f | 2016-10-13 17:58:28 -0400 | [diff] [blame] | 73 | void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); |
| 74 | |
Vladimir Sementsov-Ogievskiy | d6883bc | 2017-06-28 15:05:10 +0300 | [diff] [blame] | 75 | void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value); |
Eric Blake | 796a379 | 2019-03-12 12:05:49 -0400 | [diff] [blame] | 76 | void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap, |
Vladimir Sementsov-Ogievskiy | a88b179 | 2017-06-28 15:05:17 +0300 | [diff] [blame] | 77 | bool persistent); |
John Snow | b0f4555 | 2019-03-12 12:05:49 -0400 | [diff] [blame] | 78 | void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap); |
John Snow | 27a1b30 | 2019-03-12 12:05:48 -0400 | [diff] [blame] | 79 | void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy); |
Vladimir Sementsov-Ogievskiy | b598e53 | 2018-06-11 14:53:32 -0400 | [diff] [blame] | 80 | void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src, |
Vladimir Sementsov-Ogievskiy | fa000f2 | 2018-10-29 16:23:15 -0400 | [diff] [blame] | 81 | HBitmap **backup, Error **errp); |
John Snow | c4e4b0f | 2019-07-29 16:35:54 -0400 | [diff] [blame] | 82 | void bdrv_dirty_bitmap_skip_store(BdrvDirtyBitmap *bitmap, bool skip); |
John Snow | 28636b8 | 2019-07-29 16:35:53 -0400 | [diff] [blame] | 83 | bool bdrv_dirty_bitmap_get(BdrvDirtyBitmap *bitmap, int64_t offset); |
Vladimir Sementsov-Ogievskiy | d6883bc | 2017-06-28 15:05:10 +0300 | [diff] [blame] | 84 | |
Paolo Bonzini | b64bd51 | 2017-06-05 14:39:05 +0200 | [diff] [blame] | 85 | /* Functions that require manual locking. */ |
| 86 | void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); |
| 87 | void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap); |
John Snow | 28636b8 | 2019-07-29 16:35:53 -0400 | [diff] [blame] | 88 | bool bdrv_dirty_bitmap_get_locked(BdrvDirtyBitmap *bitmap, int64_t offset); |
Paolo Bonzini | b64bd51 | 2017-06-05 14:39:05 +0200 | [diff] [blame] | 89 | void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, |
Eric Blake | e0d7f73 | 2017-09-25 09:55:20 -0500 | [diff] [blame] | 90 | int64_t offset, int64_t bytes); |
Paolo Bonzini | b64bd51 | 2017-06-05 14:39:05 +0200 | [diff] [blame] | 91 | void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, |
Eric Blake | e0d7f73 | 2017-09-25 09:55:20 -0500 | [diff] [blame] | 92 | int64_t offset, int64_t bytes); |
Paolo Bonzini | b64bd51 | 2017-06-05 14:39:05 +0200 | [diff] [blame] | 93 | int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); |
Eric Blake | 715a74d | 2017-09-25 09:55:16 -0500 | [diff] [blame] | 94 | void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset); |
Paolo Bonzini | b64bd51 | 2017-06-05 14:39:05 +0200 | [diff] [blame] | 95 | int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); |
Eric Blake | 1b6cc57 | 2017-09-25 09:55:11 -0500 | [diff] [blame] | 96 | void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes); |
Vladimir Sementsov-Ogievskiy | d6883bc | 2017-06-28 15:05:10 +0300 | [diff] [blame] | 97 | bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap); |
| 98 | bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); |
Vladimir Sementsov-Ogievskiy | 7ae89a0 | 2020-05-22 01:06:44 +0300 | [diff] [blame] | 99 | bool bdrv_has_named_bitmaps(BlockDriverState *bs); |
Vladimir Sementsov-Ogievskiy | a0319aa | 2017-06-28 15:05:15 +0300 | [diff] [blame] | 100 | bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); |
Eric Blake | 796a379 | 2019-03-12 12:05:49 -0400 | [diff] [blame] | 101 | bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap); |
John Snow | b0f4555 | 2019-03-12 12:05:49 -0400 | [diff] [blame] | 102 | bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap); |
Vladimir Sementsov-Ogievskiy | ef9041a | 2019-09-16 17:19:11 +0300 | [diff] [blame] | 103 | |
| 104 | BdrvDirtyBitmap *bdrv_dirty_bitmap_first(BlockDriverState *bs); |
| 105 | BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BdrvDirtyBitmap *bitmap); |
| 106 | #define FOR_EACH_DIRTY_BITMAP(bs, bitmap) \ |
| 107 | for (bitmap = bdrv_dirty_bitmap_first(bs); bitmap; \ |
| 108 | bitmap = bdrv_dirty_bitmap_next(bitmap)) |
| 109 | |
Vladimir Sementsov-Ogievskiy | a3b5253 | 2017-06-28 15:05:25 +0300 | [diff] [blame] | 110 | char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp); |
Vladimir Sementsov-Ogievskiy | 9399c54 | 2020-02-05 14:20:37 +0300 | [diff] [blame] | 111 | int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *bitmap, int64_t offset, |
| 112 | int64_t bytes); |
Vladimir Sementsov-Ogievskiy | 642700f | 2020-02-05 14:20:36 +0300 | [diff] [blame] | 113 | int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offset, |
| 114 | int64_t bytes); |
Vladimir Sementsov-Ogievskiy | a78a1a4 | 2019-01-15 18:26:50 -0500 | [diff] [blame] | 115 | bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap, |
Vladimir Sementsov-Ogievskiy | 299ea9f | 2020-02-05 14:20:38 +0300 | [diff] [blame] | 116 | int64_t start, int64_t end, int64_t max_dirty_count, |
| 117 | int64_t *dirty_start, int64_t *dirty_count); |
Vladimir Sementsov-Ogievskiy | 5deb6cb | 2019-09-16 17:19:09 +0300 | [diff] [blame] | 118 | BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, |
Vladimir Sementsov-Ogievskiy | 044ee8e | 2018-03-13 15:34:00 -0400 | [diff] [blame] | 119 | Error **errp); |
Paolo Bonzini | b64bd51 | 2017-06-05 14:39:05 +0200 | [diff] [blame] | 120 | |
Fam Zheng | ebab225 | 2016-03-08 12:44:55 +0800 | [diff] [blame] | 121 | #endif |