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

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