blob: 40950ae3d589dba544cfff99380159ce03bf59f6 [file] [log] [blame]
Fam Zhengebab2252016-03-08 12:44:55 +08001#ifndef BLOCK_DIRTY_BITMAP_H
2#define BLOCK_DIRTY_BITMAP_H
3
Markus Armbruster9af23982018-02-11 10:36:01 +01004#include "qapi/qapi-types-block-core.h"
Fam Zhengebab2252016-03-08 12:44:55 +08005#include "qemu/hbitmap.h"
6
John Snow3ae96d62019-03-12 12:05:49 -04007typedef 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
Eric Blakecf7c49c2019-11-13 20:46:33 -060017#define BDRV_BITMAP_MAX_NAME_SIZE 1023
18
Eric Blakeef893b52020-05-12 20:16:42 -050019bool bdrv_supports_persistent_dirty_bitmap(BlockDriverState *bs);
Fam Zhengebab2252016-03-08 12:44:55 +080020BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
21 uint32_t granularity,
22 const char *name,
23 Error **errp);
Vladimir Sementsov-Ogievskiy5deb6cb2019-09-16 17:19:09 +030024int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap,
Fam Zhengebab2252016-03-08 12:44:55 +080025 Error **errp);
Vladimir Sementsov-Ogievskiy5deb6cb2019-09-16 17:19:09 +030026BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap,
Fam Zhengebab2252016-03-08 12:44:55 +080027 Error **errp);
Vladimir Sementsov-Ogievskiy5deb6cb2019-09-16 17:19:09 +030028BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *bitmap,
Fam Zhengebab2252016-03-08 12:44:55 +080029 Error **errp);
Vladimir Sementsov-Ogievskiye73a2652018-03-13 15:33:59 -040030void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap);
Fam Zhengebab2252016-03-08 12:44:55 +080031BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
32 const char *name);
John Snow3ae96d62019-03-12 12:05:49 -040033int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
34 Error **errp);
Vladimir Sementsov-Ogievskiy5deb6cb2019-09-16 17:19:09 +030035void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap);
Fam Zhengebab2252016-03-08 12:44:55 +080036void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
Vladimir Sementsov-Ogievskiyb56a1e32019-09-20 11:25:42 +030037int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name,
38 Error **errp);
Fam Zhengebab2252016-03-08 12:44:55 +080039void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
40void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
Vladimir Sementsov-Ogievskiy92bcea42018-07-04 02:12:49 -040041void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap);
Fam Zhengebab2252016-03-08 12:44:55 +080042BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
43uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
Vladimir Sementsov-Ogievskiyba06ff12017-06-28 15:05:05 +030044uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap);
Fam Zhengebab2252016-03-08 12:44:55 +080045bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap);
John Snow50a47252019-03-12 12:05:48 -040046bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap);
Fam Zheng15891fa2016-10-13 17:58:25 -040047const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap);
48int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap);
Fam Zhengebab2252016-03-08 12:44:55 +080049void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap,
Eric Blakee0d7f732017-09-25 09:55:20 -050050 int64_t offset, int64_t bytes);
Fam Zhengebab2252016-03-08 12:44:55 +080051void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
Eric Blakee0d7f732017-09-25 09:55:20 -050052 int64_t offset, int64_t bytes);
Eric Blake715a74d2017-09-25 09:55:16 -050053BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap);
Fam Zhengdc162c82016-10-13 17:58:21 -040054void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter);
Fam Zhengebab2252016-03-08 12:44:55 +080055
Vladimir Sementsov-Ogievskiy882c36f2016-10-13 17:58:28 -040056uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap,
Eric Blake86f6ae62017-09-25 09:55:14 -050057 uint64_t offset, uint64_t bytes);
Vladimir Sementsov-Ogievskiy882c36f2016-10-13 17:58:28 -040058uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap);
Vladimir Sementsov-Ogievskiy35f428b2021-02-24 13:47:02 +030059uint64_t bdrv_dirty_bitmap_serialization_coverage(int serialized_chunk_size,
60 const BdrvDirtyBitmap *bitmap);
Vladimir Sementsov-Ogievskiy882c36f2016-10-13 17:58:28 -040061void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
Eric Blake86f6ae62017-09-25 09:55:14 -050062 uint8_t *buf, uint64_t offset,
63 uint64_t bytes);
Vladimir Sementsov-Ogievskiy882c36f2016-10-13 17:58:28 -040064void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap,
Eric Blake86f6ae62017-09-25 09:55:14 -050065 uint8_t *buf, uint64_t offset,
66 uint64_t bytes, bool finish);
Vladimir Sementsov-Ogievskiy882c36f2016-10-13 17:58:28 -040067void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap,
Eric Blake86f6ae62017-09-25 09:55:14 -050068 uint64_t offset, uint64_t bytes,
Vladimir Sementsov-Ogievskiy882c36f2016-10-13 17:58:28 -040069 bool finish);
Vladimir Sementsov-Ogievskiy6bdc8b72017-06-28 15:05:06 +030070void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap,
Eric Blake86f6ae62017-09-25 09:55:14 -050071 uint64_t offset, uint64_t bytes,
Vladimir Sementsov-Ogievskiy6bdc8b72017-06-28 15:05:06 +030072 bool finish);
Vladimir Sementsov-Ogievskiy882c36f2016-10-13 17:58:28 -040073void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
74
Vladimir Sementsov-Ogievskiyd6883bc2017-06-28 15:05:10 +030075void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
Eric Blake796a3792019-03-12 12:05:49 -040076void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap,
Vladimir Sementsov-Ogievskiya88b1792017-06-28 15:05:17 +030077 bool persistent);
John Snowb0f45552019-03-12 12:05:49 -040078void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);
John Snow27a1b302019-03-12 12:05:48 -040079void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
Vladimir Sementsov-Ogievskiyb598e532018-06-11 14:53:32 -040080void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
Vladimir Sementsov-Ogievskiyfa000f22018-10-29 16:23:15 -040081 HBitmap **backup, Error **errp);
John Snowc4e4b0f2019-07-29 16:35:54 -040082void bdrv_dirty_bitmap_skip_store(BdrvDirtyBitmap *bitmap, bool skip);
John Snow28636b82019-07-29 16:35:53 -040083bool bdrv_dirty_bitmap_get(BdrvDirtyBitmap *bitmap, int64_t offset);
Vladimir Sementsov-Ogievskiyd6883bc2017-06-28 15:05:10 +030084
Paolo Bonzinib64bd512017-06-05 14:39:05 +020085/* Functions that require manual locking. */
86void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap);
87void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap);
John Snow28636b82019-07-29 16:35:53 -040088bool bdrv_dirty_bitmap_get_locked(BdrvDirtyBitmap *bitmap, int64_t offset);
Paolo Bonzinib64bd512017-06-05 14:39:05 +020089void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
Eric Blakee0d7f732017-09-25 09:55:20 -050090 int64_t offset, int64_t bytes);
Paolo Bonzinib64bd512017-06-05 14:39:05 +020091void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
Eric Blakee0d7f732017-09-25 09:55:20 -050092 int64_t offset, int64_t bytes);
Paolo Bonzinib64bd512017-06-05 14:39:05 +020093int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter);
Eric Blake715a74d2017-09-25 09:55:16 -050094void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset);
Paolo Bonzinib64bd512017-06-05 14:39:05 +020095int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
Eric Blake1b6cc572017-09-25 09:55:11 -050096void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes);
Vladimir Sementsov-Ogievskiyd6883bc2017-06-28 15:05:10 +030097bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
98bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
Vladimir Sementsov-Ogievskiy7ae89a02020-05-22 01:06:44 +030099bool bdrv_has_named_bitmaps(BlockDriverState *bs);
Vladimir Sementsov-Ogievskiya0319aa2017-06-28 15:05:15 +0300100bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
Eric Blake796a3792019-03-12 12:05:49 -0400101bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap);
John Snowb0f45552019-03-12 12:05:49 -0400102bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
Vladimir Sementsov-Ogievskiyef9041a2019-09-16 17:19:11 +0300103
104BdrvDirtyBitmap *bdrv_dirty_bitmap_first(BlockDriverState *bs);
105BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BdrvDirtyBitmap *bitmap);
106#define FOR_EACH_DIRTY_BITMAP(bs, bitmap) \
107for (bitmap = bdrv_dirty_bitmap_first(bs); bitmap; \
108 bitmap = bdrv_dirty_bitmap_next(bitmap))
109
Vladimir Sementsov-Ogievskiya3b52532017-06-28 15:05:25 +0300110char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp);
Vladimir Sementsov-Ogievskiy9399c542020-02-05 14:20:37 +0300111int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *bitmap, int64_t offset,
112 int64_t bytes);
Vladimir Sementsov-Ogievskiy642700f2020-02-05 14:20:36 +0300113int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offset,
114 int64_t bytes);
Vladimir Sementsov-Ogievskiya78a1a42019-01-15 18:26:50 -0500115bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
Vladimir Sementsov-Ogievskiy299ea9f2020-02-05 14:20:38 +0300116 int64_t start, int64_t end, int64_t max_dirty_count,
117 int64_t *dirty_start, int64_t *dirty_count);
Vladimir Sementsov-Ogievskiy5deb6cb2019-09-16 17:19:09 +0300118BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
Vladimir Sementsov-Ogievskiy044ee8e2018-03-13 15:34:00 -0400119 Error **errp);
Paolo Bonzinib64bd512017-06-05 14:39:05 +0200120
Fam Zhengebab2252016-03-08 12:44:55 +0800121#endif