Blame SOURCES/0235-network-enhance-team-support.patch

18971c
From 4c88c2859e3f974b2dc3c7726409c83076df8985 Mon Sep 17 00:00:00 2001
18971c
From: Harald Hoyer <harald@redhat.com>
18971c
Date: Tue, 13 Jan 2015 15:06:48 +0100
18971c
Subject: [PATCH] network: enhance team support
18971c
18971c
Install ifcfg-* files with team configuration in the initramfs.
18971c
18971c
Improve the slave configuration of the team interface, by looking up
18971c
ifcfg files in the initramfs.
18971c
18971c
Create a default loadbalance team config, if none present in the
18971c
initramfs.
18971c
---
18971c
 modules.d/40network/ifup.sh         | 38 ++++++++++++++++++++++-------
18971c
 modules.d/40network/module-setup.sh | 37 ++++++++++++++++++++++++++++
18971c
 modules.d/40network/net-genrules.sh |  9 ++++---
18971c
 modules.d/40network/net-lib.sh      | 18 ++++++++++++++
18971c
 modules.d/40network/parse-team.sh   | 30 +++++++++++++++--------
18971c
 modules.d/45ifcfg/write-ifcfg.sh    | 10 +++++++-
18971c
 6 files changed, 119 insertions(+), 23 deletions(-)
18971c
18971c
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
18971c
index 8749c4c2..7836a6b3 100755
18971c
--- a/modules.d/40network/ifup.sh
18971c
+++ b/modules.d/40network/ifup.sh
18971c
@@ -34,14 +34,16 @@ for i in /tmp/bond.*.info; do
18971c
     done
18971c
 done
18971c
 
18971c
-if [ -e /tmp/team.info ]; then
18971c
-    . /tmp/team.info
18971c
+for i in /tmp/team.*.info; do
18971c
+    [ -e "$i" ] || continue
18971c
+    unset teamslaves
18971c
+    unset teammaster
18971c
     for slave in $teamslaves ; do
18971c
         if [ "$netif" = "$slave" ] ; then
18971c
             netif=$teammaster
18971c
         fi
18971c
     done
18971c
-fi
18971c
+done
18971c
 
18971c
 if [ -e /tmp/vlan.info ]; then
18971c
     . /tmp/vlan.info
18971c
@@ -205,26 +207,44 @@ if [ -e /tmp/bond.${netif}.info ]; then
18971c
     fi
18971c
 fi
18971c
 
18971c
-if [ -e /tmp/team.info ]; then
18971c
-    . /tmp/team.info
18971c
+if [ -e /tmp/team.${netif}.info ]; then
18971c
+    . /tmp/team.${netif}.info
18971c
     if [ "$netif" = "$teammaster" ] && [ ! -e /tmp/net.$teammaster.up ] ; then
18971c
         # We shall only bring up those _can_ come up
18971c
         # in case of some slave is gone in active-backup mode
18971c
         working_slaves=""
18971c
         for slave in $teamslaves ; do
18971c
-            ip link set $slave up 2>/dev/null
18971c
+            teamdctl ${teammaster} port present ${slave} 2>/dev/null \
18971c
+                     && continue
18971c
+            ip link set dev $slave up 2>/dev/null
18971c
             if wait_for_if_up $slave; then
18971c
                 working_slaves+="$slave "
18971c
             fi
18971c
         done
18971c
         # Do not add slaves now
18971c
-        teamd -d -U -n -t $teammaster -f /etc/teamd/$teammaster.conf
18971c
+        teamd -d -U -n -t $teammaster -f /etc/teamd/${teammaster}.conf
18971c
         for slave in $working_slaves; do
18971c
             # team requires the slaves to be down before joining team
18971c
-            ip link set $slave down
18971c
+            ip link set dev $slave down
18971c
+            (
18971c
+                unset TEAM_PORT_CONFIG
18971c
+                _hwaddr=$(cat /sys/class/net/$slave/address)
18971c
+                _subchannels=$(iface_get_subchannels "$slave")
18971c
+                if [ -n "$_hwaddr" ] && [ -e "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf" ]; then
18971c
+                    . "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf"
18971c
+                elif [ -n "$_subchannels" ] && [ -e "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf" ]; then
18971c
+                    . "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf"
18971c
+                elif [ -e "/etc/sysconfig/network-scripts/ifcfg-${slave}" ]; then
18971c
+                    . "/etc/sysconfig/network-scripts/ifcfg-${slave}"
18971c
+                fi
18971c
+
18971c
+                if [ -n "${TEAM_PORT_CONFIG}" ]; then
18971c
+                    /usr/bin/teamdctl ${teammaster} port config update ${slave} "${TEAM_PORT_CONFIG}"
18971c
+                fi
18971c
+            )
18971c
             teamdctl $teammaster port add $slave
18971c
         done
