[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 02/13] block/dirty-bitmap: fix locking in bdrv_reclai
From: |
John Snow |
Subject: |
[Qemu-devel] [PULL 02/13] block/dirty-bitmap: fix locking in bdrv_reclaim_dirty_bitmap |
Date: |
Tue, 13 Mar 2018 17:14:30 -0400 |
From: Vladimir Sementsov-Ogievskiy <address@hidden>
Like other setters here these functions should take a lock.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Reviewed-by: John Snow <address@hidden>
Message-id: address@hidden
Signed-off-by: John Snow <address@hidden>
---
block/dirty-bitmap.c | 85 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 53 insertions(+), 32 deletions(-)
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index 0d0e807216..75435f6c2f 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -242,6 +242,51 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap
*bitmap)
qemu_mutex_unlock(bitmap->mutex);
}
+/* Called within bdrv_dirty_bitmap_lock..unlock */
+static void bdrv_do_release_matching_dirty_bitmap_locked(
+ BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
+ bool (*cond)(BdrvDirtyBitmap *bitmap))
+{
+ BdrvDirtyBitmap *bm, *next;
+
+ QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
+ if ((!bitmap || bm == bitmap) && (!cond || cond(bm))) {
+ assert(!bm->active_iterators);
+ assert(!bdrv_dirty_bitmap_frozen(bm));
+ assert(!bm->meta);
+ QLIST_REMOVE(bm, list);
+ hbitmap_free(bm->bitmap);
+ g_free(bm->name);
+ g_free(bm);
+
+ if (bitmap) {
+ return;
+ }
+ }
+ }
+
+ if (bitmap) {
+ abort();
+ }
+}
+
+/* Called with BQL taken. */
+static void bdrv_do_release_matching_dirty_bitmap(
+ BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
+ bool (*cond)(BdrvDirtyBitmap *bitmap))
+{
+ bdrv_dirty_bitmaps_lock(bs);
+ bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, cond);
+ bdrv_dirty_bitmaps_unlock(bs);
+}
+
+/* Called within bdrv_dirty_bitmap_lock..unlock */
+static void bdrv_release_dirty_bitmap_locked(BlockDriverState *bs,
+ BdrvDirtyBitmap *bitmap)
+{
+ bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, NULL);
+}
+
/**
* For a bitmap with a successor, yield our name to the successor,
* delete the old bitmap, and return a handle to the new bitmap.
@@ -281,7 +326,11 @@ BdrvDirtyBitmap
*bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
BdrvDirtyBitmap *parent,
Error **errp)
{
- BdrvDirtyBitmap *successor = parent->successor;
+ BdrvDirtyBitmap *successor;
+
+ qemu_mutex_lock(parent->mutex);
+
+ successor = parent->successor;
if (!successor) {
error_setg(errp, "Cannot reclaim a successor when none is present");
@@ -292,9 +341,11 @@ BdrvDirtyBitmap
*bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
error_setg(errp, "Merging of parent and successor bitmap failed");
return NULL;
}
- bdrv_release_dirty_bitmap(bs, successor);
+ bdrv_release_dirty_bitmap_locked(bs, successor);
parent->successor = NULL;
+ qemu_mutex_unlock(parent->mutex);
+
return parent;
}
@@ -321,36 +372,6 @@ static bool bdrv_dirty_bitmap_has_name(BdrvDirtyBitmap
*bitmap)
return !!bdrv_dirty_bitmap_name(bitmap);
}
-/* Called with BQL taken. */
-static void bdrv_do_release_matching_dirty_bitmap(
- BlockDriverState *bs, BdrvDirtyBitmap *bitmap,
- bool (*cond)(BdrvDirtyBitmap *bitmap))
-{
- BdrvDirtyBitmap *bm, *next;
- bdrv_dirty_bitmaps_lock(bs);
- QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
- if ((!bitmap || bm == bitmap) && (!cond || cond(bm))) {
- assert(!bm->active_iterators);
- assert(!bdrv_dirty_bitmap_frozen(bm));
- assert(!bm->meta);
- QLIST_REMOVE(bm, list);
- hbitmap_free(bm->bitmap);
- g_free(bm->name);
- g_free(bm);
-
- if (bitmap) {
- goto out;
- }
- }
- }
- if (bitmap) {
- abort();
- }
-
-out:
- bdrv_dirty_bitmaps_unlock(bs);
-}
-
/* Called with BQL taken. */
void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
{
--
2.14.3
- [Qemu-devel] [PULL 00/13] Bitmaps patches, John Snow, 2018/03/13
- [Qemu-devel] [PULL 10/13] migration: allow qmp command migrate-start-postcopy for any postcopy, John Snow, 2018/03/13
- [Qemu-devel] [PULL 03/13] block/dirty-bitmap: add _locked version of bdrv_reclaim_dirty_bitmap, John Snow, 2018/03/13
- [Qemu-devel] [PULL 08/13] migration/qemu-file: add qemu_put_counted_string(), John Snow, 2018/03/13
- [Qemu-devel] [PULL 09/13] migration: add is_active_iterate handler, John Snow, 2018/03/13
- [Qemu-devel] [PULL 05/13] migration: introduce postcopy-only pending, John Snow, 2018/03/13
- [Qemu-devel] [PULL 02/13] block/dirty-bitmap: fix locking in bdrv_reclaim_dirty_bitmap,
John Snow <=
- [Qemu-devel] [PULL 01/13] block/dirty-bitmap: add bdrv_dirty_bitmap_enable_successor(), John Snow, 2018/03/13
- [Qemu-devel] [PULL 06/13] qapi: add dirty-bitmaps migration capability, John Snow, 2018/03/13
- [Qemu-devel] [PULL 07/13] migration: include migrate_dirty_bitmaps in migrate_postcopy, John Snow, 2018/03/13
- [Qemu-devel] [PULL 04/13] dirty-bitmap: add locked state, John Snow, 2018/03/13
- [Qemu-devel] [PULL 13/13] iotests: add dirty bitmap postcopy test, John Snow, 2018/03/13
- [Qemu-devel] [PULL 12/13] iotests: add dirty bitmap migration test, John Snow, 2018/03/13
- [Qemu-devel] [PULL 11/13] migration: add postcopy migration of dirty bitmaps, John Snow, 2018/03/13
- Re: [Qemu-devel] [PULL 00/13] Bitmaps patches, no-reply, 2018/03/14
- Re: [Qemu-devel] [PULL 00/13] Bitmaps patches, Peter Maydell, 2018/03/16