Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 271896 | Differences between
and this patch

Collapse All | Expand All

(-)bonding.sh.orig (-7 / +82 lines)
Lines 15-21 Link Here
15
#
15
#
16
# Expose variables that can be configured
16
# Expose variables that can be configured
17
bonding_expose() {
17
bonding_expose() {
18
	variables slaves
18
	variables slaves bonding
19
}
19
}
20
20
21
# bool bonding_check_installed(void)
21
# bool bonding_check_installed(void)
Lines 23-28 Link Here
23
# Returns 0 if ifenslave is installed, otherwise 1
23
# Returns 0 if ifenslave is installed, otherwise 1
24
bonding_check_installed() {
24
bonding_check_installed() {
25
	[[ -x /sbin/ifenslave ]] && return 0
25
	[[ -x /sbin/ifenslave ]] && return 0
26
	[[ -f /sys/class/net/bonding_masters ]] && return 0
26
	${1:-false} && eerror "For link aggregation (bonding) support, emerge net-misc/ifenslave"
27
	${1:-false} && eerror "For link aggregation (bonding) support, emerge net-misc/ifenslave"
27
	return 1
28
	return 1
28
}
29
}
Lines 38-45 Link Here
38
#
39
#
39
# Bonds the interface
40
# Bonds the interface
40
bonding_pre_start() {
41
bonding_pre_start() {
41
	local iface="$1" s= ifvar=$(bash_variable "$1")
42
	local iface="$1" s= ifvar=$(bash_variable "$1") b= retval=0
42
	local -a slaves=()
43
	local -a slaves=() bonding=()
43
44
44
	slaves="slaves_${ifvar}[@]"
45
	slaves="slaves_${ifvar}[@]"
45
	[[ -z ${!slaves} ]] && return 0
46
	[[ -z ${!slaves} ]] && return 0
Lines 48-53 Link Here
48
	# Support space seperated slaves
49
	# Support space seperated slaves
49
	[[ ${#slaves[@]} == 1 ]] && slaves=( ${slaves} )
50
	[[ ${#slaves[@]} == 1 ]] && slaves=( ${slaves} )
50
51
52
	bonding="bonding_${ifvar}[@]"
53
	bonding=( "${!bonding}" )
54
55
	# Support space seperated bonding options
56
	[[ ${#bonding[@]} == 1 ]] && bonding=( ${bonding} )
57
58
	# Check for bonding support, otherwise load module
59
        if test ! -d /proc/net/bonding ; then
60
        	if modprobe bonding ; then
61
			# Loading the bonding module can automatically create bonds
62
			# We don't want that.
63
			if [ -d /sys/class/net/${iface} ] ; then
64
				einfo "Bringing ${iface} down, as bonding probably created it"
65
				interface_down "${iface}" && {
66
					ebegin "Waiting 5 seconds for bonding to settle";
67
					sleep 5;
68
					eend 0;
69
				}
70
			fi
71
		else
72
                	eerror "Cannot load the bonding module"
73
                	return 1
74
        	fi
75
        fi
76
77
	# Check for bonding_ifvar config
78
	if test -n ${bonding} ; then
79
		# Loading the bonding module can automatically create bonds
80
		# We don't want that.
81
		if [ -d /sys/class/net/${iface} ] ; then
82
			einfo "Bringing ${iface} down, as bonding probably created it"
83
			interface_down "${iface}" && {
84
				ebegin "Waiting 5 seconds for bonding to settle";
85
				sleep 5;
86
				eend 0;
87
			}
88
		fi
89
		if test -f /sys/class/net/bonding_masters ; then
90
			# Create bond
91
			echo "+${iface}" > /sys/class/net/bonding_masters 2> /dev/null
92
			# Wait for bond to settle
93
			sleep 4
94
			# Set options
95
			for b in "${bonding[@]}" ; do
96
				echo ${b/*=/} > /sys/class/net/${iface}/bonding/${b/=*/} 2> /dev/null
97
			done
98
		else
99
			# Complain if bonding_masters doesn't exist
100
			eerror "bonding module older than 3.0.0 (or bonding not available), sysfs support not available"
101
		fi
102
	fi
103
51
	interface_exists "${iface}" true || return 1
104
	interface_exists "${iface}" true || return 1
52
105
53
	if ! bonding_exists "${iface}" ; then
106
	if ! bonding_exists "${iface}" ; then
Lines 67-73 Link Here
67
	# Must force the slaves to a particular state before adding them
120
	# Must force the slaves to a particular state before adding them
68
	for s in "${slaves[@]}" ; do
121
	for s in "${slaves[@]}" ; do
69
		interface_del_addresses "${s}"
122
		interface_del_addresses "${s}"
70
		interface_up "${s}"
123
		test -n ${bonding} && interface_down "${s}" || interface_up "${s}"
71
	done
124
	done
72
125
73
	# now force the master to up
126
	# now force the master to up
Lines 75-82 Link Here
75
128
76
	# finally add in slaves
129
	# finally add in slaves
77
	eoutdent
130
	eoutdent
78
	/sbin/ifenslave "${iface}" ${slaves[@]} >/dev/null
131
	if test -n ${bonding} ; then
79
	eend $?
132
		for s in "${slaves[@]}" ; do
133
			echo "+${s}" > /sys/class/net/${iface}/bonding/slaves
134
			ret=$?
135
			[[ ${retval} = 0 ]] && retval=${ret}
136
		done
137
		# Set options again, as some don't work earlier
138
		for b in "${bonding[@]}" ; do
139
			echo ${b/*=/} > /sys/class/net/${iface}/bonding/${b/=*/} 2> /dev/null
140
		done
141
	else
142
		/sbin/ifenslave "${iface}" ${slaves[@]} >/dev/null
143
		retval=$?
144
	fi
145
	eend $retval
80
146
81
	return 0 #important
147
	return 0 #important
82
}
148
}
Lines 103-109 Link Here
103
	eindent
169
	eindent
104
	einfo "${slaves}"
170
	einfo "${slaves}"
105
	eoutdent
171
	eoutdent
106
	/sbin/ifenslave -d "${iface}" ${slaves}
172
	if test -n "$(cat /sys/class/net/bonding_masters)" ; then
173
		for s in ${slaves}; do
174
			echo "-${s}" > /sys/class/net/${iface}/bonding/slaves
175
		done
176
	else
177
		/sbin/ifenslave -d "${iface}" ${slaves}
178
	fi
107
179
108
	# reset all slaves
180
	# reset all slaves
109
	for s in ${slaves}; do
181
	for s in ${slaves}; do
Lines 112-117 Link Here
112
			interface_down "${s}"
184
			interface_down "${s}"
113
		fi
185
		fi
114
	done
186
	done
187
	echo "-${iface}" > /sys/class/net/bonding_masters
188
	# Wait for bond to settle
189
	sleep 4
115
190
116
	eend 0
191
	eend 0
117
	return 0
192
	return 0

Return to bug 271896