When in colo mode, call colo nic init/destroy function. 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 | 17 +++++++++++ net/colo-nic.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+)
diff --git a/include/net/colo-nic.h b/include/net/colo-nic.h index d35ee17..40dbcfb 100644 --- a/include/net/colo-nic.h +++ b/include/net/colo-nic.h @@ -14,6 +14,8 @@ #ifndef COLO_NIC_H #define COLO_NIC_H +int colo_proxy_init(int side); +void colo_proxy_destroy(int side); void colo_add_nic_devices(NetClientState *nc); void colo_remove_nic_devices(NetClientState *nc); diff --git a/migration/colo.c b/migration/colo.c index f419e88..dffd6f9 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -14,6 +14,7 @@ #include "migration/migration-colo.h" #include "qemu/error-report.h" #include "migration/migration-failover.h" +#include "net/colo-nic.h" #define DEBUG_COLO 0 @@ -291,6 +292,12 @@ static void *colo_thread(void *opaque) QEMUFile *colo_control = NULL; int ret; + if (colo_proxy_init(COLO_PRIMARY_MODE) != 0) { + error_report("Init colo proxy error"); + goto out; + } + DPRINTF("proxy init complete\n"); + colo_control = qemu_fopen_socket(qemu_get_fd(s->file), "rb"); if (!colo_control) { error_report("Open colo_control failed!"); @@ -350,6 +357,8 @@ out: qemu_bh_schedule(s->cleanup_bh); qemu_mutex_unlock_iothread(); + colo_proxy_destroy(COLO_PRIMARY_MODE); + return NULL; } @@ -419,6 +428,13 @@ void *colo_process_incoming_checkpoints(void *opaque) colo = qemu_coroutine_self(); assert(colo != NULL); + /* configure the network */ + if (colo_proxy_init(COLO_SECONDARY_MODE) != 0) { + error_report("Init colo proxy error\n"); + goto out; + } + DPRINTF("proxy init complete\n"); + ctl = qemu_fopen_socket(fd, "wb"); if (!ctl) { error_report("Can't open incoming channel!"); @@ -570,5 +586,6 @@ out: loadvm_exit_colo(); + colo_proxy_destroy(COLO_SECONDARY_MODE); return NULL; } diff --git a/net/colo-nic.c b/net/colo-nic.c index f8fc35d..a4719ce 100644 --- a/net/colo-nic.c +++ b/net/colo-nic.c @@ -26,6 +26,12 @@ typedef struct nic_device { } nic_device; +typedef struct colo_proxy { + int sockfd; + int index; +} colo_proxy; + +static colo_proxy cp_info = {-1, -1}; QTAILQ_HEAD(, nic_device) nic_devices = QTAILQ_HEAD_INITIALIZER(nic_devices); static int colo_nic_side = -1; @@ -93,6 +99,60 @@ static int colo_nic_configure(NetClientState *nc, return launch_colo_script(argv); } +static int configure_one_nic(NetClientState *nc, + bool up, int side, int index) +{ + struct nic_device *nic; + + assert(nc); + + QTAILQ_FOREACH(nic, &nic_devices, next) { + if (nic->nc == nc) { + if (!nic->support_colo || !nic->support_colo(nic->nc) + || !nic->configure) { + return -1; + } + if (up == nic->is_up) { + return 0; + } + + if (nic->configure(nic->nc, up, side, index) && up) { + return -1; + } + nic->is_up = up; + return 0; + } + } + + return -1; +} + +static int configure_nic(int side, int index) +{ + struct nic_device *nic; + + if (QTAILQ_EMPTY(&nic_devices)) { + return -1; + } + + QTAILQ_FOREACH(nic, &nic_devices, next) { + if (configure_one_nic(nic->nc, 1, side, index)) { + return -1; + } + } + + return 0; +} + +static void teardown_nic(int side, int index) +{ + struct nic_device *nic; + + QTAILQ_FOREACH(nic, &nic_devices, next) { + configure_one_nic(nic->nc, 0, side, index); + } +} + void colo_add_nic_devices(NetClientState *nc) { struct nic_device *nic = g_malloc0(sizeof(*nic)); @@ -119,9 +179,29 @@ void colo_remove_nic_devices(NetClientState *nc) QTAILQ_FOREACH_SAFE(nic, &nic_devices, next, next_nic) { if (nic->nc == nc) { + configure_one_nic(nc, 0, colo_nic_side, cp_info.index); QTAILQ_REMOVE(&nic_devices, nic, next); g_free(nic); } } colo_nic_side = -1; } + +int colo_proxy_init(int side) +{ + int ret = -1; + + ret = configure_nic(side, cp_info.index); + if (ret != 0) { + error_report("excute colo-proxy-script failed"); + } + colo_nic_side = side; + return ret; +} + +void colo_proxy_destroy(int side) +{ + teardown_nic(side, cp_info.index); + cp_info.index = -1; + colo_nic_side = -1; +} -- 1.7.12.4