]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut: add team device support
authorCong Wang <amwang@redhat.com>
Thu, 13 Dec 2012 14:30:25 +0000 (22:30 +0800)
committerHarald Hoyer <harald@redhat.com>
Fri, 14 Dec 2012 08:06:51 +0000 (09:06 +0100)
V2: merge patch 2/2
    fix active-backup mode by adding slaves one by one
    sync with the latest teamd
    improve the comments
    wait for team ports to come up
    install /etc/libnl/classid too

This patch adds the initial support for team device [1].
A new cmdline team= is introduced for it.

Note, currently we don't support stacked devices
on/under team, it is tricky and can be added on request.

1. http://www.libteam.org/

Cc: Harald Hoyer <harald@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Cong Wang <amwang@redhat.com>
dracut.cmdline.7.asc
modules.d/40network/ifup.sh
modules.d/40network/module-setup.sh
modules.d/40network/net-genrules.sh
modules.d/40network/parse-team.sh [new file with mode: 0755]

index 4ab77a6bccf3bcbbe2acfbb48a38cdb1773cf84f..ab0468a4496993942c73d0d0f88454a4bd6a1b1d 100644 (file)
@@ -420,6 +420,10 @@ interface name. Better name it "bootnet" or "bluesocket".
     then its values should be separated by semicolon.
     Bond without parameters assumes bond=bond0:eth0,eth1:mode=balance-rr
 
+**team =_<teammaster>_:_<teamslaves>_**::
+    Setup team device <teammaster> on top of <teamslaves>.
+    <teamslaves> is a comma-separated list of physical (ethernet) interfaces.
+
 **bridge=_<bridgename>_:_<ethnames>_**::
     Setup bridge <bridgename> with <ethnames>. <ethnames> is a comma-separated
     list of physical (ethernet) interfaces. Bridge without parameters assumes bridge=br0:eth0
index 70bc1612d88db4fe50725514496826060f531592..576e276604788695c5a94689522684c8c1b0d2e5 100755 (executable)
@@ -28,6 +28,15 @@ if [ -e /tmp/bond.info ]; then
     done
 fi
 
+if [ -e /tmp/team.info ]; then
+    . /tmp/team.info
+    for slave in $teamslaves ; do
+        if [ "$netif" = "$slave" ] ; then
+            netif=$teammaster
+        fi
+    done
+fi
+
 # bridge this interface?
 if [ -e /tmp/bridge.info ]; then
     . /tmp/bridge.info
@@ -167,6 +176,28 @@ if [ -e /tmp/bond.info ]; then
     fi
 fi
 
+if [ -e /tmp/team.info ]; then
+    . /tmp/team.info
+    if [ "$netif" = "$teammaster" ] && [ ! -e /tmp/net.$teammaster.up ] ; then
+        # We shall only bring up those _can_ come up
+        # in case of some slave is gone in active-backup mode
+        working_slaves=""
+        for slave in $teamslaves ; do
+            ip link set $slave up 2>/dev/null
+            if wait_for_if_up $slave; then
+                working_slaves+="$slave "
+            fi
+        done
+        # Do not add slaves now
+        teamd -d -U -n -f /etc/teamd/$teammaster.conf
+        for slave in $working_slaves; do
+            # team requires the slaves to be down before joining team
+            ip link set $slave down
+            teamdctl $teammaster port add $slave
+        done
+        ip link set $teammaster up
+    fi
+fi
 
 # XXX need error handling like dhclient-script
 
index da0f44770760ced40e14a3ae8c65ca62e2a1dcbb..524fefbd95fda190a4391f48b9d10c5fc14d0488 100755 (executable)
@@ -64,7 +64,8 @@ installkernel() {
     { find_kernel_modules_by_path drivers/net; if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then find_kernel_modules_by_path drivers/s390/net; fi; } \
         | net_module_filter | instmods
 
-    instmods =drivers/net/phy ecb arc4 bridge stp llc ipv6 bonding 8021q af_packet virtio_net
+    #instmods() will take care of hostonly
+    instmods =drivers/net/phy ecb arc4 bridge stp llc ipv6 bonding 8021q af_packet virtio_net =drivers/net/team
 }
 
 install() {
@@ -72,6 +73,8 @@ install() {
     dracut_install ip arping dhclient sed
     dracut_install -o ping ping6
     dracut_install -o brctl
+    dracut_install -o teamd teamdctl teamnl
+    inst_simple /etc/libnl/classid
     inst_script "$moddir/ifup.sh" "/sbin/ifup"
     inst_script "$moddir/netroot.sh" "/sbin/netroot"
     inst_script "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
@@ -82,6 +85,7 @@ install() {
     inst_hook cmdline 91 "$moddir/dhcp-root.sh"
     inst_hook cmdline 95 "$moddir/parse-vlan.sh"
     inst_hook cmdline 96 "$moddir/parse-bond.sh"
+    inst_hook cmdline 96 "$moddir/parse-team.sh"
     inst_hook cmdline 97 "$moddir/parse-bridge.sh"
     inst_hook cmdline 98 "$moddir/parse-ip-opts.sh"
     inst_hook cmdline 99 "$moddir/parse-ifname.sh"
index d2197ffefa9c188906f2cd6db49940d2ba177690..50e223d2cdefae5af4ae5f038e652fbae372d90b 100755 (executable)
@@ -34,6 +34,11 @@ fi
         IFACES+=" ${bondslaves%% *}"
     fi
 
+    if [ -e /tmp/team.info ]; then
+        . /tmp/team.info
+        IFACES+=" ${teamslaves}"
+    fi
+
     if [ -e /tmp/vlan.info ]; then
         . /tmp/vlan.info
         IFACES+=" $phydevice"
diff --git a/modules.d/40network/parse-team.sh b/modules.d/40network/parse-team.sh
new file mode 100755 (executable)
index 0000000..318c0e1
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/sh
+#
+# Format:
+#       team=<teammaster>:<teamslaves>
+#
+#       teamslaves is a comma-separated list of physical (ethernet) interfaces
+#
+
+# return if team already parsed
+[ -n "$teammaster" ] && return
+
+# Check if team parameter is valid
+if getarg team= >/dev/null ; then
+    :
+fi
+
+parseteam() {
+    local v=${1}:
+    set --
+    while [ -n "$v" ]; do
+        set -- "$@" "${v%%:*}"
+        v=${v#*:}
+    done
+
+    unset teammaster teamslaves
+    case $# in
+    2)  teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;;
+    *)  die "team= requires two parameters" ;;
+    esac
+}
+
+unset teammaster teamslaves
+
+if getarg team>/dev/null; then
+    # Read team= parameters if they exist
+    team="$(getarg team=)"
+    if [ ! "$team" = "team" ]; then
+        parseteam "$(getarg team=)"
+    fi
+
+    echo "teammaster=$teammaster" > /tmp/team.info
+    echo "teamslaves=\"$teamslaves\"" >> /tmp/team.info
+    return
+fi