For migration destination, we also need to know its state, we will use it in COLO.
Here we add a new member 'state' for MigrationIncomingState, and also use migrate_set_state() to modify its value. We fix the first parameter of migrate_set_state(), and make it public. Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com> --- include/migration/migration.h | 3 +++ migration/migration.c | 38 +++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/include/migration/migration.h b/include/migration/migration.h index 5fd61a3..6fde8df 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -50,6 +50,7 @@ typedef QLIST_HEAD(, LoadStateEntry) LoadStateEntry_Head; struct MigrationIncomingState { QEMUFile *file; + int state; /* See savevm.c */ LoadStateEntry_Head loadvm_handlers; }; @@ -82,6 +83,8 @@ struct MigrationState int64_t dirty_sync_count; }; +void migrate_set_state(int *state, int old_state, int new_state); + void process_incoming_migration(QEMUFile *f); void qemu_start_incoming_migration(const char *uri, Error **errp); diff --git a/migration/migration.c b/migration/migration.c index 70ca246..08628c2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -89,6 +89,7 @@ MigrationIncomingState *migration_incoming_state_new(QEMUFile* f) { mis_current = g_malloc0(sizeof(MigrationIncomingState)); mis_current->file = f; + mis_current->state = MIGRATION_STATUS_NONE; QLIST_INIT(&mis_current->loadvm_handlers); return mis_current; @@ -263,11 +264,13 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) static void process_incoming_migration_co(void *opaque) { QEMUFile *f = opaque; + MigrationIncomingState *mis; Error *local_err = NULL; int ret; - migration_incoming_state_new(f); - migrate_generate_event(MIGRATION_STATUS_ACTIVE); + mis = migration_incoming_state_new(f); + migrate_set_state(&mis->state, MIGRATION_STATUS_NONE, + MIGRATION_STATUS_ACTIVE); ret = qemu_loadvm_state(f); qemu_fclose(f); @@ -275,12 +278,14 @@ static void process_incoming_migration_co(void *opaque) migration_incoming_state_destroy(); if (ret < 0) { - migrate_generate_event(MIGRATION_STATUS_FAILED); + migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); error_report("load of migration failed: %s", strerror(-ret)); migrate_decompress_threads_join(); exit(EXIT_FAILURE); } - migrate_generate_event(MIGRATION_STATUS_COMPLETED); + migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_COMPLETED); qemu_announce_self(); /* Make sure all file formats flush their mutable metadata */ @@ -536,9 +541,9 @@ void qmp_migrate_set_parameters(bool has_compress_level, /* shared migration helpers */ -static void migrate_set_state(MigrationState *s, int old_state, int new_state) +void migrate_set_state(int *state, int old_state, int new_state) { - if (atomic_cmpxchg(&s->state, old_state, new_state) == old_state) { + if (atomic_cmpxchg(state, old_state, new_state) == old_state) { trace_migrate_set_state(new_state); migrate_generate_event(new_state); } @@ -567,7 +572,7 @@ static void migrate_fd_cleanup(void *opaque) if (s->state != MIGRATION_STATUS_COMPLETED) { qemu_savevm_state_cancel(); if (s->state == MIGRATION_STATUS_CANCELLING) { - migrate_set_state(s, MIGRATION_STATUS_CANCELLING, + migrate_set_state(&s->state, MIGRATION_STATUS_CANCELLING, MIGRATION_STATUS_CANCELLED); } } @@ -579,7 +584,8 @@ void migrate_fd_error(MigrationState *s) { trace_migrate_fd_error(); assert(s->file == NULL); - migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED); + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_FAILED); notifier_list_notify(&migration_state_notifiers, s); } @@ -595,7 +601,7 @@ static void migrate_fd_cancel(MigrationState *s) old_state != MIGRATION_STATUS_ACTIVE) { break; } - migrate_set_state(s, old_state, MIGRATION_STATUS_CANCELLING); + migrate_set_state(&s->state, old_state, MIGRATION_STATUS_CANCELLING); } while (s->state != MIGRATION_STATUS_CANCELLING); /* @@ -663,7 +669,7 @@ static MigrationState *migrate_init(const MigrationParams *params) s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS] = decompress_thread_count; s->bandwidth_limit = bandwidth_limit; - migrate_set_state(s, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP); + migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP); s->total_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); return s; @@ -761,7 +767,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } else { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol"); - migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_FAILED); + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_FAILED); return; } @@ -941,7 +948,8 @@ static void *migration_thread(void *opaque) qemu_savevm_state_begin(s->file, &s->params); s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; - migrate_set_state(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE); + migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, + MIGRATION_STATUS_ACTIVE); while (s->state == MIGRATION_STATUS_ACTIVE) { int64_t current_time; @@ -971,13 +979,13 @@ static void *migration_thread(void *opaque) qemu_mutex_unlock_iothread(); if (ret < 0) { - migrate_set_state(s, MIGRATION_STATUS_ACTIVE, + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_FAILED); break; } if (!qemu_file_get_error(s->file)) { - migrate_set_state(s, MIGRATION_STATUS_ACTIVE, + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COMPLETED); break; } @@ -985,7 +993,7 @@ static void *migration_thread(void *opaque) } if (qemu_file_get_error(s->file)) { - migrate_set_state(s, MIGRATION_STATUS_ACTIVE, + migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_FAILED); break; } -- 1.8.3.1