xref: /openbmc/qemu/include/block/dirty-bitmap.h (revision 37b0b24e)
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 bool bdrv_supports_persistent_dirty_bitmap(BlockDriverState *bs);
20 BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
21                                           uint32_t granularity,
22                                           const char *name,
23                                           Error **errp);
24 int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap,
25                                        Error **errp);
26 BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap,
27                                             Error **errp);
28 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *bitmap,
29                                            Error **errp);
30 void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap);
31 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
32                                         const char *name);
33 int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
34                             Error **errp);
35 void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap);
36 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
37 
38 int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs,
39                                                         const char *name,
40                                                         Error **errp);
41 int co_wrapper bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs,
42                                                    const char *name,
43                                                    Error **errp);
44 
45 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
46 void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
47 void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap);
48 BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
49 uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
50 uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap);
51 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap);
52 bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap);
53 const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap);
54 int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap);
55 void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap,
56                            int64_t offset, int64_t bytes);
57 void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
58                              int64_t offset, int64_t bytes);
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 uint64_t bdrv_dirty_bitmap_serialization_coverage(int serialized_chunk_size,
66         const BdrvDirtyBitmap *bitmap);
67 void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
68                                       uint8_t *buf, uint64_t offset,
69                                       uint64_t bytes);
70 void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap,
71                                         uint8_t *buf, uint64_t offset,
72                                         uint64_t bytes, bool finish);
73 void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap,
74                                           uint64_t offset, uint64_t bytes,
75                                           bool finish);
76 void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap,
77                                         uint64_t offset, uint64_t bytes,
78                                         bool finish);
79 void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
80 
81 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
82 void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap,
83                                        bool persistent);
84 void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);
85 void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
86 bool bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
87                              HBitmap **backup, Error **errp);
88 void bdrv_dirty_bitmap_skip_store(BdrvDirtyBitmap *bitmap, bool skip);
89 bool bdrv_dirty_bitmap_get(BdrvDirtyBitmap *bitmap, int64_t offset);
90 
91 /* Functions that require manual locking.  */
92 void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap);
93 void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap);
94 bool bdrv_dirty_bitmap_get_locked(BdrvDirtyBitmap *bitmap, int64_t offset);
95 void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
96                                   int64_t offset, int64_t bytes);
97 void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
98                                     int64_t offset, int64_t bytes);
99 int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter);
100 void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset);
101 int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
102 void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes);
103 bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
104 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
105 bool bdrv_has_named_bitmaps(BlockDriverState *bs);
106 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
107 bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap);
108 bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
109 
110 BdrvDirtyBitmap *bdrv_dirty_bitmap_first(BlockDriverState *bs);
111 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BdrvDirtyBitmap *bitmap);
112 #define FOR_EACH_DIRTY_BITMAP(bs, bitmap) \
113 for (bitmap = bdrv_dirty_bitmap_first(bs); bitmap; \
114      bitmap = bdrv_dirty_bitmap_next(bitmap))
115 
116 char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp);
117 int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *bitmap, int64_t offset,
118                                      int64_t bytes);
119 int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offset,
120                                     int64_t bytes);
121 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
122         int64_t start, int64_t end, int64_t max_dirty_count,
123         int64_t *dirty_start, int64_t *dirty_count);
124 bool bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap, int64_t offset,
125                               int64_t bytes, int64_t *count);
126 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
127                                                   Error **errp);
128 
129 #endif
130