xref: /openbmc/qemu/include/block/dirty-bitmap.h (revision 7f6c3d1a)
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 int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name,
38                                         Error **errp);
39 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
40 void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
41 void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap);
42 BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
43 uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
44 uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap);
45 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap);
46 bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap);
47 const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap);
48 int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap);
49 DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap);
50 void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap,
51                            int64_t offset, int64_t bytes);
52 void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
53                              int64_t offset, int64_t bytes);
54 BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap);
55 void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter);
56 
57 uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap,
58                                               uint64_t offset, uint64_t bytes);
59 uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap);
60 void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
61                                       uint8_t *buf, uint64_t offset,
62                                       uint64_t bytes);
63 void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap,
64                                         uint8_t *buf, uint64_t offset,
65                                         uint64_t bytes, bool finish);
66 void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap,
67                                           uint64_t offset, uint64_t bytes,
68                                           bool finish);
69 void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap,
70                                         uint64_t offset, uint64_t bytes,
71                                         bool finish);
72 void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
73 
74 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
75 void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap,
76                                        bool persistent);
77 void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);
78 void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
79 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
80                              HBitmap **backup, Error **errp);
81 void bdrv_dirty_bitmap_skip_store(BdrvDirtyBitmap *bitmap, bool skip);
82 bool bdrv_dirty_bitmap_get(BdrvDirtyBitmap *bitmap, int64_t offset);
83 
84 /* Functions that require manual locking.  */
85 void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap);
86 void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap);
87 bool bdrv_dirty_bitmap_get_locked(BdrvDirtyBitmap *bitmap, int64_t offset);
88 void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
89                                   int64_t offset, int64_t bytes);
90 void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
91                                     int64_t offset, int64_t bytes);
92 int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter);
93 void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset);
94 int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
95 void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes);
96 bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
97 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
98 bool bdrv_has_named_bitmaps(BlockDriverState *bs);
99 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
100 bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap);
101 bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
102 
103 BdrvDirtyBitmap *bdrv_dirty_bitmap_first(BlockDriverState *bs);
104 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BdrvDirtyBitmap *bitmap);
105 #define FOR_EACH_DIRTY_BITMAP(bs, bitmap) \
106 for (bitmap = bdrv_dirty_bitmap_first(bs); bitmap; \
107      bitmap = bdrv_dirty_bitmap_next(bitmap))
108 
109 char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp);
110 int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *bitmap, int64_t offset,
111                                      int64_t bytes);
112 int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offset,
113                                     int64_t bytes);
114 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
115         int64_t start, int64_t end, int64_t max_dirty_count,
116         int64_t *dirty_start, int64_t *dirty_count);
117 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
118                                                   Error **errp);
119 
120 #endif
121