18971c
-        ip link set $teammaster up
18971c
+        ip link set dev $teammaster up
18971c
     fi
18971c
 fi
18971c
 
18971c
diff --git a/modules.d/40network/module-setup.sh b/modules.d/40network/module-setup.sh
18971c
index a5e796f4..a52e881b 100755
18971c
--- a/modules.d/40network/module-setup.sh
18971c
+++ b/modules.d/40network/module-setup.sh
18971c
@@ -95,6 +95,43 @@ install() {
18971c
     inst_hook cmdline 99 "$moddir/parse-ifname.sh"
18971c
     inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
18971c
 
18971c
+    # install all config files for teaming
18971c
+    unset TEAM_MASTER
18971c
+    unset TEAM_CONFIG
18971c
+    unset TEAM_PORT_CONFIG
18971c
+    unset HWADDR
18971c
+    unset SUBCHANNELS
18971c
+    for i in /etc/sysconfig/network-scripts/ifcfg-*; do
18971c
+        [ -e "$i" ] || continue
18971c
+        case "$i" in
18971c
+            *~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave)
18971c
+                continue
18971c
+                ;;
18971c
+        esac
18971c
+        (
18971c
+            . "$i"
18971c
+            if ! [ "${ONBOOT}" = "no" -o "${ONBOOT}" = "NO" ] \
18971c
+                    && [ -n "${TEAM_MASTER}${TEAM_CONFIG}${TEAM_PORT_CONFIG}" ]; then
18971c
+                if [ -n "$TEAM_CONFIG" ] && [ -n "$DEVICE" ]; then
18971c
+                    mkdir -p $initdir/etc/teamd
18971c
+                    printf -- "%s" "$TEAM_CONFIG" > "$initdir/etc/teamd/${DEVICE}.conf"
18971c
+                elif [ -n "$TEAM_PORT_CONFIG" ]; then
18971c
+                    inst_simple "$i"
18971c
+
18971c
+                    HWADDR="$(echo $HWADDR | sed 'y/ABCDEF/abcdef/')"
18971c
+                    if [ -n "$HWADDR" ]; then
18971c
+                        ln_r "$i" "/etc/sysconfig/network-scripts/mac-${HWADDR}.conf"
18971c
+                    fi
18971c
+
18971c
+                    SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')"
18971c
+                    if [ -n "$SUBCHANNELS" ]; then
18971c
+                        ln_r "$i" "/etc/sysconfig/network-scripts/ccw-${SUBCHANNELS}.conf"
18971c
+                    fi
18971c
+                fi
18971c
+            fi
18971c
+        )
18971c
+    done
18971c
+
18971c
     _arch=$(uname -m)
18971c
 
18971c
     inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \
18971c
diff --git a/modules.d/40network/net-genrules.sh b/modules.d/40network/net-genrules.sh
18971c
index a43e3df1..3664984f 100755
18971c
--- a/modules.d/40network/net-genrules.sh
18971c
+++ b/modules.d/40network/net-genrules.sh
18971c
@@ -31,11 +31,14 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh
18971c
         MASTER_IFACES="$MASTER_IFACES ${bondname}"
18971c
     done
18971c
 
18971c
-    if [ -e /tmp/team.info ]; then
18971c
-        . /tmp/team.info
18971c
+    for i in /tmp/team.*.info; do
18971c
+        [ -e "$i" ] || continue
18971c
+        unset teamslaves
18971c
+        unset teammaster
18971c
+        . "$i"
18971c
         IFACES="$IFACES ${teamslaves}"
18971c
         MASTER_IFACES="$MASTER_IFACES ${teammaster}"
18971c
-    fi
18971c
+    done
18971c
 
18971c
     if [ -e /tmp/vlan.info ]; then
18971c
         . /tmp/vlan.info
18971c
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
18971c
index 9c6b9dae..82827b6d 100755
18971c
--- a/modules.d/40network/net-lib.sh
18971c
+++ b/modules.d/40network/net-lib.sh
18971c
@@ -643,3 +643,21 @@ is_kernel_ethernet_name() {
18971c
     esac
18971c
 
18971c
 }
18971c
+
18971c
+iface_get_subchannels() {
18971c
+    local _netif
18971c
+    local _subchannels
18971c
+
18971c
+    _netif="$1"
18971c
+
18971c
+    _subchannels=$({
18971c
+        for i in /sys/class/net/$_netif/device/cdev[0-9]*; do
18971c
+            [ -e $i ] || continue
18971c
+            channel=$(readlink -f $i)
18971c
+            printf -- "%s" "${channel##*/},"
18971c
+        done
18971c
+    })
18971c
+    [ -n "$_subchannels" ] || return 1
18971c
+
18971c
+    printf -- "%s" ${_subchannels%,}
18971c
+}
18971c
diff --git a/modules.d/40network/parse-team.sh b/modules.d/40network/parse-team.sh
18971c
index 318c0e1e..a836d688 100755
18971c
--- a/modules.d/40network/parse-team.sh
18971c
+++ b/modules.d/40network/parse-team.sh
18971c
@@ -24,21 +24,31 @@ parseteam() {
18971c
 
18971c
     unset teammaster teamslaves
18971c
     case $# in
18971c
-    2)  teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;;
18971c
-    *)  die "team= requires two parameters" ;;
18971c
+        2)  teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;;
18971c
+        *)  warn "team= requires two parameters"; return 1;;
18971c
     esac
