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