From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com,
quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com,
stefanha@redhat.com, jsnow@redhat.com
Subject: [PATCH 4/7] migration/block-dirty-bitmap: keep bitmap state for all bitmaps
Date: Wed, 22 Jan 2020 16:23:25 +0300 [thread overview]
Message-ID: <20200122132328.31156-5-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20200122132328.31156-1-vsementsov@virtuozzo.com>
Keep bitmap state for disabled bitmaps too. Keep the state until the
end of the process. It's needed for the following commit to implement
bitmap postcopy canceling.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
migration/block-dirty-bitmap.c | 59 ++++++++++++++++++++++------------
1 file changed, 38 insertions(+), 21 deletions(-)
diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
index eeaab2174e..f96458113c 100644
--- a/migration/block-dirty-bitmap.c
+++ b/migration/block-dirty-bitmap.c
@@ -131,6 +131,7 @@ typedef struct DirtyBitmapLoadBitmapState {
BlockDriverState *bs;
BdrvDirtyBitmap *bitmap;
bool migrated;
+ bool enabled;
} DirtyBitmapLoadBitmapState;
typedef struct DirtyBitmapLoadState {
@@ -140,8 +141,11 @@ typedef struct DirtyBitmapLoadState {
BlockDriverState *bs;
BdrvDirtyBitmap *bitmap;
- GSList *enabled_bitmaps;
- QemuMutex lock; /* protect enabled_bitmaps */
+ bool bitmaps_enabled; /* set in dirty_bitmap_mig_before_vm_start */
+ bool stream_ended; /* set when all migrated data handled */
+
+ GSList *bitmaps;
+ QemuMutex lock; /* protect bitmaps */
} DirtyBitmapLoadState;
static DirtyBitmapLoadState dbm_load_state;
@@ -446,6 +450,7 @@ static int dirty_bitmap_load_start(QEMUFile *f)
Error *local_err = NULL;
uint32_t granularity = qemu_get_be32(f);
uint8_t flags = qemu_get_byte(f);
+ DirtyBitmapLoadBitmapState *b;
if (s->bitmap) {
error_report("Bitmap with the same name ('%s') already exists on "
@@ -472,22 +477,23 @@ static int dirty_bitmap_load_start(QEMUFile *f)
bdrv_disable_dirty_bitmap(s->bitmap);
if (flags & DIRTY_BITMAP_MIG_START_FLAG_ENABLED) {
- DirtyBitmapLoadBitmapState *b;
-
bdrv_dirty_bitmap_create_successor(s->bitmap, &local_err);
if (local_err) {
error_report_err(local_err);
return -EINVAL;
}
-
- b = g_new(DirtyBitmapLoadBitmapState, 1);
- b->bs = s->bs;
- b->bitmap = s->bitmap;
- b->migrated = false;
- dbm_load_state.enabled_bitmaps =
- g_slist_prepend(dbm_load_state.enabled_bitmaps, b);
}
+ b = g_new(DirtyBitmapLoadBitmapState, 1);
+ *b = (DirtyBitmapLoadBitmapState) {
+ .bs = s->bs,
+ .bitmap = s->bitmap,
+ .migrated = false,
+ .enabled = flags & DIRTY_BITMAP_MIG_START_FLAG_ENABLED,
+ };
+
+ dbm_load_state.bitmaps = g_slist_prepend(dbm_load_state.bitmaps, b);
+
return 0;
}
@@ -497,22 +503,25 @@ void dirty_bitmap_mig_before_vm_start(void)
qemu_mutex_lock(&dbm_load_state.lock);
- for (item = dbm_load_state.enabled_bitmaps; item;
- item = g_slist_next(item))
- {
+ for (item = dbm_load_state.bitmaps; item; item = g_slist_next(item)) {
DirtyBitmapLoadBitmapState *b = item->data;
+ if (!b->enabled) {
+ continue;
+ }
+
if (b->migrated) {
bdrv_enable_dirty_bitmap_locked(b->bitmap);
} else {
bdrv_dirty_bitmap_enable_successor(b->bitmap);
}
-
- g_free(b);
}
- g_slist_free(dbm_load_state.enabled_bitmaps);
- dbm_load_state.enabled_bitmaps = NULL;
+ dbm_load_state.bitmaps_enabled = true;
+ if (dbm_load_state.stream_ended) {
+ g_slist_free_full(dbm_load_state.bitmaps, g_free);
+ dbm_load_state.bitmaps = NULL;
+ }
qemu_mutex_unlock(&dbm_load_state.lock);
}
@@ -530,9 +539,7 @@ static void dirty_bitmap_load_complete(QEMUFile *f)
bdrv_reclaim_dirty_bitmap(s->bitmap, &error_abort);
}
- for (item = dbm_load_state.enabled_bitmaps; item;
- item = g_slist_next(item))
- {
+ for (item = dbm_load_state.bitmaps; item; item = g_slist_next(item)) {
DirtyBitmapLoadBitmapState *b = item->data;
if (b->bitmap == s->bitmap) {
@@ -671,6 +678,16 @@ static int dirty_bitmap_load(QEMUFile *f, void *opaque, int version_id)
}
} while (!(dbm_load_state.flags & DIRTY_BITMAP_MIG_FLAG_EOS));
+ qemu_mutex_lock(&dbm_load_state.lock);
+
+ dbm_load_state.stream_ended = true;
+ if (dbm_load_state.bitmaps_enabled) {
+ g_slist_free_full(dbm_load_state.bitmaps, g_free);
+ dbm_load_state.bitmaps = NULL;
+ }
+
+ qemu_mutex_unlock(&dbm_load_state.lock);
+
trace_dirty_bitmap_load_success();
return 0;
}
--
2.21.0
next prev parent reply other threads:[~2020-01-22 13:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-22 13:23 [PATCH 0/7] Fix crashes on early shutdown during bitmaps postcopy Vladimir Sementsov-Ogievskiy
2020-01-22 13:23 ` [PATCH 1/7] migration/block-dirty-bitmap: refactor incoming state to be one struct Vladimir Sementsov-Ogievskiy
2020-01-24 10:56 ` Juan Quintela
2020-02-11 15:03 ` Vladimir Sementsov-Ogievskiy
2020-01-22 13:23 ` [PATCH 2/7] migration/block-dirty-bitmap: rename finish_lock to just lock Vladimir Sementsov-Ogievskiy
2020-01-24 10:57 ` Juan Quintela
2020-01-22 13:23 ` [PATCH 3/7] migration/block-dirty-bitmap: simplify dirty_bitmap_load_complete Vladimir Sementsov-Ogievskiy
2020-01-22 13:23 ` Vladimir Sementsov-Ogievskiy [this message]
2020-01-24 11:01 ` [PATCH 4/7] migration/block-dirty-bitmap: keep bitmap state for all bitmaps Juan Quintela
2020-02-11 15:12 ` Vladimir Sementsov-Ogievskiy
2020-02-11 15:14 ` Vladimir Sementsov-Ogievskiy
2020-01-22 13:23 ` [PATCH 5/7] migration/block-dirty-bitmap: cancel migration on shutdown Vladimir Sementsov-Ogievskiy
2020-01-22 13:23 ` [PATCH 6/7] migration: handle to_src_file on target only for ram postcopy Vladimir Sementsov-Ogievskiy
2020-01-22 13:23 ` [PATCH 7/7] qemu-iotests/199: add early shutdown case to bitmaps postcopy Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200122132328.31156-5-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=dgilbert@redhat.com \
--cc=fam@euphon.net \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).