]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
network: enhance team support
authorHarald Hoyer <harald@redhat.com>
Tue, 13 Jan 2015 14:06:48 +0000 (15:06 +0100)
committerHarald Hoyer <harald@redhat.com>
Thu, 30 Mar 2017 09:50:35 +0000 (11:50 +0200)
Install ifcfg-* files with team configuration in the initramfs.

Improve the slave configuration of the team interface, by looking up
ifcfg files in the initramfs.

Create a default loadbalance team config, if none present in the
initramfs.

forward port of
4c88c2859e3f974b2dc3c7726409c83076df8985

modules.d/40network/ifup.sh
modules.d/40network/module-setup.sh
modules.d/40network/net-lib.sh
modules.d/40network/parse-team.sh
modules.d/45ifcfg/write-ifcfg.sh

index 5d498ede2af72d3d48214018b0517006b0ca2a34..fd721e74866e2e78b3ec0a50ce3b8d272e5ccb4f 100755 (executable)
@@ -298,20 +298,38 @@ if [ -z "$NO_TEAM_MASTER" ]; then
                 # 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
+                    teamdctl ${teammaster} port present ${slave} 2>/dev/null \
+                        && continue
+                    ip link set dev $slave up 2>/dev/null
                     if wait_for_if_up $slave; then
                         working_slaves="$working_slaves$slave "
                     fi
                 done
                 # Do not add slaves now
-                teamd -d -U -n -N -t $teammaster -f /etc/teamd/$teammaster.conf
+                teamd -d -U -n -N -t $teammaster -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
+                    ip link set dev $slave down
+                    (
+                        unset TEAM_PORT_CONFIG
+                        _hwaddr=$(cat /sys/class/net/$slave/address)
+                        _subchannels=$(iface_get_subchannels "$slave")
+                        if [ -n "$_hwaddr" ] && [ -e "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf" ]; then
+                            . "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf"
+                        elif [ -n "$_subchannels" ] && [ -e "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf" ]; then
+                            . "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf"
+                        elif [ -e "/etc/sysconfig/network-scripts/ifcfg-${slave}" ]; then
+                            . "/etc/sysconfig/network-scripts/ifcfg-${slave}"
+                        fi
+
+                        if [ -n "${TEAM_PORT_CONFIG}" ]; then
+                            /usr/bin/teamdctl ${teammaster} port config update ${slave} "${TEAM_PORT_CONFIG}"
+                        fi
+                    )
                     teamdctl $teammaster port add $slave
                 done
 
-                ip link set $teammaster up
+                ip link set dev $teammaster up
 
                 > /tmp/team.$teammaster.up
                 NO_TEAM_MASTER=yes ifup $teammaster
index 6730f16e52c2d1d791c3e3ae741351af3af63fd2..b3a1519e372611ebd730e9ff38d303158bc29c8a 100755 (executable)
@@ -47,6 +47,43 @@ install() {
     inst_hook cmdline 99 "$moddir/parse-ifname.sh"
     inst_hook cleanup 10 "$moddir/kill-dhclient.sh"
 
+    # install all config files for teaming
+    unset TEAM_MASTER
+    unset TEAM_CONFIG
+    unset TEAM_PORT_CONFIG
+    unset HWADDR
+    unset SUBCHANNELS
+    for i in /etc/sysconfig/network-scripts/ifcfg-*; do
+        [ -e "$i" ] || continue
+        case "$i" in
+            *~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave)
+                continue
+                ;;
+        esac
+        (
+            . "$i"
+            if ! [ "${ONBOOT}" = "no" -o "${ONBOOT}" = "NO" ] \
+                    && [ -n "${TEAM_MASTER}${TEAM_CONFIG}${TEAM_PORT_CONFIG}" ]; then
+                if [ -n "$TEAM_CONFIG" ] && [ -n "$DEVICE" ]; then
+                    mkdir -p $initdir/etc/teamd
+                    printf -- "%s" "$TEAM_CONFIG" > "$initdir/etc/teamd/${DEVICE}.conf"
+                elif [ -n "$TEAM_PORT_CONFIG" ]; then
+                    inst_simple "$i"
+
+                    HWADDR="$(echo $HWADDR | sed 'y/ABCDEF/abcdef/')"
+                    if [ -n "$HWADDR" ]; then
+                        ln_r "$i" "/etc/sysconfig/network-scripts/mac-${HWADDR}.conf"
+                    fi
+
+                    SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')"
+                    if [ -n "$SUBCHANNELS" ]; then
+                        ln_r "$i" "/etc/sysconfig/network-scripts/ccw-${SUBCHANNELS}.conf"
+                    fi
+                fi
+            fi
+        )
+    done
+
     _arch=$(uname -m)
 
     inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" \
index b86721bce3ef6918789c8cd0f9298b8dc4864268..75051544ebd35a03f1863753698056218c022751 100755 (executable)
@@ -817,3 +817,21 @@ is_kernel_ethernet_name() {
     esac
 
 }
