Blame SOURCES/kvm-block-dirty-bitmaps-rename-frozen-predicate-helper.patch

7711c0
From 1e53f224150ad795131e8ea93605979de0e3c40c Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 3 Apr 2019 18:18:40 +0200
7711c0
Subject: [PATCH 135/163] block/dirty-bitmaps: rename frozen predicate helper
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190403181857.9693-5-jsnow@redhat.com>
7711c0
Patchwork-id: 85421
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 04/21] block/dirty-bitmaps: rename frozen predicate helper
7711c0
Bugzilla: 1677073
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
7711c0
7711c0
"Frozen" was a good description a long time ago, but it isn't adequate now.
7711c0
Rename the frozen predicate to has_successor to make the semantics of the
7711c0
predicate more clear to outside callers.
7711c0
7711c0
In the process, remove some calls to frozen() that no longer semantically
7711c0
make sense. For bdrv_enable_dirty_bitmap_locked and
7711c0
bdrv_disable_dirty_bitmap_locked, it doesn't make sense to prohibit QEMU
7711c0
internals from performing this action when we only wished to prohibit QMP
7711c0
users from issuing these commands. All of the QMP API commands for bitmap
7711c0
manipulation already check against user_locked() to prohibit these actions.
7711c0
7711c0
Several other assertions really want to check that the bitmap isn't in-use
7711c0
by another operation -- use the bitmap_user_locked function for this instead,
7711c0
which presently also checks for has_successor. This leaves some redundant
7711c0
checks of has_successor through different helpers that are addressed in
7711c0
forthcoming patches.
7711c0
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Reviewed-by: Eric Blake <eblake@redhat.com>
7711c0
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
Message-id: 20190223000614.13894-3-jsnow@redhat.com
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
(cherry picked from commit 50a47257f8f1368ba08e4789bb63ca84c4306dde)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 block/dirty-bitmap.c           | 32 ++++++++++++++++++--------------
7711c0
 include/block/dirty-bitmap.h   |  2 +-
7711c0
 migration/block-dirty-bitmap.c |  2 +-
7711c0
 3 files changed, 20 insertions(+), 16 deletions(-)
7711c0
7711c0
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
7711c0
index 101383b..f8984b8 100644
7711c0
--- a/block/dirty-bitmap.c
7711c0
+++ b/block/dirty-bitmap.c
7711c0
@@ -50,7 +50,7 @@ struct BdrvDirtyBitmap {
7711c0
     HBitmap *meta;              /* Meta dirty bitmap */
7711c0
     bool qmp_locked;            /* Bitmap is locked, it can't be modified
7711c0
                                    through QMP */
7711c0
-    BdrvDirtyBitmap *successor; /* Anonymous child; implies frozen status */
7711c0
+    BdrvDirtyBitmap *successor; /* Anonymous child; implies user_locked state */
7711c0
     char *name;                 /* Optional non-empty unique ID */
7711c0
     int64_t size;               /* Size of the bitmap, in bytes */
7711c0
     bool disabled;              /* Bitmap is disabled. It ignores all writes to
7711c0
@@ -183,14 +183,14 @@ const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap)
7711c0
 }
7711c0
 
7711c0
 /* Called with BQL taken.  */
7711c0
-bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap)
7711c0
+bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap)
7711c0
 {
7711c0
     return bitmap->successor;
7711c0
 }
7711c0
 
7711c0
 /* Both conditions disallow user-modification via QMP. */
7711c0
 bool bdrv_dirty_bitmap_user_locked(BdrvDirtyBitmap *bitmap) {
7711c0
-    return bdrv_dirty_bitmap_frozen(bitmap) ||
7711c0
+    return bdrv_dirty_bitmap_has_successor(bitmap) ||
7711c0
            bdrv_dirty_bitmap_qmp_locked(bitmap);
7711c0
 }
7711c0
 
7711c0
@@ -215,7 +215,7 @@ bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap)
7711c0
 /* Called with BQL taken.  */
7711c0
 DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap)
