cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
26ba25
From 9d75983943f6510a804b2b9c48efa1eb3dcb41a2 Mon Sep 17 00:00:00 2001
26ba25
From: John Snow <jsnow@redhat.com>
26ba25
Date: Tue, 20 Nov 2018 18:18:06 +0000
26ba25
Subject: [PATCH 12/35] block: simplify code around releasing bitmaps
26ba25
26ba25
RH-Author: John Snow <jsnow@redhat.com>
26ba25
Message-id: <20181120181828.15132-3-jsnow@redhat.com>
26ba25
Patchwork-id: 83053
26ba25
O-Subject: [RHEL8/rhel qemu-kvm PATCH 02/24] block: simplify code around releasing bitmaps
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
From: Paolo Bonzini <pbonzini@redhat.com>
26ba25
26ba25
QLIST_REMOVE does not require walking the list, and once the "bitmap"
26ba25
argument is removed from bdrv_do_release_matching_dirty_bitmap_locked
26ba25
the code simplifies a lot and it is worth inlining everything in the
26ba25
callers of bdrv_do_release_matching_dirty_bitmap.
26ba25
26ba25
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
26ba25
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
26ba25
Reviewed-by: John Snow <jsnow@redhat.com>
26ba25
Message-id: 20180326104037.6894-1-pbonzini@redhat.com
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
(cherry picked from commit b133c27f5dc59969574b0715e5837d32c99caa86)
26ba25
Signed-off-by: John Snow <jsnow@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 block/dirty-bitmap.c | 84 ++++++++++++++++++++--------------------------------
26ba25
 1 file changed, 32 insertions(+), 52 deletions(-)
26ba25
26ba25
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
26ba25
index 634f143..dac8d74 100644
26ba25
--- a/block/dirty-bitmap.c
26ba25
+++ b/block/dirty-bitmap.c
26ba25
@@ -256,49 +256,16 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap)
26ba25
     qemu_mutex_unlock(bitmap->mutex);
26ba25
 }
26ba25
 
26ba25
-/* Called within bdrv_dirty_bitmap_lock..unlock */
26ba25
-static void bdrv_do_release_matching_dirty_bitmap_locked(
26ba25
-    BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
26ba25
-    bool (*cond)(BdrvDirtyBitmap *bitmap))
26ba25
+/* Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken.  */
26ba25
+static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap)
26ba25
 {
26ba25
-    BdrvDirtyBitmap *bm, *next;
26ba25
-
26ba25
-    QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
26ba25
-        if ((!bitmap || bm == bitmap) && (!cond || cond(bm))) {
26ba25
-            assert(!bm->active_iterators);
26ba25
-            assert(!bdrv_dirty_bitmap_frozen(bm));
26ba25
-            assert(!bm->meta);
26ba25
-            QLIST_REMOVE(bm, list);
26ba25
-            hbitmap_free(bm->bitmap);
26ba25
-            g_free(bm->name);
26ba25
-            g_free(bm);
26ba25
-
26ba25
-            if (bitmap) {
26ba25
-                return;
26ba25
-            }
26ba25
-        }
26ba25
-    }
26ba25
-
26ba25
-    if (bitmap) {
26ba25
-        abort();
26ba25
-    }
26ba25
-}
26ba25
-
26ba25
-/* Called with BQL taken.  */
26ba25
-static void bdrv_do_release_matching_dirty_bitmap(
26ba25
-    BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
26ba25
-    bool (*cond)(BdrvDirtyBitmap *bitmap))
26ba25
-{
26ba25
-    bdrv_dirty_bitmaps_lock(bs);
26ba25
-    bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, cond);
26ba25
-    bdrv_dirty_bitmaps_unlock(bs);
26ba25
-}
26ba25
-
26ba25
-/* Called within bdrv_dirty_bitmap_lock..unlock */
26ba25
-static void bdrv_release_dirty_bitmap_locked(BlockDriverState *bs,
26ba25
-                                             BdrvDirtyBitmap *bitmap)
26ba25
-{
26ba25
-    bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, NULL);
26ba25
+    assert(!bitmap->active_iterators);
26ba25
+    assert(!bdrv_dirty_bitmap_frozen(bitmap));
26ba25
+    assert(!bitmap->meta);
26ba25
+    QLIST_REMOVE(bitmap, list);
26ba25
+    hbitmap_free(bitmap->bitmap);
26ba25
+    g_free(bitmap->name);
26ba25
+    g_free(bitmap);
26ba25
 }