+
+iface_get_subchannels() {
+    local _netif
+    local _subchannels
+
+    _netif="$1"
+
+    _subchannels=$({
+                      for i in /sys/class/net/$_netif/device/cdev[0-9]*; do
+                          [ -e $i ] || continue
+                          channel=$(readlink -f $i)
+                          printf -- "%s" "${channel##*/},"
+                      done
+                  })
+    [ -n "$_subchannels" ] || return 1
+
+    printf -- "%s" ${_subchannels%,}
+}
index cc5cba7ee4f19d4a0df4e6c625a271b0115c681f..a6eef18efe0e5d37428f83839c897c7bdd0df2d4 100755 (executable)
@@ -18,13 +18,24 @@ parseteam() {
     2)  teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;;
     *)  die "team= requires two parameters" ;;
     esac
+    return 0
 }
 
+for team in $(getargs team); do
+    [ "$team" = "team" ] && continue
 
-for team in $(getargs team=); do
-    unset teammaster teamslaves
-    parseteam "$(getarg team=)"
+    unset teammaster
+    unset teamslaves
+
+    parseteam "$team" || continue
 
     echo "teammaster=$teammaster" > /tmp/team.${teammaster}.info
     echo "teamslaves=\"$teamslaves\"" >> /tmp/team.${teammaster}.info
+
+    if ! [ -e /etc/teamd/${teammaster}.conf ]; then
+        warn "Team master $teammaster specified, but no /etc/teamd/$teammaster.conf present. Using activebackup."
+        mkdir -p /etc/teamd
+        printf -- "%s" '{"runner": {"name": "activebackup"}, "link_watch": {"name": "ethtool"}}' > "/etc/teamd/${teammaster}.conf"
+    fi
 done
+
index 811a847825c9400dc494594fd0edfab6f2cad03b..25c81be3f510d58f534a13410bd8c257cc94885d 100755 (executable)
@@ -123,6 +123,7 @@ for netup in /tmp/net.*.did-setup ; do
     unset bondoptions
     unset bridgename
     unset bridgeslaves
+    unset team
     unset uuid
     unset ip
     unset gw
@@ -137,10 +138,13 @@ for netup in /tmp/net.*.did-setup ; do
 
     [ -e /tmp/bond.${netif}.info ] && . /tmp/bond.${netif}.info
     [ -e /tmp/bridge.${netif}.info ] && . /tmp/bridge.${netif}.info
+    [ -e /tmp/team.${netif}.info ] && . /tmp/team.${netif}.info
 
     uuid=$(cat /proc/sys/kernel/random/uuid)
     if [ "$netif" = "$bridgename" ]; then
         bridge=yes
+    elif [ "$netif" = "$teammaster" ]; then
+        team=yes
     elif [ "$netif" = "$bondname" ]; then
         # $netif can't be bridge and bond at the same time
         bond=yes
@@ -153,6 +157,9 @@ for netup in /tmp/net.*.did-setup ; do
         break
     done
 
+    # skip team interfaces for now, the host config must be in sync
+    [ "$netif" = "$teammaster" ] && continue
+
     {
         echo "# Generated by dracut initrd"
         echo "NAME=\"$netif\""
@@ -199,7 +206,7 @@ for netup in /tmp/net.*.did-setup ; do
     } > /tmp/ifcfg/ifcfg-$netif
 
     # bridge needs different things written to ifcfg
-    if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ]; then
+    if [ -z "$bridge" ] && [ -z "$bond" ] && [ -z "$vlan" ] && [ -z "$team" ]; then
         # standard interface
         echo "TYPE=Ethernet" >> /tmp/ifcfg/ifcfg-$netif
     fi