7711c0
 {
7711c0
-    if (bdrv_dirty_bitmap_frozen(bitmap)) {
7711c0
+    if (bdrv_dirty_bitmap_has_successor(bitmap)) {
7711c0
         return DIRTY_BITMAP_STATUS_FROZEN;
7711c0
     } else if (bdrv_dirty_bitmap_qmp_locked(bitmap)) {
7711c0
         return DIRTY_BITMAP_STATUS_LOCKED;
7711c0
@@ -235,7 +235,7 @@ static bool bdrv_dirty_bitmap_recording(BdrvDirtyBitmap *bitmap)
7711c0
 
7711c0
 /**
7711c0
  * Create a successor bitmap destined to replace this bitmap after an operation.
7711c0
- * Requires that the bitmap is not frozen and has no successor.
7711c0
+ * Requires that the bitmap is not user_locked and has no successor.
7711c0
  * Called with BQL taken.
7711c0
  */
7711c0
 int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
7711c0
@@ -244,12 +244,16 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
7711c0
     uint64_t granularity;
7711c0
     BdrvDirtyBitmap *child;
7711c0
 
7711c0
-    if (bdrv_dirty_bitmap_frozen(bitmap)) {
7711c0
+    if (bdrv_dirty_bitmap_user_locked(bitmap)) {
7711c0
         error_setg(errp, "Cannot create a successor for a bitmap that is "
7711c0
-                   "currently frozen");
7711c0
+                   "in-use by an operation");
7711c0
+        return -1;
7711c0
+    }
7711c0
+    if (bdrv_dirty_bitmap_has_successor(bitmap)) {
7711c0
+        error_setg(errp, "Cannot create a successor for a bitmap that already "
7711c0
+                   "has one");
7711c0
         return -1;
7711c0
     }
7711c0
-    assert(!bitmap->successor);
7711c0
 
7711c0
     /* Create an anonymous successor */
7711c0
     granularity = bdrv_dirty_bitmap_granularity(bitmap);
7711c0
@@ -268,7 +272,6 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
7711c0
 
7711c0
 void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
7711c0
 {
7711c0
-    assert(!bdrv_dirty_bitmap_frozen(bitmap));
7711c0
     bitmap->disabled = false;
7711c0
 }
7711c0
 
7711c0
@@ -285,7 +288,8 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap)
7711c0
 static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
7711c0
 {
7711c0
     assert(!bitmap->active_iterators);
7711c0
-    assert(!bdrv_dirty_bitmap_frozen(bitmap));
7711c0
+    assert(!bdrv_dirty_bitmap_user_locked(bitmap));
7711c0
+    assert(!bdrv_dirty_bitmap_has_successor(bitmap));
7711c0
     assert(!bitmap->meta);
7711c0
     QLIST_REMOVE(bitmap, list);
7711c0
     hbitmap_free(bitmap->bitmap);
7711c0
@@ -325,7 +329,7 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
7711c0
 /**
7711c0
  * In cases of failure where we can no longer safely delete the parent,
7711c0
  * we may wish to re-join the parent and child/successor.
7711c0
- * The merged parent will be un-frozen, but not explicitly re-enabled.
7711c0
+ * The merged parent will not be user_locked, nor explicitly re-enabled.
7711c0
  * Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken.
7711c0
  */
7711c0
 BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
7711c0
@@ -373,7 +377,8 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
7711c0
 
7711c0
     bdrv_dirty_bitmaps_lock(bs);
7711c0
     QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) {
7711c0
-        assert(!bdrv_dirty_bitmap_frozen(bitmap));
7711c0
+        assert(!bdrv_dirty_bitmap_user_locked(bitmap));
7711c0
+        assert(!bdrv_dirty_bitmap_has_successor(bitmap));
7711c0
         assert(!bitmap->active_iterators);
7711c0
         hbitmap_truncate(bitmap->bitmap, bytes);
7711c0
         bitmap->size = bytes;
7711c0
@@ -391,7 +396,7 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
7711c0
 
7711c0
 /**
7711c0
  * Release all named dirty bitmaps attached to a BDS (for use in bdrv_close()).
7711c0
- * There must not be any frozen bitmaps attached.
7711c0
+ * There must not be any user_locked bitmaps attached.
7711c0
  * This function does not remove persistent bitmaps from the storage.
7711c0
  * Called with BQL taken.
7711c0
  */
7711c0
@@ -428,7 +433,6 @@ void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs,
7711c0
 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap)
7711c0
 {
7711c0
     bdrv_dirty_bitmap_lock(bitmap);
7711c0
-    assert(!bdrv_dirty_bitmap_frozen(bitmap));
7711c0
     bitmap->disabled = true;
7711c0
     bdrv_dirty_bitmap_unlock(bitmap);
7711c0
 }
7711c0
diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h
7711c0
index 04a117f..cdbb4df 100644
7711c0
--- a/include/block/dirty-bitmap.h
7711c0
+++ b/include/block/dirty-bitmap.h
7711c0
@@ -36,7 +36,7 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
7711c0
 uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
7711c0
 uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap);
7711c0
 bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap);
7711c0
-bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap);
7711c0
+bool bdrv_dirty_bitmap_has_successor(BdrvDirtyBitmap *bitmap);
7711c0
 const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap);
7711c0
 int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap);
7711c0
 DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap);
7711c0
diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
7711c0
index ffe7aca..89b2a2f 100644
7711c0
--- a/migration/block-dirty-bitmap.c
7711c0
+++ b/migration/block-dirty-bitmap.c
7711c0
@@ -542,7 +542,7 @@ static void dirty_bitmap_load_complete(QEMUFile *f, DirtyBitmapLoadState *s)
7711c0
         }
7711c0
     }
7711c0
 
7711c0
-    if (bdrv_dirty_bitmap_frozen(s->bitmap)) {
7711c0
+    if (bdrv_dirty_bitmap_has_successor(s->bitmap)) {
7711c0
         bdrv_dirty_bitmap_lock(s->bitmap);
7711c0
         if (enabled_bitmaps == NULL) {
7711c0
             /* in postcopy */
7711c0
-- 
7711c0
1.8.3.1
7711c0