Signed-off-by: zhanghailiang <zhang.zhanghaili...@huawei.com> Signed-off-by: Li Zhijian <lizhij...@cn.fujitsu.com> --- include/net/colo-nic.h | 2 ++ migration/colo.c | 22 +++++++++++++++++++--- net/colo-nic.c | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/include/net/colo-nic.h b/include/net/colo-nic.h index 271ab8b..a9960f1 100644 --- a/include/net/colo-nic.h +++ b/include/net/colo-nic.h @@ -31,5 +31,7 @@ int colo_proxy_init(enum COLOMode mode); void colo_proxy_destroy(enum COLOMode mode); int colo_proxy_compare(void); +int colo_proxy_failover(void); +int colo_proxy_checkpoint(enum COLOMode mode); #endif diff --git a/migration/colo.c b/migration/colo.c index b466959..2b518d4 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -148,6 +148,12 @@ static void secondary_vm_do_failover(void) migrate_set_state(&mis->state, MIGRATION_STATUS_COLO, MIGRATION_STATUS_COMPLETED); + + if (colo_proxy_failover() != 0) { + error_report("colo proxy failed to do failover"); + } + colo_proxy_destroy(COLO_MODE_SECONDARY); + if (!autostart) { error_report("\"-S\" qemu option will be ignored in secondary side"); /* recover runstate to normal migration finish state */ @@ -177,6 +183,8 @@ static void primary_vm_do_failover(void) MigrationState *s = migrate_get_current(); int old_state; + colo_proxy_destroy(COLO_MODE_PRIMARY); + if (s->state != MIGRATION_STATUS_FAILED) { migrate_set_state(&s->state, MIGRATION_STATUS_COLO, MIGRATION_STATUS_COMPLETED); @@ -318,6 +326,11 @@ static int colo_do_checkpoint_transaction(MigrationState *s, QEMUFile *control) qemu_fflush(trans); + ret = colo_proxy_checkpoint(COLO_MODE_PRIMARY); + if (ret < 0) { + goto out; + } + ret = colo_ctl_put(s->file, COLO_CHECKPOINT_SEND); if (ret < 0) { goto out; @@ -463,8 +476,6 @@ out: } qemu_mutex_unlock_iothread(); - colo_proxy_destroy(COLO_MODE_PRIMARY); - return NULL; } @@ -592,6 +603,11 @@ void *colo_process_incoming_checkpoints(void *opaque) goto out; } + ret = colo_proxy_checkpoint(COLO_MODE_SECONDARY); + if (ret < 0) { + goto out; + } + ret = colo_ctl_get(f, COLO_CHECKPOINT_SEND); if (ret < 0) { goto out; @@ -688,10 +704,10 @@ out: * just kill Secondary VM */ error_report("SVM is going to exit in default!"); + colo_proxy_destroy(COLO_MODE_SECONDARY); exit(1); } - colo_proxy_destroy(COLO_MODE_SECONDARY); migration_incoming_exit_colo(); return NULL; diff --git a/net/colo-nic.c b/net/colo-nic.c index d2073b8..62bd35a 100644 --- a/net/colo-nic.c +++ b/net/colo-nic.c @@ -428,6 +428,29 @@ void colo_proxy_destroy(enum COLOMode mode) teardown_nic(mode, getpid()); } +/* +* Note: Weird, Only the VM in slave side need to do failover work !!! +*/ +int colo_proxy_failover(void) +{ + if (colo_proxy_send(NFCOLO_DO_FAILOVER, COLO_MODE_SECONDARY, 0, NULL) < 0) { + return -1; + } + + return 0; +} + +/* +* Note: Only the VM in master side need to do checkpoint +*/ +int colo_proxy_checkpoint(enum COLOMode mode) +{ + if (colo_proxy_send(NFCOLO_DO_CHECKPOINT, mode, 0, NULL) < 0) { + return -1; + } + return 0; +} + int colo_proxy_compare(void) { return atomic_xchg(&packet_compare_different, 0); -- 1.8.3.1