xref: /openbmc/qemu/include/block/dirty-bitmap.h (revision 0dacec87)
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 BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
9                                           uint32_t granularity,
10                                           const char *name,
11                                           Error **errp);
12 void bdrv_create_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap,
13                                    int chunk_size);
14 void bdrv_release_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap);
15 int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
16                                        BdrvDirtyBitmap *bitmap,
17                                        Error **errp);
18 BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
19                                             BdrvDirtyBitmap *bitmap,
20                                             Error **errp);
21 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
22                                            BdrvDirtyBitmap *bitmap,
23                                            Error **errp);
24 void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap);
25 BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
26                                         const char *name);
27 void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap);
28 void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
29 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
30 void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs);
31 void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs,
32                                          const char *name,
33                                          Error **errp);
34 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
35 void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
36 BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
37 uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
38 uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap);
39 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap);
40 bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap);
41 const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap);
42 int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap);
43 DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap);
44 void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap,
45                            int64_t offset, int64_t bytes);
46 void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
47                              int64_t offset, int64_t bytes);
48 BdrvDirtyBitmapIter *bdrv_dirty_meta_iter_new(BdrvDirtyBitmap *bitmap);
49 BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap);
50 void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter);
51 
52 uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap,
53                                               uint64_t offset, uint64_t bytes);
54 uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap);
55 void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
56                                       uint8_t *buf, uint64_t offset,
57                                       uint64_t bytes);
58 void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap,
59                                         uint8_t *buf, uint64_t offset,
60                                         uint64_t bytes, bool finish);
61 void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap,
62                                           uint64_t offset, uint64_t bytes,
63                                           bool finish);
64 void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap,
65                                         uint64_t offset, uint64_t bytes,
66                                         bool finish);
67 void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
68 
69 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
70 void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap,
71                                        bool persistent);
72 void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked);
73 
74 
75 /* Functions that require manual locking.  */
76 void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap);
77 void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap);
78 bool bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
79                            int64_t offset);
80 void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
81                                   int64_t offset, int64_t bytes);
82 void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
83                                     int64_t offset, int64_t bytes);
84 int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter);
85 void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset);
86 int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
87 int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap);
88 void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes);
89 bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
90 bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
91 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
92 bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
93 bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap);
94 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
95 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
96                                         BdrvDirtyBitmap *bitmap);
97 char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp);
98 int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, uint64_t start);
99 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
100                                                   BdrvDirtyBitmap *bitmap,
101                                                   Error **errp);
102 
103 #endif
104