yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-dirty-bitmaps-add-user_locked-status-checker.patch

ae23c9
From e1a7b82bc7f0dc8f65c9bf07acbcdca1fb08bb17 Mon Sep 17 00:00:00 2001
ae23c9
From: John Snow <jsnow@redhat.com>
ae23c9
Date: Tue, 20 Nov 2018 18:18:16 +0000
ae23c9
Subject: [PATCH 22/35] block/dirty-bitmaps: add user_locked status checker
ae23c9
ae23c9
RH-Author: John Snow <jsnow@redhat.com>
ae23c9
Message-id: <20181120181828.15132-13-jsnow@redhat.com>
ae23c9
Patchwork-id: 83056
ae23c9
O-Subject: [RHEL8/rhel qemu-kvm PATCH 12/24] block/dirty-bitmaps: add user_locked status checker
ae23c9
Bugzilla: 1518989
ae23c9
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ae23c9
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ae23c9
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
ae23c9
Instead of both frozen and qmp_locked checks, wrap it into one check.
ae23c9
frozen implies the bitmap is split in two (for backup), and shouldn't
ae23c9
be modified. qmp_locked implies it's being used by another operation,
ae23c9
like being exported over NBD. In both cases it means we shouldn't allow
ae23c9
the user to modify it in any meaningful way.
ae23c9
ae23c9
Replace any usages where we check both frozen and qmp_locked with the
ae23c9
new check.
ae23c9
ae23c9
Signed-off-by: John Snow <jsnow@redhat.com>
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
Message-id: 20181002230218.13949-2-jsnow@redhat.com
ae23c9
[w/edits Suggested-By: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>]
ae23c9
Signed-off-by: John Snow <jsnow@redhat.com>
ae23c9
(cherry picked from commit 993edc0ce0c6f44deb8272a7a857e419417f5f84)
ae23c9
Signed-off-by: John Snow <jsnow@redhat.com>
ae23c9
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 block/dirty-bitmap.c           |  6 ++++++
ae23c9
 blockdev.c                     | 29 ++++++++---------------------
ae23c9
 include/block/dirty-bitmap.h   |  1 +
ae23c9
 migration/block-dirty-bitmap.c | 10 ++--------
ae23c9
 4 files changed, 17 insertions(+), 29 deletions(-)
ae23c9
ae23c9
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
ae23c9
index 8ac933c..9603cdd 100644
ae23c9
--- a/block/dirty-bitmap.c
ae23c9
+++ b/block/dirty-bitmap.c
ae23c9
@@ -176,6 +176,12 @@ bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap)
ae23c9
     return bitmap->successor;
ae23c9
 }
ae23c9
 
ae23c9
+/* Both conditions disallow user-modification via QMP. */
ae23c9
+bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap) {
ae23c9
+    return bdrv_dirty_bitmap_frozen(bitmap) ||
ae23c9
+           bdrv_dirty_bitmap_qmp_locked(bitmap);
ae23c9
+}
ae23c9
+
ae23c9
 void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_locked)
