qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH v4 18/28] COLO NIC: Init/remove colo nic devices


From: zhanghailiang
Subject: [Qemu-devel] [RFC PATCH v4 18/28] COLO NIC: Init/remove colo nic devices when add/cleanup tap devices
Date: Thu, 26 Mar 2015 13:29:24 +0800

When COLO mode, we will do some init work for nic that will be used for COLO.

Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
---
 include/net/colo-nic.h | 20 ++++++++++++++
 net/Makefile.objs      |  1 +
 net/colo-nic.c         | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 net/tap.c              | 18 +++++++++----
 stubs/migration-colo.c |  9 +++++++
 5 files changed, 116 insertions(+), 5 deletions(-)
 create mode 100644 include/net/colo-nic.h
 create mode 100644 net/colo-nic.c

diff --git a/include/net/colo-nic.h b/include/net/colo-nic.h
new file mode 100644
index 0000000..d35ee17
--- /dev/null
+++ b/include/net/colo-nic.h
@@ -0,0 +1,20 @@
+/*
+ * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
+ * (a.k.a. Fault Tolerance or Continuous Replication)
+ *
+ * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD.
+ * Copyright (c) 2015 FUJITSU LIMITED
+ * Copyright (c) 2015 Intel Corporation
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef COLO_NIC_H
+#define COLO_NIC_H
+
+void colo_add_nic_devices(NetClientState *nc);
+void colo_remove_nic_devices(NetClientState *nc);
+
+#endif
diff --git a/net/Makefile.objs b/net/Makefile.objs
index ec19cb3..73f4a81 100644
--- a/net/Makefile.objs
+++ b/net/Makefile.objs
@@ -13,3 +13,4 @@ common-obj-$(CONFIG_HAIKU) += tap-haiku.o
 common-obj-$(CONFIG_SLIRP) += slirp.o
 common-obj-$(CONFIG_VDE) += vde.o
 common-obj-$(CONFIG_NETMAP) += netmap.o
+common-obj-$(CONFIG_COLO) += colo-nic.o
diff --git a/net/colo-nic.c b/net/colo-nic.c
new file mode 100644
index 0000000..965af49
--- /dev/null
+++ b/net/colo-nic.c
@@ -0,0 +1,73 @@
+/*
+ * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO)
+ * (a.k.a. Fault Tolerance or Continuous Replication)
+ *
+ * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD.
+ * Copyright (c) 2015 FUJITSU LIMITED
+ * Copyright (c) 2015 Intel Corporation
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later.  See the COPYING file in the top-level directory.
+ *
+ */
+#include "include/migration/migration.h"
+#include "migration/migration-colo.h"
+#include "net/net.h"
+#include "net/colo-nic.h"
+#include "qemu/error-report.h"
+
+
+typedef struct nic_device {
+    NetClientState *nc;
+    bool (*support_colo)(NetClientState *nc);
+    int (*configure)(NetClientState *nc, bool up, int side, int index);
+    QTAILQ_ENTRY(nic_device) next;
+    bool is_up;
+} nic_device;
+
+
+
+QTAILQ_HEAD(, nic_device) nic_devices = QTAILQ_HEAD_INITIALIZER(nic_devices);
+static int colo_nic_side = -1;
+
+/*
+* colo_proxy_script usage
+* ./colo_proxy_script master/slave install/uninstall phy_if virt_if index
+*/
+static bool colo_nic_support(NetClientState *nc)
+{
+    return nc && nc->colo_script[0] && nc->colo_nicname[0];
+}
+
+void colo_add_nic_devices(NetClientState *nc)
+{
+    struct nic_device *nic = g_malloc0(sizeof(*nic));
+
+    nic->support_colo = colo_nic_support;
+    nic->configure = NULL;
+    /*
+     * TODO
+     * only support "-netdev tap,colo_scripte..."  options
+     * "-net nic -net tap..." options is not supported
+     */
+    nic->nc = nc;
+
+    QTAILQ_INSERT_TAIL(&nic_devices, nic, next);
+}
+
+void colo_remove_nic_devices(NetClientState *nc)
+{
+    struct nic_device *nic, *next_nic;
+
+    if (!nc || colo_nic_side == -1) {
+        return;
+    }
+
+    QTAILQ_FOREACH_SAFE(nic, &nic_devices, next, next_nic) {
+        if (nic->nc == nc) {
+            QTAILQ_REMOVE(&nic_devices, nic, next);
+            g_free(nic);
+        }
+    }
+    colo_nic_side = -1;
+}
diff --git a/net/tap.c b/net/tap.c
index 823f78e..d64e046 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -41,6 +41,7 @@
 #include "qemu/error-report.h"
 
 #include "net/tap.h"
