Commit 033c948b authored by Ben Hutchings's avatar Ben Hutchings

scripts/local: Apply a single time limit to all device discovery

Instead of counting how many times we wait and poll for each critical
device (root or /usr) to appear, use /proc/uptime to tell how long we
have waited in total (starting from when local_top runs).

This is complicated by the hack mdadm's local-block uses to decide
when 2/3 of the time limit has expired.  Use an even worse hack to
keep it working.
Signed-off-by: 's avatarBen Hutchings <ben@decadent.org.uk>
parent dc22177c
......@@ -8,6 +8,14 @@ local_top()
[ "$quiet" != "y" ] && log_end_msg
fi
local_top_used=yes
# Start time for measuring elapsed time in local_device_setup
if [ -z "${local_top_time}" ]; then
local_top_time="$(cat /proc/uptime)"
local_top_time="${local_top_time%%[. ]*}"
local_top_time=$((local_top_time + 1)) # round up
export local_top_time
fi
}
local_block()
......@@ -36,6 +44,7 @@ local_bottom()
fi
local_premount_used=no
local_top_used=no
unset local_top_time
}
# $1=device ID to mount
......@@ -46,6 +55,8 @@ local_device_setup()
local dev_id="$1"
local name="$2"
local real_dev
local time_elapsed
local count
wait_for_udev 10
......@@ -81,15 +92,38 @@ local_device_setup()
while true; do
sleep 1
time_elapsed="$(cat /proc/uptime)"
time_elapsed="${time_elapsed%%[. ]*}"
time_elapsed=$((time_elapsed - local_top_time))
local_block "${dev_id}"
# If mdadm's local-block script counts the
# number of times it is run, make sure to
# run it the expected number of times.
while true; do
if [ -f /run/count.mdadm.initrd ]; then
count="$(cat /run/count.mdadm.initrd)"
elif [ -n "${count}" ]; then
# mdadm script deleted it; put it back
count=$((count + 1))
echo "${count}" >/run/count.mdadm.initrd
else
break
fi
if [ ${count} -ge ${time_elapsed} ]; then
break;
fi
/scripts/local-block/mdadm "${dev_id}"
done
if real_dev=$(resolve_device "${dev_id}") &&
get_fstype "${real_dev}" >/dev/null; then
wait_for_udev 10
log_end_msg 0
break
fi
slumber=$(( ${slumber} - 1 ))
if [ ${slumber} -eq 0 ]; then
if [ ${time_elapsed} -ge ${slumber} ]; then
log_end_msg 1 || true
break
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment