@@ -176,6 +176,12 @@ bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap)
return bitmap->successor;
}
+/* Both conditions disallow user-modification via QMP. */
+bool bdrv_dirty_bitmap_user_modifiable(BdrvDirtyBitmap *bitmap) {
+ return !(bdrv_dirty_bitmap_frozen(bitmap) ||
+ bdrv_dirty_bitmap_qmp_locked(bitmap));
+}
+
void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked)
{
qemu_mutex_lock(bitmap->mutex);
@@ -797,8 +803,7 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap *src,
qemu_mutex_lock(dest->mutex);
- assert(!bdrv_dirty_bitmap_frozen(dest));
- assert(!bdrv_dirty_bitmap_qmp_locked(dest));
+ assert(bdrv_dirty_bitmap_user_modifiable(dest));
assert(!bdrv_dirty_bitmap_readonly(dest));
if (!hbitmap_merge(dest->bitmap, src->bitmap)) {
@@ -2009,11 +2009,8 @@ static void block_dirty_bitmap_clear_prepare(BlkActionState *common,
return;
}
- if (bdrv_dirty_bitmap_frozen(state->bitmap)) {
- error_setg(errp, "Cannot modify a frozen bitmap");
- return;
- } else if (bdrv_dirty_bitmap_qmp_locked(state->bitmap)) {
- error_setg(errp, "Cannot modify a locked bitmap");
+ if (!bdrv_dirty_bitmap_user_modifiable(state->bitmap)) {
+ error_setg(errp, "Cannot modify a bitmap in-use by another operation");
return;
} else if (bdrv_dirty_bitmap_readonly(state->bitmap)) {
error_setg(errp, "Cannot clear a readonly bitmap");
@@ -2838,14 +2835,9 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name,
return;
}
- if (bdrv_dirty_bitmap_frozen(bitmap)) {
+ if (!bdrv_dirty_bitmap_user_modifiable(bitmap)) {
error_setg(errp,
- "Bitmap '%s' is currently frozen and cannot be removed",
- name);
- return;
- } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) {
- error_setg(errp,
- "Bitmap '%s' is currently locked and cannot be removed",
+ "Bitmap '%s' is currently in-use by another operation and cannot be removed",
name);
return;
}
@@ -2876,14 +2868,9 @@ void qmp_block_dirty_bitmap_clear(const char *node, const char *name,
return;
}
- if (bdrv_dirty_bitmap_frozen(bitmap)) {
+ if (!bdrv_dirty_bitmap_user_modifiable(bitmap)) {
error_setg(errp,
- "Bitmap '%s' is currently frozen and cannot be modified",
- name);
- return;
- } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) {
- error_setg(errp,
- "Bitmap '%s' is currently locked and cannot be modified",
+ "Bitmap '%s' is currently in-use by another operation and cannot be cleared",
name);
return;
} else if (bdrv_dirty_bitmap_readonly(bitmap)) {
@@ -2947,18 +2934,15 @@ void qmp_x_block_dirty_bitmap_merge(const char *node, const char *dst_name,
return;
}
- if (bdrv_dirty_bitmap_frozen(dst)) {
- error_setg(errp, "Bitmap '%s' is frozen and cannot be modified",
+ if (!bdrv_dirty_bitmap_user_modifiable(dst)) {
+ error_setg(errp,
+ "Bitmap '%s' is currently in-use by another operation and cannot be modified",
dst_name);
return;
} else if (bdrv_dirty_bitmap_readonly(dst)) {
error_setg(errp, "Bitmap '%s' is readonly and cannot be modified",
dst_name);
return;
- } else if (bdrv_dirty_bitmap_qmp_locked(dst)) {
- error_setg(errp, "Bitmap '%s' is in-use by an operation "
- "and cannot be modified", dst_name);
- return;
}
src = bdrv_find_dirty_bitmap(bs, src_name);
@@ -94,6 +94,7 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap);
+bool bdrv_dirty_bitmap_user_modifiable(BdrvDirtyBitmap *bitmap);
bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
BdrvDirtyBitmap *bitmap);
Instead of both frozen and qmp_locked checks, wrap it into one check. frozen implies the bitmap is split in two (for backup), and shouldn't be modified. qmp_locked implies it's being used by another operation, like being exported over NBD. In both cases it means we shouldn't allow the user to modify it in any meaningful way. Replace any usages where we check both frozen and qmp_locked with the new check. Signed-off-by: John Snow <jsnow@redhat.com> --- block/dirty-bitmap.c | 9 +++++++-- blockdev.c | 34 +++++++++------------------------- include/block/dirty-bitmap.h | 1 + 3 files changed, 17 insertions(+), 27 deletions(-)