[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH COLO-Frame v6 21/31] COLO NIC: Implement colo nic de
From: |
zhanghailiang |
Subject: |
[Qemu-devel] [PATCH COLO-Frame v6 21/31] COLO NIC: Implement colo nic device interface configure() |
Date: |
Thu, 18 Jun 2015 16:58:45 +0800 |
Implement colo nic device interface configure()
add a script to configure nic devices:
${QEMU_SCRIPT_DIR}/colo-proxy-script.sh
Cc: Stefan Hajnoczi <address@hidden>
Cc: Jason Wang <address@hidden>
Signed-off-by: zhanghailiang <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
---
include/net/tap.h | 17 +++++++++
net/colo-nic.c | 47 ++++++++++++++++++++---
net/tap.c | 17 ---------
scripts/colo-proxy-script.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 148 insertions(+), 23 deletions(-)
create mode 100755 scripts/colo-proxy-script.sh
diff --git a/include/net/tap.h b/include/net/tap.h
index ac99b31..9688765 100644
--- a/include/net/tap.h
+++ b/include/net/tap.h
@@ -29,6 +29,23 @@
#include "qemu-common.h"
#include "qapi-types.h"
#include "standard-headers/linux/virtio_net.h"
+#include "net/net.h"
+#include "net/vhost_net.h"
+
+typedef struct TAPState {
+ NetClientState nc;
+ int fd;
+ char down_script[1024];
+ char down_script_arg[128];
+ uint8_t buf[NET_BUFSIZE];
+ bool read_poll;
+ bool write_poll;
+ bool using_vnet_hdr;
+ bool has_ufo;
+ bool enabled;
+ VHostNetState *vhost_net;
+ unsigned host_vnet_hdr_len;
+} TAPState;
int tap_enable(NetClientState *nc);
int tap_disable(NetClientState *nc);
diff --git a/net/colo-nic.c b/net/colo-nic.c
index 9745817..c7dd473 100644
--- a/net/colo-nic.c
+++ b/net/colo-nic.c
@@ -15,7 +15,7 @@
#include "net/net.h"
#include "net/colo-nic.h"
#include "qemu/error-report.h"
-
+#include "net/tap.h"
typedef struct nic_device {
COLONicState *cns;
@@ -28,10 +28,45 @@ typedef struct nic_device {
QTAILQ_HEAD(, nic_device) nic_devices = QTAILQ_HEAD_INITIALIZER(nic_devices);
-/*
-* colo_proxy_script usage
-* ./colo_proxy_script master/slave install/uninstall phy_if virt_if index
-*/
+static int colo_nic_configure(COLONicState *cns,
+ bool up, int side, int index)
+{
+ int i, argc = 6;
+ char *argv[7], index_str[32];
+ char **parg;
+ NetClientState *nc = container_of(cns, NetClientState, cns);
+ TAPState *s = DO_UPCAST(TAPState, nc, nc);
+ Error *err = NULL;
+
+ if (!cns && index <= 0) {
+ error_report("Can not parse colo_script or colo_nicname");
+ return -1;
+ }
+
+ parg = argv;
+ *parg++ = cns->script;
+ *parg++ = (char *)(side == COLO_MODE_SECONDARY ? "secondary" : "primary");
+ *parg++ = (char *)(up ? "install" : "uninstall");
+ *parg++ = cns->nicname;
+ *parg++ = cns->ifname;
+ sprintf(index_str, "%d", index);
+ *parg++ = index_str;
+ *parg = NULL;
+
+ for (i = 0; i < argc; i++) {
+ if (!argv[i][0]) {
+ error_report("Can not get colo_script argument");
+ return -1;
+ }
+ }
+
+ launch_script(argv, s->fd, &err);
+ if (err) {
+ error_report_err(err);
+ return -1;
+ }
+ return 0;
+}
void colo_add_nic_devices(COLONicState *cns)
{
@@ -51,7 +86,7 @@ void colo_add_nic_devices(COLONicState *cns)
}
nic = g_malloc0(sizeof(*nic));
- nic->configure = NULL;
+ nic->configure = colo_nic_configure;
nic->cns = cns;
QTAILQ_INSERT_TAIL(&nic_devices, nic, next);
diff --git a/net/tap.c b/net/tap.c
index 78104b2..1339085 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -43,23 +43,6 @@
#include "net/tap.h"
#include "net/colo-nic.h"
-#include "net/vhost_net.h"
-
-typedef struct TAPState {
- NetClientState nc;
- int fd;
- char down_script[1024];
- char down_script_arg[128];
- uint8_t buf[NET_BUFSIZE];
- bool read_poll;
- bool write_poll;
- bool using_vnet_hdr;
- bool has_ufo;
- bool enabled;
- VHostNetState *vhost_net;
- unsigned host_vnet_hdr_len;
-} TAPState;
-
static void tap_send(void *opaque);
static void tap_writable(void *opaque);
diff --git a/scripts/colo-proxy-script.sh b/scripts/colo-proxy-script.sh
new file mode 100755
index 0000000..9ebff21
--- /dev/null
+++ b/scripts/colo-proxy-script.sh
@@ -0,0 +1,90 @@
+#!/bin/sh
+#usage:
+# colo-proxy-script.sh primary/secondary install/uninstall phy_if virt_if index
+#.e.g:
+# colo-proxy-script.sh primary install eth2 tap0 1
+
+side=$1
+action=$2
+phy_if=$3
+virt_if=$4
+index=$5
+br=br1
+failover_br=br0
+
+script_usage()
+{
+ echo -n "usage: ./colo-proxy-script.sh primary/secondary "
+ echo -e "install/uninstall phy_if virt_if index\n"
+}
+
+primary_install()
+{
+ tc qdisc add dev $virt_if root handle 1: prio
+ tc filter add dev $virt_if parent 1: protocol ip prio 10 u32 match u32 \
+ 0 0 flowid 1:2 action mirred egress mirror dev $phy_if
+ tc filter add dev $virt_if parent 1: protocol arp prio 11 u32 match u32 \
+ 0 0 flowid 1:2 action mirred egress mirror dev $phy_if
+ tc filter add dev $virt_if parent 1: protocol ipv6 prio 12 u32 match u32 \
+ 0 0 flowid 1:2 action mirred egress mirror dev $phy_if
+
+ /usr/local/sbin/iptables -t mangle -I PREROUTING -m physdev --physdev-in \
+ $virt_if -j PMYCOLO --index $index --forward-dev $phy_if
+ /usr/local/sbin/ip6tables -t mangle -I PREROUTING -m physdev --physdev-in \
+ $virt_if -j PMYCOLO --index $index --forward-dev $phy_if
+ /usr/local/sbin/arptables -I INPUT -i $phy_if -j MARK --set-mark $index
+}
+
+primary_uninstall()
+{
+ tc filter del dev $virt_if parent 1: protocol ip prio 10 u32 match u32 \
+ 0 0 flowid 1:2 action mirred egress mirror dev $phy_if
+ tc filter del dev $virt_if parent 1: protocol arp prio 11 u32 match u32 \
+ 0 0 flowid 1:2 action mirred egress mirror dev $phy_if
+ tc filter del dev $virt_if parent 1: protocol ipv6 prio 12 u32 match u32 \
+ 0 0 flowid 1:2 action mirred egress mirror dev $phy_if
+ tc qdisc del dev $virt_if root handle 1: prio
+
+ /usr/local/sbin/iptables -t mangle -D PREROUTING -m physdev --physdev-in \
+ $virt_if -j PMYCOLO --index $index --forward-dev $phy_if
+ /usr/local/sbin/ip6tables -t mangle -D PREROUTING -m physdev --physdev-in \
+ $virt_if -j PMYCOLO --index $index --forward-dev $phy_if
+ /usr/local/sbin/arptables -F
+}
+
+secondary_install()
+{
+ brctl addif $br $phy_if
+
+ /usr/local/sbin/iptables -t mangle -I PREROUTING -m physdev --physdev-in \
+ $virt_if -j SECCOLO --index $index
+ /usr/local/sbin/ip6tables -t mangle -I PREROUTING -m physdev --physdev-in \
+ $virt_if -j SECCOLO --index $index
+}
+
+secondary_uninstall()
+{
+ brctl delif $br $phy_if
+ brctl delif $br $virt_if
+ brctl addif $failover_br $virt_if
+
+ /usr/local/sbin/iptables -t mangle -F
+ /usr/local/sbin/ip6tables -t mangle -F
+}
+
+if [ $# -ne 5 ]; then
+ script_usage
+ exit 1
+fi
+
+if [ "x$side" != "xprimary" ] && [ "x$side" != "xsecondary" ]; then
+ script_usage
+ exit 2
+fi
+
+if [ "x$action" != "xinstall" ] && [ "x$action" != "xuninstall" ]; then
+ script_usage
+ exit 3
+fi
+
+${side}_${action}
--
1.7.12.4
- [Qemu-devel] [PATCH COLO-Frame v6 09/31] COLO: Save VM state to slave when do checkpoint, (continued)
- [Qemu-devel] [PATCH COLO-Frame v6 09/31] COLO: Save VM state to slave when do checkpoint, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 12/31] arch_init: Start to trace dirty pages of SVM, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 13/31] COLO RAM: Flush cached RAM into SVM's memory, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 07/31] COLO: Add a new RunState RUN_STATE_COLO, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 08/31] QEMUSizedBuffer: Introduce two help functions for qsb, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 11/31] COLO VMstate: Load VM state into qsb before restore it, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 15/31] COLO failover: Implement COLO primary/secondary vm failover work, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 02/31] migration: Introduce capability 'colo' to migration, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 14/31] COLO failover: Introduce a new command to trigger a failover, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 17/31] COLO failover: Don't do failover during loading VM's state, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 21/31] COLO NIC: Implement colo nic device interface configure(),
zhanghailiang <=
- [Qemu-devel] [PATCH COLO-Frame v6 24/31] COLO: Handle nfnetlink message from proxy module, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 19/31] COLO NIC: Init/remove colo nic devices when add/cleanup tap devices, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 26/31] COLO: Improve checkpoint efficiency by do additional periodic checkpoint, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 25/31] COLO: Do checkpoint according to the result of packets comparation, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 20/31] tap: Make launch_script() public, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 16/31] qmp event: Add event notification for COLO error, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 22/31] COLO NIC : Implement colo nic init/destroy function, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 29/31] COLO: Disable qdev hotplug when VM is in COLO mode, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 31/31] COLO: Add block replication into colo process, zhanghailiang, 2015/06/18
- [Qemu-devel] [PATCH COLO-Frame v6 28/31] COLO NIC: Implement NIC checkpoint and failover, zhanghailiang, 2015/06/18