xref: /freebsd/contrib/hyperv/tools/scripts/hyperv_vfattach (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1#!/bin/sh
2
3#
4# If transparent VF is enabled, don't do anything.
5#
6
7sysctl -n hw.hn.vf_transparent > /dev/null 2>&1
8if [ $? -ne 0 ]
9then
10	# Old kernel; no transparent VF.
11	vf_transparent=0
12else
13	vf_transparent=`sysctl -n hw.hn.vf_transparent`
14fi
15
16if [ $vf_transparent -ne 0 ]
17then
18	# Transparent VF; done!
19	exit 0
20fi
21
22iface=$1
23delay=$2
24
25if [ $delay -gt 0 ]
26then
27	#
28	# Delayed VF up.
29	#
30	sleep $delay
31	ifconfig $iface up
32	# Done!
33	exit $?
34fi
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
44sysctl -n hw.hn.vflist > /dev/null 2>&1
45if [ $? -ne 0 ]
46then
47	# Old kernel; nothing could be done properly.
48	exit 0
49fi
50vf_list=`sysctl -n hw.hn.vflist`
51
52for vf in $vf_list
53do
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
79done
80