summaryrefslogtreecommitdiffstats
path: root/core/modules/dnbd3-proxy-mode/data/opt/openslx/scripts/systemd-dnbd3_local_stage4
blob: 0afa7a265b9438b535210127afe2deda4d8d1303 (plain) (blame)
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
#!/bin/ash

# Force immediate switch to localhost for stage4 if applicable
if [ -d "/mnt/dnbd3" ] && [ -b /dev/dnbd0 ] \
		&& [ "$( cat /sys/block/dnbd0/net/rid )" -gt 0 ]; then
	DNBD3_PORT=5003
	# give it some time to start
	usleep 250000
	if ! grep -q -F 127.0.0.1 /sys/block/dnbd0/net/alt_servers; then
		# add the server
		if ! dnbd3-client -A "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0; then
			echo "WARN: Cannot add localhost to dnbd0" >&2
		fi
	fi
	# Call this repeatedly - this will keep resetting the RTT values to
	# prevent switching away from localhost for some time, which can
	# sometimes happen during bootup, if the system is so busy that the
	# local dnbd3 proxy replies slower than some upstream server on the
	# network, which is not that unlikely if the data is not cached
	# locally yet.
	for i in 1 2 4 8 16 32 64 128; do
		dnbd3-client -s "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0 &> /dev/null
		usleep ${i}00000 # tenths of a second
	done
	# One last time without swallowing any errors
	dnbd3-client -s "127.0.0.1:$DNBD3_PORT" -d /dev/dnbd0
fi

exit 0