+#include "net/colo-nic.h"
 
 #include "net/vhost_net.h"
 
@@ -296,6 +297,8 @@ static void tap_cleanup(NetClientState *nc)
 
     qemu_purge_queued_packets(nc);
 
+    colo_remove_nic_devices(nc);
+
     if (s->down_script[0])
         launch_script(s->down_script, s->down_script_arg, s->fd);
 
@@ -603,7 +606,7 @@ static int net_init_tap_one(const NetdevTapOptions *tap, 
NetClientState *peer,
                             const char *model, const char *name,
                             const char *ifname, const char *script,
                             const char *downscript, const char *vhostfdname,
-                            int vnet_hdr, int fd)
+                            int vnet_hdr, int fd, bool setup_colo)
 {
     Error *err = NULL;
     TAPState *s;
@@ -647,6 +650,10 @@ static int net_init_tap_one(const NetdevTapOptions *tap, 
NetClientState *peer,
                  tap->colo_nicname);
     }
 
+    if (setup_colo) {
+        colo_add_nic_devices(nc);
+    }
+
     if (tap->has_vhost ? tap->vhost :
         vhostfdname || (tap->has_vhostforce && tap->vhostforce)) {
         VhostNetOptions options;
@@ -756,7 +763,7 @@ int net_init_tap(const NetClientOptions *opts, const char 
*name,
 
         if (net_init_tap_one(tap, peer, "tap", name, NULL,
                              script, downscript,
-                             vhostfdname, vnet_hdr, fd)) {
+                             vhostfdname, vnet_hdr, fd, true)) {
             return -1;
         }
     } else if (tap->has_fds) {
@@ -803,7 +810,7 @@ int net_init_tap(const NetClientOptions *opts, const char 
*name,
             if (net_init_tap_one(tap, peer, "tap", name, ifname,
                                  script, downscript,
                                  tap->has_vhostfds ? vhost_fds[i] : NULL,
-                                 vnet_hdr, fd)) {
+                                 vnet_hdr, fd, false)) {
                 return -1;
             }
         }
@@ -827,7 +834,7 @@ int net_init_tap(const NetClientOptions *opts, const char 
*name,
 
         if (net_init_tap_one(tap, peer, "bridge", name, ifname,
                              script, downscript, vhostfdname,
-                             vnet_hdr, fd)) {
+                             vnet_hdr, fd, false)) {
             close(fd);
             return -1;
         }
@@ -870,7 +877,8 @@ int net_init_tap(const NetClientOptions *opts, const char 
*name,
             if (net_init_tap_one(tap, peer, "tap", name, ifname,
                                  i >= 1 ? "no" : script,
                                  i >= 1 ? "no" : downscript,
-                                 vhostfdname, vnet_hdr, fd)) {
+                                 vhostfdname, vnet_hdr, fd,
+                                 i == 0)) {
                 close(fd);
                 return -1;
             }
diff --git a/stubs/migration-colo.c b/stubs/migration-colo.c
index 75b9940..61fe22b 100644
--- a/stubs/migration-colo.c
+++ b/stubs/migration-colo.c
@@ -12,6 +12,7 @@
 
 #include "migration/migration-colo.h"
 #include "qmp-commands.h"
+#include "net/colo-nic.h"
 
 bool colo_supported(void)
 {
@@ -37,6 +38,14 @@ bool loadvm_in_colo_state(void)
     return false;
 }
 
+void colo_add_nic_devices(NetClientState *nc)
+{
+}
+
+void colo_remove_nic_devices(NetClientState *nc)
+{
+}
+
 void qmp_colo_lost_heartbeat(Error **errp)
 {
     error_setg(errp, "COLO is not supported, please rerun configure"
-- 
1.7.12.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]