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

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