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

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