On Tue, Feb 11, 2025 at 12:01:33PM -0300, Fabiano Rosas wrote: > It's possible that the migration is cancelled during > migration_switchover_start(). In that case, don't set the migration > state FAILED in migration_completion(). > > Fixes: 3dde8fdbad ("migration: Merge precopy/postcopy on switchover start") > Signed-off-by: Fabiano Rosas <faro...@suse.de>
I remember I paid some attention on this one when working on the commit, where it has: static bool migration_switchover_prepare(MigrationState *s) { /* Concurrent cancellation? Quit */ if (s->state == MIGRATION_STATUS_CANCELLING) { <================= [1] return false; } ... bql_unlock(); qemu_sem_wait(&s->pause_sem); bql_lock(); /* * After BQL released and retaken, the state can be CANCELLING if it * happend during sem_wait().. Only change the state if it's still * pre-switchover. */ migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER, <====== [2] MIGRATION_STATUS_DEVICE); return s->state == MIGRATION_STATUS_DEVICE; } So when holding BQL logically it can't change to CANCELLING, it'll check first [1] making sure no prior CANCELLING. Then after release and retake BQL it'll check again [2] (see the comment above [2], it's done by passing in explicit old_state to not change it if it's CANCELLING). Any hint on how this could be triggered? OTOH, when looking at this.. I seem to have found a bug indeed (which could be another?), where I may have forgot to touch up the old_state in migrate_set_state() after switching to always use DEVICE.. diff --git a/migration/migration.c b/migration/migration.c index 74c50cc72c..513e5955cc 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2793,8 +2793,9 @@ static int postcopy_start(MigrationState *ms, Error **errp) fail_closefb: qemu_fclose(fb); fail: - migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, - MIGRATION_STATUS_FAILED); + if (ms->state != MIGRATION_STATUS_CANCELLING) { + migrate_set_state(&ms->state, ms->state, MIGRATION_STATUS_FAILED); + } migration_block_activate(NULL); migration_call_notifiers(ms, MIG_EVENT_PRECOPY_FAILED, NULL); bql_unlock(); I'm not sure whether it's relevant to what you hit, though.. since you're looking at this, I'd rely on you help figuring it out before I do.. :) > --- > migration/migration.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/migration/migration.c b/migration/migration.c > index 375de6d460..5dc43bcdc0 100644 > --- a/migration/migration.c > +++ b/migration/migration.c > @@ -2986,7 +2986,9 @@ fail: > error_free(local_err); > } > > - migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED); > + if (s->state != MIGRATION_STATUS_CANCELLING) { > + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED); > + } > } > > /** > -- > 2.35.3 > -- Peter Xu