You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

291 lines
10 KiB

From 4c88c2859e3f974b2dc3c7726409c83076df8985 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Tue, 13 Jan 2015 15:06:48 +0100
Subject: [PATCH] network: enhance team support
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.
---
modules.d/40network/ifup.sh | 38 ++++++++++++++++++++++++++++---------
modules.d/40network/module-setup.sh | 37 ++++++++++++++++++++++++++++++++++++
modules.d/40network/net-genrules.sh | 9 ++++++---
modules.d/40network/net-lib.sh | 18 ++++++++++++++++++
modules.d/40network/parse-team.sh | 30 +++++++++++++++++++----------
modules.d/45ifcfg/write-ifcfg.sh | 10 +++++++++-
6 files changed, 119 insertions(+), 23 deletions(-)
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
index 8749c4c2..7836a6b3 100755
--- a/modules.d/40network/ifup.sh
+++ b/modules.d/40network/ifup.sh
@@ -34,14 +34,16 @@ for i in /tmp/bond.*.info; do
done
done
-if [ -e /tmp/team.info ]; then
- . /tmp/team.info
+for i in /tmp/team.*.info; do
+ [ -e "$i" ] || continue
+ unset teamslaves
+ unset teammaster
for slave in $teamslaves ; do
if [ "$netif" = "$slave" ] ; then
netif=$teammaster
fi
done
-fi
+done
if [ -e /tmp/vlan.info ]; then
. /tmp/vlan.info
@@ -205,26 +207,44 @@ if [ -e /tmp/bond.${netif}.info ]; then
fi
fi
-if [ -e /tmp/team.info ]; then
- . /tmp/team.info
+if [ -e /tmp/team.${netif}.info ]; then
+ . /tmp/team.${netif}.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
+ 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+="$slave "
fi
done
# Do not add slaves now
- teamd -d -U -n -t $teammaster -f /etc/teamd/$teammaster.conf
+ teamd -d -U -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
fi
fi
diff --git a/modules.d/40network/module-setup.sh b/modules.d/40network/module-setup.sh
index a5e796f4..a52e881b 100755
--- a/modules.d/40network/module-setup.sh
+++ b/modules.d/40network/module-setup.sh
@@ -95,6 +95,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.*" \
diff --git a/modules.d/40network/net-genrules.sh b/modules.d/40network/net-genrules.sh
index a43e3df1..3664984f 100755
--- a/modules.d/40network/net-genrules.sh
+++ b/modules.d/40network/net-genrules.sh
@@ -31,11 +31,14 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh
MASTER_IFACES="$MASTER_IFACES ${bondname}"
done
- if [ -e /tmp/team.info ]; then
- . /tmp/team.info
+ for i in /tmp/team.*.info; do
+ [ -e "$i" ] || continue
+ unset teamslaves
+ unset teammaster
+ . "$i"
IFACES="$IFACES ${teamslaves}"
MASTER_IFACES="$MASTER_IFACES ${teammaster}"
- fi
+ done
if [ -e /tmp/vlan.info ]; then
. /tmp/vlan.info
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
index 9c6b9dae..82827b6d 100755
--- a/modules.d/40network/net-lib.sh
+++ b/modules.d/40network/net-lib.sh
@@ -643,3 +643,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%,}
+}
diff --git a/modules.d/40network/parse-team.sh b/modules.d/40network/parse-team.sh
index 318c0e1e..a836d688 100755
--- a/modules.d/40network/parse-team.sh
+++ b/modules.d/40network/parse-team.sh
@@ -24,21 +24,31 @@ parseteam() {
unset teammaster teamslaves
case $# in
- 2) teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;;
- *) die "team= requires two parameters" ;;
+ 2) teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;;
+ *) warn "team= requires two parameters"; return 1;;
esac
+ return 0
}
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
+ for team in $(getargs team); do
+ [ "$team" = "team" ] && continue
+
+ 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
fi
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
index a1bae72f..b2462dae 100755
--- a/modules.d/45ifcfg/write-ifcfg.sh
+++ b/modules.d/45ifcfg/write-ifcfg.sh
@@ -128,6 +128,7 @@ for netup in /tmp/net.*.did-setup ; do
[ -e /tmp/ifcfg/ifcfg-$netif ] && continue
unset bridge
unset bond
+ unset team
unset bondslaves
unset bondname
unset bondoptions
@@ -140,10 +141,13 @@ for netup in /tmp/net.*.did-setup ; do
unset slave
unset ethname
[ -e /tmp/bond.${netif}.info ] && . /tmp/bond.${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
@@ -152,6 +156,9 @@ for netup in /tmp/net.*.did-setup ; do
vlan=yes
fi
+ # skip team interfaces for now, the host config must be in sync
+ [ "$netif" = "$teammaster" ] && continue
+
{
echo "# Generated by dracut initrd"
echo "NAME=\"$netif\""
@@ -198,7 +205,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"
@@ -264,6 +271,7 @@ for netup in /tmp/net.*.did-setup ; do
) >> /tmp/ifcfg/ifcfg-$slave
done
fi
+
i=1
for ns in $(getargs nameserver); do
echo "DNS${i}=\"${ns}\"" >> /tmp/ifcfg/ifcfg-$netif