xref: /openbmc/qemu/include/block/dirty-bitmap.h (revision 500016e5)
1 #ifndef BLOCK_DIRTY_BITMAP_H
2 #define BLOCK_DIRTY_BITMAP_H
3 
4 #include "qemu-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 BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
19                                           uint32_t granularity,
20                                           const char *name,
21                                           Error **errp);
22 void bdrv_create_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap,
23                                    int chunk_size);
24 void bdrv_release_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap);
25 int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
26                                        BdrvDirtyBitmap *bitmap,
27                                        Error **errp);
28 BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
29                                             BdrvDirtyBitmap *bitmap,
30                                             Error **errp);
31 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
32                                            BdrvDirtyBitmap *bitmap,
33                                            Error **errp);
34 void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap);
35 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
36                                         const char *name);
37 int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
38                             Error **errp);
39 void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
40 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
41 void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs,
42                                          const char *name,
43                                          Error **errp);
44 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
45 void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
46 void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap);
47 BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
48 uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
49 uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap);
50 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap);
51 bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap);
52 const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap);
53 int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap);
54 DirtyBitmapStatus bdrv_dirty_bitmap_status(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_meta_iter_new(BdrvDirtyBitmap *bitmap);
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 void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
67                                       uint8_t *buf, uint64_t offset,
68                                       uint64_t bytes);
69 void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap,
70                                         uint8_t *buf, uint64_t offset,
71                                         uint64_t bytes, bool finish);
72 void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap,
73                                           uint64_t offset, uint64_t bytes,
74                                           bool finish);
75 void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap,
76                                         uint64_t offset, uint64_t bytes,
77                                         bool finish);
78 void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
79 
80 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
81 void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap,
82                                        bool persistent);
83 void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);
84 void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
85 void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
86                              HBitmap **backup, Error **errp);
87 void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migration);
88 
89 /* Functions that require manual locking.  */
90 void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap);
91 void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap);
92 bool bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
93                            int64_t offset);
94 void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
95                                   int64_t offset, int64_t bytes);
96 void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
97                                     int64_t offset, int64_t bytes);
98 int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter);
99 void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset);
100 int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
101 int64_t bdrv_get_meta_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_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
106 bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap);
107 bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
108 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
109 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
110                                         BdrvDirtyBitmap *bitmap);
111 char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp);
112 int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t offset,
113                                     uint64_t bytes);
114 bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
115                                        uint64_t *offset, uint64_t *bytes);
116 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
117                                                   BdrvDirtyBitmap *bitmap,
118                                                   Error **errp);
119 
120 #endif
121