From af1f0a23c57d71953342cc2df904a656f8ff73c9 Mon Sep 17 00:00:00 2001 From: Tim Nordell Date: Tue, 15 Jun 2021 16:25:25 -0500 Subject: [PATCH] pluto automounter: Retry automount in case device driver isn't ready The automounter can try to mount the device prematurely. Catch this kind of error output and retry a few times with some time in between in case we can successfully mount this device. Signed-off-by: Tim Nordell --- board/pluto/automounter.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/board/pluto/automounter.sh b/board/pluto/automounter.sh index 6aa77324b0..0d093a53fc 100644 --- a/board/pluto/automounter.sh +++ b/board/pluto/automounter.sh @@ -12,11 +12,36 @@ my_umount() [ -d "${destdir}/$1" ] && rmdir "${destdir}/$1" } +do_mount() +{ + local errno + local err + + errno=0 + for I in $(seq 5) + do + err=$(mount -t auto -o sync "/dev/$1" "${destdir}/$1" 2>&1) + errno=$? + + # If we get a "Device or resource busy" error, retry again in a + # little bit, otherwise just return immediately. + if ! echo "${err}" | grep -q "Device or resource busy" + then + return ${errno} + fi + + sleep .25 + done + + echo "${err}" >&2 + return ${errno} +} + my_mount() { mkdir -p "${destdir}/$1" || exit 1 - if ! mount -t auto -o sync "/dev/$1" "${destdir}/$1"; then + if ! do_mount $1; then # failed to mount, clean up mountpoint rmdir "${destdir}/$1" exit 1