]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/hyperv/tools/scripts/hyperv_vfattach
MFC 321762
[FreeBSD/stable/10.git] / contrib / hyperv / tools / scripts / hyperv_vfattach
1 #!/bin/sh
2
3 #
4 # If transparent VF is enabled, don't do anything.
5 #
6
7 sysctl -n hw.hn.vf_transparent > /dev/null 2>&1
8 if [ $? -ne 0 ]
9 then
10         # Old kernel; no transparent VF.
11         vf_transparent=0
12 else
13         vf_transparent=`sysctl -n hw.hn.vf_transparent`
14 fi
15
16 if [ $vf_transparent -ne 0 ]
17 then
18         # Transparent VF; done!
19         exit 0
20 fi
21
22 iface=$1
23 delay=$2
24
25 if [ $delay -gt 0 ]
26 then
27         #
28         # Delayed VF up.
29         #
30         sleep $delay
31         ifconfig $iface up
32         # Done!
33         exit $?
34 fi
35
36 #
37 # Check to see whether $iface is a VF or not.
38 # If $iface is a VF, bring it up now.
39 #
40
41 # for hyperv_vf_delay
42 . /etc/rc.conf
43
44 sysctl -n hw.hn.vflist > /dev/null 2>&1
45 if [ $? -ne 0 ]
46 then
47         # Old kernel; nothing could be done properly.
48         exit 0
49 fi
50 vf_list=`sysctl -n hw.hn.vflist`
51
52 for vf in $vf_list
53 do
54         if [ $vf = $iface ]
55         then
56                 #
57                 # Linger a little bit (at least 2 seconds) mainly to
58                 # make sure that $iface is fully attached.
59                 #
60                 # NOTE:
61                 # In Azure hyperv_vf_delay should be configured to a
62                 # large value, e.g. 120 seconds, to avoid racing cloud
63                 # agent goofs.
64                 #
65                 test $hyperv_vf_delay -ge 2 > /dev/null 2>&1
66                 if [ $? -ne 0 ]
67                 then
68                         hyperv_vf_delay=2
69                 fi
70                 #
71                 # NOTE:
72                 # "(sleep ..; ifconfig .. up) > /dev/null 2>&1 &"
73                 # does _not_ work.
74                 #
75                 daemon -f /usr/libexec/hyperv/hyperv_vfattach \
76                     $iface $hyperv_vf_delay
77                 break
78         fi
79 done