ae23c9
 {
ae23c9
     qemu_mutex_lock(bitmap->mutex);
ae23c9
diff --git a/blockdev.c b/blockdev.c
ae23c9
index d2e7e5a..5cdb608 100644
ae23c9
--- a/blockdev.c
ae23c9
+++ b/blockdev.c
ae23c9
@@ -2119,11 +2119,8 @@ static void block_dirty_bitmap_clear_prepare(BlkActionState *common,
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    if (bdrv_dirty_bitmap_frozen(state->bitmap)) {
ae23c9
-        error_setg(errp, "Cannot modify a frozen bitmap");
ae23c9
-        return;
ae23c9
-    } else if (bdrv_dirty_bitmap_qmp_locked(state->bitmap)) {
ae23c9
-        error_setg(errp, "Cannot modify a locked bitmap");
ae23c9
+    if (bdrv_dirty_bitmap_user_locked(state->bitmap)) {
ae23c9
+        error_setg(errp, "Cannot modify a bitmap in use by another operation");
ae23c9
         return;
ae23c9
     } else if (!bdrv_dirty_bitmap_enabled(state->bitmap)) {
ae23c9
         error_setg(errp, "Cannot clear a disabled bitmap");
ae23c9
@@ -2992,15 +2989,10 @@ void qmp_block_dirty_bitmap_remove(const char *node, const char *name,
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    if (bdrv_dirty_bitmap_frozen(bitmap)) {
ae23c9
-        error_setg(errp,
ae23c9
-                   "Bitmap '%s' is currently frozen and cannot be removed",
ae23c9
-                   name);
ae23c9
-        return;
ae23c9
-    } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) {
ae23c9
+    if (bdrv_dirty_bitmap_user_locked(bitmap)) {
ae23c9
         error_setg(errp,
ae23c9
-                   "Bitmap '%s' is currently locked and cannot be removed",
ae23c9
-                   name);
ae23c9
+                   "Bitmap '%s' is currently in use by another operation and"
ae23c9
+                   " cannot be removed", name);
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
@@ -3030,15 +3022,10 @@ void qmp_block_dirty_bitmap_clear(const char *node, const char *name,
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    if (bdrv_dirty_bitmap_frozen(bitmap)) {
ae23c9
+    if (bdrv_dirty_bitmap_user_locked(bitmap)) {
ae23c9
         error_setg(errp,
ae23c9
-                   "Bitmap '%s' is currently frozen and cannot be modified",
ae23c9
-                   name);
ae23c9
-        return;
ae23c9
-    } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) {
ae23c9
-        error_setg(errp,
ae23c9
-                   "Bitmap '%s' is currently locked and cannot be modified",
ae23c9
-                   name);
ae23c9
+                   "Bitmap '%s' is currently in use by another operation"
ae23c9
+                   " and cannot be cleared", name);
ae23c9
         return;
ae23c9
     } else if (!bdrv_dirty_bitmap_enabled(bitmap)) {
ae23c9
         error_setg(errp,
ae23c9
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
ae23c9
index 201ff7f..1463943 100644
ae23c9
--- a/include/block/dirty-bitmap.h
ae23c9
+++ b/include/block/dirty-bitmap.h
ae23c9
@@ -94,6 +94,7 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs);
ae23c9
 bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap);
ae23c9
 bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap);
ae23c9
 bool bdrv_dirty_bitmap_qmp_locked(BdrvDirtyBitmap *bitmap);
ae23c9
+bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap);
ae23c9
 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs);
ae23c9
 BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs,
ae23c9
                                         BdrvDirtyBitmap *bitmap);
ae23c9
diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
ae23c9
index fefbc6a..47251af 100644
ae23c9
--- a/migration/block-dirty-bitmap.c
ae23c9
+++ b/migration/block-dirty-bitmap.c
ae23c9
@@ -301,14 +301,8 @@ static int init_dirty_bitmap_migration(void)
ae23c9
                 goto fail;
ae23c9
             }
ae23c9
 
ae23c9
-            if (bdrv_dirty_bitmap_frozen(bitmap)) {
ae23c9
-                error_report("Can't migrate frozen dirty bitmap: '%s",
ae23c9
-                             bdrv_dirty_bitmap_name(bitmap));
ae23c9
-                goto fail;
ae23c9
-            }
ae23c9
-
ae23c9
-            if (bdrv_dirty_bitmap_qmp_locked(bitmap)) {
ae23c9
-                error_report("Can't migrate locked dirty bitmap: '%s",
ae23c9
+            if (bdrv_dirty_bitmap_user_locked(bitmap)) {
ae23c9
+                error_report("Can't migrate a bitmap that is in use by another operation: '%s'",
ae23c9
                              bdrv_dirty_bitmap_name(bitmap));
ae23c9
                 goto fail;
ae23c9
             }
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9