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