26ba25
 
26ba25
 /**
26ba25
@@ -351,7 +318,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(BlockDriverState *bs,
26ba25
         error_setg(errp, "Merging of parent and successor bitmap failed");
26ba25
         return NULL;
26ba25
     }
26ba25
-    bdrv_release_dirty_bitmap_locked(bs, successor);
26ba25
+    bdrv_release_dirty_bitmap_locked(successor);
26ba25
     parent->successor = NULL;
26ba25
 
26ba25
     return parent;
26ba25
@@ -389,15 +356,12 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs, int64_t bytes)
26ba25
     bdrv_dirty_bitmaps_unlock(bs);
26ba25
 }
26ba25
 
26ba25
-static bool bdrv_dirty_bitmap_has_name(BdrvDirtyBitmap *bitmap)
26ba25
-{
26ba25
-    return !!bdrv_dirty_bitmap_name(bitmap);
26ba25
-}
26ba25
-
26ba25
 /* Called with BQL taken.  */
26ba25
 void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
26ba25
 {
26ba25
-    bdrv_do_release_matching_dirty_bitmap(bs, bitmap, NULL);
26ba25
+    bdrv_dirty_bitmaps_lock(bs);
26ba25
+    bdrv_release_dirty_bitmap_locked(bitmap);
26ba25
+    bdrv_dirty_bitmaps_unlock(bs);
26ba25
 }
26ba25
 
26ba25
 /**
26ba25
@@ -408,7 +372,15 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
26ba25
  */
26ba25
 void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
26ba25
 {
26ba25
-    bdrv_do_release_matching_dirty_bitmap(bs, NULL, bdrv_dirty_bitmap_has_name);
26ba25
+    BdrvDirtyBitmap *bm, *next;
26ba25
+
26ba25
+    bdrv_dirty_bitmaps_lock(bs);
26ba25
+    QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
26ba25
+        if (bdrv_dirty_bitmap_name(bm)) {
26ba25
+            bdrv_release_dirty_bitmap_locked(bm);
26ba25
+        }
26ba25
+    }
26ba25
+    bdrv_dirty_bitmaps_unlock(bs);
26ba25
 }
26ba25
 
26ba25
 /**
26ba25
@@ -416,11 +388,19 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
26ba25
  * bdrv_inactivate_recurse()).
26ba25
  * There must not be any frozen bitmaps attached.
26ba25
  * This function does not remove persistent bitmaps from the storage.
26ba25
+ * Called with BQL taken.
26ba25
  */
26ba25
 void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs)
26ba25
 {
26ba25
-    bdrv_do_release_matching_dirty_bitmap(bs, NULL,
26ba25
-                                          bdrv_dirty_bitmap_get_persistance);
26ba25
+    BdrvDirtyBitmap *bm, *next;
26ba25
+
26ba25
+    bdrv_dirty_bitmaps_lock(bs);
26ba25
+    QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
26ba25
+        if (bdrv_dirty_bitmap_get_persistance(bm)) {
26ba25
+            bdrv_release_dirty_bitmap_locked(bm);
26ba25
+        }
26ba25
+    }
26ba25
+    bdrv_dirty_bitmaps_unlock(bs);
26ba25
 }
26ba25
 
26ba25
 /**
26ba25
-- 
26ba25
1.8.3.1
26ba25