From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKN0v-0002HL-17 for qemu-devel@nongnu.org; Wed, 29 Jul 2015 04:47:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKN0t-0006Fh-Q4 for qemu-devel@nongnu.org; Wed, 29 Jul 2015 04:47:00 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:61848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKN0t-0006EQ-0E for qemu-devel@nongnu.org; Wed, 29 Jul 2015 04:46:59 -0400 From: zhanghailiang Date: Wed, 29 Jul 2015 16:45:36 +0800 Message-ID: <1438159544-6224-27-git-send-email-zhang.zhanghailiang@huawei.com> In-Reply-To: <1438159544-6224-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1438159544-6224-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH COLO-Frame v8 26/34] COLO NIC: Implement colo nic init/destroy function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: lizhijian@cn.fujitsu.com, quintela@redhat.com, Jason Wang , yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, arei.gonglei@huawei.com, Stefan Hajnoczi , amit.shah@redhat.com, zhanghailiang When in colo mode, call colo nic init/destroy function. Cc: Stefan Hajnoczi Cc: Jason Wang Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian --- include/net/colo-nic.h | 3 +++ migration/colo.c | 14 ++++++++++ net/colo-nic.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/include/net/colo-nic.h b/include/net/colo-nic.h index f1d9c25..7b8ff57 100644 --- a/include/net/colo-nic.h +++ b/include/net/colo-nic.h @@ -27,4 +27,7 @@ typedef struct COLONicState { void colo_add_nic_devices(COLONicState *cns); void colo_remove_nic_devices(COLONicState *cns); +int colo_proxy_init(enum COLOMode mode); +void colo_proxy_destroy(enum COLOMode mode); + #endif diff --git a/migration/colo.c b/migration/colo.c index 0f3dd7d..c286152 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -17,6 +17,7 @@ #include "qemu/sockets.h" #include "migration/failover.h" #include "qapi-event.h" +#include "net/colo-nic.h" /* Fix me: Convert to use QAPI */ typedef enum COLOCommand { @@ -343,6 +344,10 @@ static void *colo_thread(void *opaque) int i, ret; failover_init_state(); + if (colo_proxy_init(COLO_MODE_PRIMARY) != 0) { + error_report("Init colo proxy error"); + goto out; + } colo_control = qemu_fopen_socket(qemu_get_fd(s->file), "rb"); if (!colo_control) { @@ -404,6 +409,8 @@ out: } qemu_mutex_unlock_iothread(); + colo_proxy_destroy(COLO_MODE_PRIMARY); + return NULL; } @@ -469,6 +476,11 @@ void *colo_process_incoming_checkpoints(void *opaque) migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); failover_init_state(); + /* configure the network */ + if (colo_proxy_init(COLO_MODE_SECONDARY) != 0) { + error_report("Init colo proxy error\n"); + goto out; + } ctl = qemu_fopen_socket(fd, "wb"); if (!ctl) { @@ -625,6 +637,8 @@ out: 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 4b53f72..5c24169 100644 --- a/net/colo-nic.c +++ b/net/colo-nic.c @@ -121,6 +121,57 @@ static int colo_nic_configure(COLONicState *cns, return -1; } +static int configure_one_nic(COLONicState *cns, + bool up, int side, int index) +{ + struct nic_device *nic; + + assert(cns); + + QTAILQ_FOREACH(nic, &nic_devices, next) { + if (nic->cns == cns) { + if (up == nic->is_up) { + return 0; + } + + if (!nic->configure || (nic->configure(nic->cns, 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->cns, 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->cns, 0, side, index); + } +} + void colo_add_nic_devices(COLONicState *cns) { struct nic_device *nic; @@ -151,8 +202,26 @@ void colo_remove_nic_devices(COLONicState *cns) QTAILQ_FOREACH_SAFE(nic, &nic_devices, next, next_nic) { if (nic->cns == cns) { + configure_one_nic(cns, 0, get_colo_mode(), getpid()); QTAILQ_REMOVE(&nic_devices, nic, next); g_free(nic); } } } + +int colo_proxy_init(enum COLOMode mode) +{ + int ret = -1; + + ret = configure_nic(mode, getpid()); + if (ret != 0) { + error_report("excute colo-proxy-script failed"); + } + + return ret; +} + +void colo_proxy_destroy(enum COLOMode mode) +{ + teardown_nic(mode, getpid()); +} -- 1.8.3.1