18971c
+    return 0
18971c
 }
18971c
 
18971c
 unset teammaster teamslaves
18971c
 
18971c
 if getarg team>/dev/null; then
18971c
     # Read team= parameters if they exist
18971c
-    team="$(getarg team=)"
18971c
-    if [ ! "$team" = "team" ]; then
18971c
-        parseteam "$(getarg team=)"
18971c
-    fi
18971c
-
18971c
-    echo "teammaster=$teammaster" > /tmp/team.info
18971c
-    echo "teamslaves=\"$teamslaves\"" >> /tmp/team.info
18971c
-    return
18971c
+    for team in $(getargs team); do
18971c
+        [ "$team" = "team" ] && continue
18971c
+
18971c
+        unset teammaster
18971c
+        unset teamslaves
18971c
+
18971c
+        parseteam "$team" || continue
18971c
+
18971c
+        echo "teammaster=$teammaster" > /tmp/team.${teammaster}.info
18971c
+        echo "teamslaves=\"$teamslaves\"" >> /tmp/team.${teammaster}.info
18971c
+
18971c
+        if ! [ -e /etc/teamd/${teammaster}.conf ]; then
18971c
+            warn "Team master $teammaster specified, but no /etc/teamd/$teammaster.conf present. Using activebackup."
18971c
+            mkdir -p /etc/teamd
18971c
+            printf -- "%s" '{"runner": {"name": "activebackup"}, "link_watch": {"name": "ethtool"}}' > "/etc/teamd/${teammaster}.conf"
18971c
+        fi
18971c
+    done
18971c
 fi
18971c
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
18971c
index a1bae72f..b2462dae 100755
18971c
--- a/modules.d/45ifcfg/write-ifcfg.sh
18971c
+++ b/modules.d/45ifcfg/write-ifcfg.sh
18971c
@@ -128,6 +128,7 @@ for netup in /tmp/net.*.did-setup ; do
18971c
     [ -e /tmp/ifcfg/ifcfg-$netif ] && continue
18971c
     unset bridge
18971c
     unset bond
18971c
+    unset team
18971c
     unset bondslaves
18971c
     unset bondname
18971c
     unset bondoptions
18971c
@@ -140,10 +141,13 @@ for netup in /tmp/net.*.did-setup ; do
18971c
     unset slave
18971c
     unset ethname
18971c
     [ -e /tmp/bond.${netif}.info ] && . /tmp/bond.${netif}.info
18971c
+    [ -e /tmp/team.${netif}.info ] && . /tmp/team.${netif}.info
18971c
 
18971c
     uuid=$(cat /proc/sys/kernel/random/uuid)
18971c
     if [ "$netif" = "$bridgename" ]; then
18971c
         bridge=yes
18971c
+    elif [ "$netif" = "$teammaster" ]; then
18971c
+        team=yes
18971c
     elif [ "$netif" = "$bondname" ]; then
18971c
     # $netif can't be bridge and bond at the same time
18971c
         bond=yes
18971c
@@ -152,6 +156,9 @@ for netup in /tmp/net.*.did-setup ; do
18971c
         vlan=yes
18971c
     fi
18971c
 
18971c
+    # skip team interfaces for now, the host config must be in sync
18971c
+    [ "$netif" = "$teammaster" ] && continue
18971c
+
18971c
     {
18971c
         echo "# Generated by dracut initrd"
18971c
         echo "NAME=\"$netif\""
18971c
@@ -198,7 +205,7 @@ for netup in /tmp/net.*.did-setup ; do
18971c
     } > /tmp/ifcfg/ifcfg-$netif
18971c
 
18971c
     # bridge needs different things written to ifcfg
18971c
-    if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ]; then
18971c
+    if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ] && [ -z "$team" ]; then
18971c
         # standard interface
18971c
         {
18971c
             echo "TYPE=Ethernet"
18971c
@@ -264,6 +271,7 @@ for netup in /tmp/net.*.did-setup ; do
18971c
             ) >> /tmp/ifcfg/ifcfg-$slave
18971c
         done
18971c
     fi
18971c
+
18971c
     i=1
18971c
     for ns in $(getargs nameserver); do
18971c
         echo "DNS${i}=\"${ns}\"" >> /tmp/ifcfg/ifcfg-$netif