2016-03-08 05:44:55 +01:00
|
|
|
#ifndef BLOCK_DIRTY_BITMAP_H
|
|
|
|
#define BLOCK_DIRTY_BITMAP_H
|
|
|
|
|
2022-12-21 14:35:49 +01:00
|
|
|
#include "block/block-common.h"
|
2018-02-11 10:36:01 +01:00
|
|
|
#include "qapi/qapi-types-block-core.h"
|
2016-03-08 05:44:55 +01:00
|
|
|
#include "qemu/hbitmap.h"
|
|
|
|
|
2019-03-12 17:05:49 +01:00
|
|
|
typedef enum BitmapCheckFlags {
|
|
|
|
BDRV_BITMAP_BUSY = 1,
|
|
|
|
BDRV_BITMAP_RO = 2,
|
|
|
|
BDRV_BITMAP_INCONSISTENT = 4,
|
|
|
|
} BitmapCheckFlags;
|
|
|
|
|
|
|
|
#define BDRV_BITMAP_DEFAULT (BDRV_BITMAP_BUSY | BDRV_BITMAP_RO | \
|
|
|
|
BDRV_BITMAP_INCONSISTENT)
|
|
|
|
#define BDRV_BITMAP_ALLOW_RO (BDRV_BITMAP_BUSY | BDRV_BITMAP_INCONSISTENT)
|
|
|
|
|
2019-11-14 03:46:33 +01:00
|
|
|
#define BDRV_BITMAP_MAX_NAME_SIZE 1023
|
|
|
|
|
block: Make it easier to learn which BDS support bitmaps
Upcoming patches will enhance bitmap support in qemu-img, but in doing
so, it turns out to be nice to suppress output when persistent bitmaps
make no sense (such as on a qcow2 v2 image). Add a hook to make this
easier to query.
This patch adds a new callback .bdrv_supports_persistent_dirty_bitmap,
rather than trying to shoehorn the answer in via existing callbacks.
In particular, while it might have been possible to overload
.bdrv_co_can_store_new_dirty_bitmap to special-case a NULL input to
answer whether any persistent bitmaps are supported, that is at odds
with whether a particular bitmap can be stored (for example, even on
an image that supports persistent bitmaps but has currently filled up
the maximum number of bitmaps, attempts to store another one should
fail); and the new functionality doesn't require coroutine safety.
Similarly, we could have added one more piece of information to
.bdrv_get_info, but then again, most callers to that function tend to
already discard extraneous information, and making it a catch-all
rather than a series of dedicated scalar queries hasn't really
simplified life.
In the future, when we improve the ability to look up bitmaps through
a filter, we will probably also want to teach the block layer to
automatically let filters pass this request on through.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200513011648.166876-4-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2020-05-13 03:16:42 +02:00
|
|
|
bool bdrv_supports_persistent_dirty_bitmap(BlockDriverState *bs);
|
2016-03-08 05:44:55 +01:00
|
|
|
BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
|
|
|
|
uint32_t granularity,
|
|
|
|
const char *name,
|
|
|
|
Error **errp);
|
2019-09-16 16:19:09 +02:00
|
|
|
int bdrv_dirty_bitmap_create_successor(BdrvDirtyBitmap *bitmap,
|
2016-03-08 05:44:55 +01:00
|
|
|
Error **errp);
|
2019-09-16 16:19:09 +02:00
|
|
|
BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BdrvDirtyBitmap *bitmap,
|
2016-03-08 05:44:55 +01:00
|
|
|
Error **errp);
|
2019-09-16 16:19:09 +02:00
|
|
|
BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BdrvDirtyBitmap *bitmap,
|
2016-03-08 05:44:55 +01:00
|
|
|
Error **errp);
|
2018-03-13 20:33:59 +01:00
|
|
|
void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap);
|
2016-03-08 05:44:55 +01:00
|
|
|
BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
|
|
|
|
const char *name);
|
2019-03-12 17:05:49 +01:00
|
|
|
int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitmap, uint32_t flags,
|
|
|
|
Error **errp);
|
2019-09-16 16:19:09 +02:00
|
|
|
void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap);
|
2016-03-08 05:44:55 +01:00
|
|
|
void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
|
2022-11-28 15:23:37 +01:00
|
|
|
|
2023-02-03 16:22:01 +01:00
|
|
|
int coroutine_fn GRAPH_RDLOCK
|
|
|
|
bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name,
|
|
|
|
Error **errp);
|
|
|
|
int co_wrapper_bdrv_rdlock
|
|
|
|
bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name,
|
|
|
|
Error **errp);
|
2022-11-28 15:23:37 +01:00
|
|
|
|
2016-03-08 05:44:55 +01:00
|
|
|
void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
|
|
|
|
void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
|
2018-07-04 08:12:49 +02:00
|
|
|
void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap);
|
2016-03-08 05:44:55 +01:00
|
|
|
BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
|
|
|
|
uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
|
2017-06-28 14:05:05 +02:00
|
|
|
uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap);
|
2016-03-08 05:44:55 +01:00
|
|
|
bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap);
|
2019-03-12 17:05:48 +01:00
|
|
|
bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap);
|
2016-10-13 23:58:25 +02:00
|
|
|
const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap);
|
|
|
|
int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap);
|
2016-03-08 05:44:55 +01:00
|
|
|
void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:20 +02:00
|
|
|
int64_t offset, int64_t bytes);
|
2016-03-08 05:44:55 +01:00
|
|
|
void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:20 +02:00
|
|
|
int64_t offset, int64_t bytes);
|
2017-09-25 16:55:16 +02:00
|
|
|
BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap);
|
2016-10-13 23:58:21 +02:00
|
|
|
void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter);
|
2016-03-08 05:44:55 +01:00
|
|
|
|
2016-10-13 23:58:28 +02:00
|
|
|
uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:14 +02:00
|
|
|
uint64_t offset, uint64_t bytes);
|
2016-10-13 23:58:28 +02:00
|
|
|
uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap);
|
2021-02-24 11:47:02 +01:00
|
|
|
uint64_t bdrv_dirty_bitmap_serialization_coverage(int serialized_chunk_size,
|
|
|
|
const BdrvDirtyBitmap *bitmap);
|
2016-10-13 23:58:28 +02:00
|
|
|
void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:14 +02:00
|
|
|
uint8_t *buf, uint64_t offset,
|
|
|
|
uint64_t bytes);
|
2016-10-13 23:58:28 +02:00
|
|
|
void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:14 +02:00
|
|
|
uint8_t *buf, uint64_t offset,
|
|
|
|
uint64_t bytes, bool finish);
|
2016-10-13 23:58:28 +02:00
|
|
|
void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:14 +02:00
|
|
|
uint64_t offset, uint64_t bytes,
|
2016-10-13 23:58:28 +02:00
|
|
|
bool finish);
|
2017-06-28 14:05:06 +02:00
|
|
|
void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:14 +02:00
|
|
|
uint64_t offset, uint64_t bytes,
|
2017-06-28 14:05:06 +02:00
|
|
|
bool finish);
|
2016-10-13 23:58:28 +02:00
|
|
|
void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap);
|
|
|
|
|
2017-06-28 14:05:10 +02:00
|
|
|
void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value);
|
2019-03-12 17:05:49 +01:00
|
|
|
void bdrv_dirty_bitmap_set_persistence(BdrvDirtyBitmap *bitmap,
|
2017-06-28 14:05:17 +02:00
|
|
|
bool persistent);
|
2019-03-12 17:05:49 +01:00
|
|
|
void bdrv_dirty_bitmap_set_inconsistent(BdrvDirtyBitmap *bitmap);
|
2019-03-12 17:05:48 +01:00
|
|
|
void bdrv_dirty_bitmap_set_busy(BdrvDirtyBitmap *bitmap, bool busy);
|
2022-03-03 20:43:35 +01:00
|
|
|
bool bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
|
2018-10-29 21:23:15 +01:00
|
|
|
HBitmap **backup, Error **errp);
|
2019-07-29 22:35:54 +02:00
|
|
|
void bdrv_dirty_bitmap_skip_store(BdrvDirtyBitmap *bitmap, bool skip);
|
2019-07-29 22:35:53 +02:00
|
|
|
bool bdrv_dirty_bitmap_get(BdrvDirtyBitmap *bitmap, int64_t offset);
|
2017-06-28 14:05:10 +02:00
|
|
|
|
2017-06-05 14:39:05 +02:00
|
|
|
/* Functions that require manual locking. */
|
|
|
|
void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap);
|
|
|
|
void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap);
|
2019-07-29 22:35:53 +02:00
|
|
|
bool bdrv_dirty_bitmap_get_locked(BdrvDirtyBitmap *bitmap, int64_t offset);
|
2017-06-05 14:39:05 +02:00
|
|
|
void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:20 +02:00
|
|
|
int64_t offset, int64_t bytes);
|
2017-06-05 14:39:05 +02:00
|
|
|
void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
|
2017-09-25 16:55:20 +02:00
|
|
|
int64_t offset, int64_t bytes);
|
2017-06-05 14:39:05 +02:00
|
|
|
int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter);
|
2017-09-25 16:55:16 +02:00
|
|
|
void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t offset);
|
2017-06-05 14:39:05 +02:00
|
|
|
int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
|
2017-09-25 16:55:11 +02:00
|
|
|
void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes);
|
2017-06-28 14:05:10 +02:00
|
|
|
bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap);
|
|
|
|
bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
|
2020-05-22 00:06:44 +02:00
|
|
|
bool bdrv_has_named_bitmaps(BlockDriverState *bs);
|
2017-06-28 14:05:15 +02:00
|
|
|
bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
|
2019-03-12 17:05:49 +01:00
|
|
|
bool bdrv_dirty_bitmap_get_persistence(BdrvDirtyBitmap *bitmap);
|
2019-03-12 17:05:49 +01:00
|
|
|
bool bdrv_dirty_bitmap_inconsistent(const BdrvDirtyBitmap *bitmap);
|
2019-09-16 16:19:11 +02:00
|
|
|
|
|
|
|
BdrvDirtyBitmap *bdrv_dirty_bitmap_first(BlockDriverState *bs);
|
|
|
|
BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BdrvDirtyBitmap *bitmap);
|
|
|
|
#define FOR_EACH_DIRTY_BITMAP(bs, bitmap) \
|
|
|
|
for (bitmap = bdrv_dirty_bitmap_first(bs); bitmap; \
|
|
|
|
bitmap = bdrv_dirty_bitmap_next(bitmap))
|
|
|
|
|
2017-06-28 14:05:25 +02:00
|
|
|
char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp);
|
2020-02-05 12:20:37 +01:00
|
|
|
int64_t bdrv_dirty_bitmap_next_dirty(BdrvDirtyBitmap *bitmap, int64_t offset,
|
|
|
|
int64_t bytes);
|
2020-02-05 12:20:36 +01:00
|
|
|
int64_t bdrv_dirty_bitmap_next_zero(BdrvDirtyBitmap *bitmap, int64_t offset,
|
|
|
|
int64_t bytes);
|
2019-01-16 00:26:50 +01:00
|
|
|
bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap *bitmap,
|
2020-02-05 12:20:38 +01:00
|
|
|
int64_t start, int64_t end, int64_t max_dirty_count,
|
|
|
|
int64_t *dirty_start, int64_t *dirty_count);
|
2022-03-03 20:43:41 +01:00
|
|
|
bool bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap, int64_t offset,
|
|
|
|
int64_t bytes, int64_t *count);
|
2019-09-16 16:19:09 +02:00
|
|
|
BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap,
|
2018-03-13 20:34:00 +01:00
|
|
|
Error **errp);
|
2017-06-05 14:39:05 +02:00
|
|
|
|
2016-03-08 05:44:55 +01:00
|
|
|
#endif
|