-
Notifications
You must be signed in to change notification settings - Fork 0
/
bond-dummy-enslave.sh
executable file
·56 lines (51 loc) · 1.74 KB
/
bond-dummy-enslave.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
#
# Copyright (c) 2018, 2021 StorPool
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# This tool is inspired by similar tools in the fedora-sysv/initscripts
# package which carry the following copyright notice:
#
# Copyright (c) 1996-2014 Red Hat, Inc. all rights reserved.
set -e
bond="$1"
dummyname="$2"
if [ ! -d "/sys/class/net/$bond" ]; then
echo "$dummyname: waiting 60 seconds for $bond to appear" 1>&2
count=0
while [ ! -d "/sys/class/net/$bond" ]; do
sleep 0.1
count="$((count + 1))"
if [ "$count" -gt 600 ]; then
echo "$dummyname: the $bond interface is still not up after 60 seconds, proceeding anyway" 1>&2
break
fi
done
fi
if [ ! -d "/sys/class/net/$dummyname" ]; then
/sbin/ip link add "$dummyname" type dummy
fi
master_path="$(readlink "/sys/class/net/$dummyname/master" 2>/dev/null || true)"
if [ -n "$master_path" ]; then
master_device="$(basename -- "$master_path")"
if [ "$master_device" != "$bond" ]; then
echo "The $dummyname device already has a master device: $master_device" 1>&2
exit 1
fi
else
echo 0 > "/sys/class/net/${dummyname}/carrier"
/sbin/ip link set "$dummyname" master "$bond"
fi