Blame SOURCES/kvm-block-simplify-code-around-releasing-bitmaps.patch

7711c0
From 4cf452add8a2760d325b79efdd484c8d37cd2158 Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 6 Feb 2019 22:12:22 +0100
7711c0
Subject: [PATCH 12/33] block: simplify code around releasing bitmaps
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190206221243.7407-3-jsnow@redhat.com>
7711c0
Patchwork-id: 84262
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH v2 02/23] block: simplify code around releasing bitmaps
7711c0
Bugzilla: 1658343
7711c0
RH-Acked-by: Thomas Huth <thuth@redhat.com>
7711c0
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
7711c0
From: Paolo Bonzini <pbonzini@redhat.com>
7711c0
7711c0
QLIST_REMOVE does not require walking the list, and once the "bitmap"
7711c0
argument is removed from bdrv_do_release_matching_dirty_bitmap_locked
7711c0
the code simplifies a lot and it is worth inlining everything in the
7711c0
callers of bdrv_do_release_matching_dirty_bitmap.
7711c0
7711c0
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7711c0
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
7711c0
Reviewed-by: John Snow <jsnow@redhat.com>
7711c0
Message-id: 20180326104037.6894-1-pbonzini@redhat.com
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
(cherry picked from commit b133c27f5dc59969574b0715e5837d32c99caa86)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 block/dirty-bitmap.c | 84 ++++++++++++++++++++--------------------------------
7711c0
 1 file changed, 32 insertions(+), 52 deletions(-)
7711c0
7711c0
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
7711c0
index 50e855a..cd39afd 100644
7711c0
--- a/block/dirty-bitmap.c
7711c0
+++ b/block/dirty-bitmap.c
7711c0
@@ -256,49 +256,16 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap)
7711c0
     qemu_mutex_unlock(bitmap->mutex);
7711c0
 }
7711c0
 
7711c0
-/* Called within bdrv_dirty_bitmap_lock..unlock */
7711c0
-static void bdrv_do_release_matching_dirty_bitmap_locked(
7711c0
-    BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
7711c0
-    bool (*cond)(BdrvDirtyBitmap *bitmap))
7711c0
+/* Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken.  */
7711c0
+static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
7711c0
 {
7711c0
-    BdrvDirtyBitmap *bm, *next;
7711c0
-
7711c0
-    QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
7711c0
-        if ((!bitmap || bm == bitmap) && (!cond || cond(bm))) {
7711c0
-            assert(!bm->active_iterators);
7711c0
-            assert(!bdrv_dirty_bitmap_frozen(bm));
7711c0
-            assert(!bm->meta);
7711c0
-            QLIST_REMOVE(bm, list);
7711c0
-            hbitmap_free(bm->bitmap);
7711c0
-            g_free(bm->name);
7711c0
-            g_free(bm);
7711c0
-
7711c0
-            if (bitmap) {
7711c0
-                return;
7711c0
-            }
7711c0
-        }
7711c0
-    }
7711c0
-
7711c0
-    if (bitmap) {
7711c0
-        abort();
7711c0
-    }
7711c0
-}
7711c0
-
7711c0
-/* Called with BQL taken.  */
7711c0
-static void bdrv_do_release_matching_dirty_bitmap(
7711c0
-    BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
7711c0
-    bool (*cond)(BdrvDirtyBitmap *bitmap))
7711c0
-{
7711c0
-    bdrv_dirty_bitmaps_lock(bs);
7711c0
-    bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, cond);
7711c0
-    bdrv_dirty_bitmaps_unlock(bs);
7711c0
-}
7711c0
-
7711c0
-/* Called within bdrv_dirty_bitmap_lock..unlock */
7711c0
-static void bdrv_release_dirty_bitmap_locked(BlockDriverState *bs,
7711c0
-                                             BdrvDirtyBitmap *bitmap)
7711c0
-{
7711c0
-    bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, NULL);
7711c0
+    assert(!bitmap->active_iterators);
7711c0
+    assert(!bdrv_dirty_bitmap_frozen(bitmap));
7711c0
+    assert(!bitmap->meta);
7711c0
+    QLIST_REMOVE(bitmap, list);
7711c0
+    hbitmap_free(bitmap->bitmap);
7711c0
+    g_free(bitmap->name);
7711c0
+    g_free(bitmap);
7711c0
 }
7711c0
 
7711c0
 /**
7711c0
@@ -351,7 +318,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
7711c0
         error_setg(errp, "Merging of parent and successor bitmap failed");
7711c0
         return NULL;
7711c0
     }
7711c0
-    bdrv_release_dirty_bitmap_locked(bs, successor);
7711c0
+    bdrv_release_dirty_bitmap_locked(successor);
7711c0
     parent->successor = NULL;
7711c0
 
7711c0
     return parent;
7711c0
@@ -389,15 +356,12 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
7711c0
     bdrv_dirty_bitmaps_unlock(bs);
7711c0
 }
7711c0
 
7711c0
-static bool bdrv_dirty_bitmap_has_name(BdrvDirtyBitmap *bitmap)
7711c0
-{
7711c0
-    return !!bdrv_dirty_bitmap_name(bitmap);
7711c0
-}
7711c0
-
7711c0
 /* Called with BQL taken.  */
7711c0
 void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
7711c0
 {
7711c0
-    bdrv_do_release_matching_dirty_bitmap(bs, bitmap, NULL);
7711c0
+    bdrv_dirty_bitmaps_lock(bs);
7711c0
+    bdrv_release_dirty_bitmap_locked(bitmap);
7711c0
+    bdrv_dirty_bitmaps_unlock(bs);
7711c0
 }
7711c0
 
7711c0
 /**
7711c0
@@ -408,7 +372,15 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
7711c0
  */
7711c0
 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
7711c0
 {
7711c0
-    bdrv_do_release_matching_dirty_bitmap(bs, NULL, bdrv_dirty_bitmap_has_name);
7711c0
+    BdrvDirtyBitmap *bm, *next;
7711c0
+
7711c0
+    bdrv_dirty_bitmaps_lock(bs);
7711c0
+    QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
7711c0
+        if (bdrv_dirty_bitmap_name(bm)) {
7711c0
+            bdrv_release_dirty_bitmap_locked(bm);
7711c0
+        }
7711c0
+    }
7711c0
+    bdrv_dirty_bitmaps_unlock(bs);
7711c0
 }
7711c0
 
7711c0
 /**
7711c0
@@ -416,11 +388,19 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
7711c0
  * bdrv_inactivate_recurse()).
7711c0
  * There must not be any frozen bitmaps attached.
7711c0
  * This function does not remove persistent bitmaps from the storage.
7711c0
+ * Called with BQL taken.
7711c0
  */
7711c0
 void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs)
7711c0
 {
7711c0
-    bdrv_do_release_matching_dirty_bitmap(bs, NULL,
7711c0
-                                          bdrv_dirty_bitmap_get_persistance);
7711c0
+    BdrvDirtyBitmap *bm, *next;
7711c0
+
7711c0
+    bdrv_dirty_bitmaps_lock(bs);
7711c0
+    QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
7711c0
+        if (bdrv_dirty_bitmap_get_persistance(bm)) {
7711c0
+            bdrv_release_dirty_bitmap_locked(bm);
7711c0
+        }
7711c0
+    }
7711c0
+    bdrv_dirty_bitmaps_unlock(bs);
7711c0
 }
7711c0
 
7711c0
 /**
7711c0
-- 
7711c0
1.8.3.1
7711c0