diff mbox series

[RFC,v2,5/6] bitmaps: prohibit enable/disable on locked/frozen bitmaps

Message ID 20180921222847.1012-6-jsnow@redhat.com (mailing list archive)
State New, archived
Headers show
Series dirty-bitmaps: fix QMP command permissions | expand

Commit Message

John Snow Sept. 21, 2018, 10:28 p.m. UTC
We're not being consistent about this. If it's in use by an operation,
the user should not be able to change the behavior of that bitmap.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 blockdev.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/blockdev.c b/blockdev.c
index 070180898f..651c50d1fa 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2058,6 +2058,13 @@  static void block_dirty_bitmap_enable_prepare(BlkActionState *common,
         return;
     }
 
+    if (!bdrv_dirty_bitmap_user_modifiable(state->bitmap)) {
+        error_setg(errp,
+                   "Bitmap '%s' is currently in-use by another operation and cannot be enabled",
+                   action->name);
+        return;
+    }
+
     state->was_enabled = bdrv_dirty_bitmap_enabled(state->bitmap);
     bdrv_enable_dirty_bitmap(state->bitmap);
 }
@@ -2092,6 +2099,13 @@  static void block_dirty_bitmap_disable_prepare(BlkActionState *common,
         return;
     }
 
+    if (!bdrv_dirty_bitmap_user_modifiable(state->bitmap)) {
+        error_setg(errp,
+                   "Bitmap '%s' is currently in-use by another operation and cannot be disabled",
+                   action->name);
+        return;
+    }
+
     state->was_enabled = bdrv_dirty_bitmap_enabled(state->bitmap);
     bdrv_disable_dirty_bitmap(state->bitmap);
 }
@@ -2892,9 +2906,9 @@  void qmp_x_block_dirty_bitmap_enable(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 enabled",
+                   "Bitmap '%s' is currently in-use by another operation and cannot be enabled",
                    name);
         return;
     }
@@ -2913,9 +2927,9 @@  void qmp_x_block_dirty_bitmap_disable(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 disabled",
+                   "Bitmap '%s' is currently in-use by another operation and cannot be disabled",
                    name);
         return;
     }