migration: refactor init_dirty_bitmap_migration

Split out handling one bs, it is needed for the following commit, which
will handle BlockBackends separately.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200521220648.3255-2-vsementsov@virtuozzo.com>
[eblake: shorter subject line]
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2020-05-22 01:06:43 +03:00 committed by Eric Blake
parent a20ab81d22
commit 38908bbc65
1 changed files with 49 additions and 40 deletions

View File

@ -268,36 +268,26 @@ static void dirty_bitmap_mig_cleanup(void)
} }
/* Called with iothread lock taken. */ /* Called with iothread lock taken. */
static int init_dirty_bitmap_migration(void) static int add_bitmaps_to_list(BlockDriverState *bs, const char *bs_name)
{ {
BlockDriverState *bs;
BdrvDirtyBitmap *bitmap; BdrvDirtyBitmap *bitmap;
DirtyBitmapMigBitmapState *dbms; DirtyBitmapMigBitmapState *dbms;
Error *local_err = NULL; Error *local_err = NULL;
dirty_bitmap_mig_state.bulk_completed = false;
dirty_bitmap_mig_state.prev_bs = NULL;
dirty_bitmap_mig_state.prev_bitmap = NULL;
dirty_bitmap_mig_state.no_bitmaps = false;
for (bs = bdrv_next_all_states(NULL); bs; bs = bdrv_next_all_states(bs)) {
const char *name = bdrv_get_device_or_node_name(bs);
FOR_EACH_DIRTY_BITMAP(bs, bitmap) { FOR_EACH_DIRTY_BITMAP(bs, bitmap) {
if (!bdrv_dirty_bitmap_name(bitmap)) { if (!bdrv_dirty_bitmap_name(bitmap)) {
continue; continue;
} }
if (!name || strcmp(name, "") == 0) { if (!bs_name || strcmp(bs_name, "") == 0) {
error_report("Found bitmap '%s' in unnamed node %p. It can't " error_report("Found bitmap '%s' in unnamed node %p. It can't "
"be migrated", bdrv_dirty_bitmap_name(bitmap), bs); "be migrated", bdrv_dirty_bitmap_name(bitmap), bs);
goto fail; return -1;
} }
if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, &local_err)) {
&local_err)) {
error_report_err(local_err); error_report_err(local_err);
goto fail; return -1;
} }
bdrv_ref(bs); bdrv_ref(bs);
@ -305,7 +295,7 @@ static int init_dirty_bitmap_migration(void)
dbms = g_new0(DirtyBitmapMigBitmapState, 1); dbms = g_new0(DirtyBitmapMigBitmapState, 1);
dbms->bs = bs; dbms->bs = bs;
dbms->node_name = name; dbms->node_name = bs_name;
dbms->bitmap = bitmap; dbms->bitmap = bitmap;
dbms->total_sectors = bdrv_nb_sectors(bs); dbms->total_sectors = bdrv_nb_sectors(bs);
dbms->sectors_per_chunk = CHUNK_SIZE * 8 * dbms->sectors_per_chunk = CHUNK_SIZE * 8 *
@ -320,6 +310,25 @@ static int init_dirty_bitmap_migration(void)
QSIMPLEQ_INSERT_TAIL(&dirty_bitmap_mig_state.dbms_list, QSIMPLEQ_INSERT_TAIL(&dirty_bitmap_mig_state.dbms_list,
dbms, entry); dbms, entry);
} }
return 0;
}
/* Called with iothread lock taken. */
static int init_dirty_bitmap_migration(void)
{
BlockDriverState *bs;
DirtyBitmapMigBitmapState *dbms;
dirty_bitmap_mig_state.bulk_completed = false;
dirty_bitmap_mig_state.prev_bs = NULL;
dirty_bitmap_mig_state.prev_bitmap = NULL;
dirty_bitmap_mig_state.no_bitmaps = false;
for (bs = bdrv_next_all_states(NULL); bs; bs = bdrv_next_all_states(bs)) {
if (add_bitmaps_to_list(bs, bdrv_get_device_or_node_name(bs))) {
goto fail;
}
} }
/* unset migration flags here, to not roll back it */ /* unset migration flags here, to not roll back it */