#!/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