tests: Ensure that mountpoints are unmounted before exiting

When all tests complete successfully, filesystems mounted by grub-fs-tester
will be unmounted before exiting. However, on certain test failures the
tester will exit with a failure code and not unmount previously mounted
filesystems. Now keep track of mounts and umounts and run an exit handler
on exit or process interruption that will umount all mounts that haven't
already been unmounted.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Glenn Washburn authored and Daniel Kiper committed 2022-04-26 14:45:10 +02:00
1 parent a4666d31ba
commit f035853761
1 file changed
+26 -3
+26 -3
View File
@@ -14,6 +14,16 @@ tempdir=`mktemp -d "${TMPDIR:-/tmp}/${0##*/}.$(date '+%Y%m%d%H%M%S%N').${fs}.XXX
# FSLABEL. This is especially needed for the conversion to Joliet UCS-2. # FSLABEL. This is especially needed for the conversion to Joliet UCS-2.
XORRISOFS_CHARSET="-input-charset UTF-8 -output-charset UTF-8" XORRISOFS_CHARSET="-input-charset UTF-8 -output-charset UTF-8"
MOUNTS=
cleanup() {
for i in $MOUNTS; do
umount "$i" || :
done
}
trap cleanup EXIT INT
# This is for bash, dash and ash do not recognize ERR
trap cleanup ERR || :
# This wrapper is to ease insertion of valgrind or time statistics # This wrapper is to ease insertion of valgrind or time statistics
run_it () { run_it () {
LC_ALL=C "$GRUBFSTEST" "$@" LC_ALL=C "$GRUBFSTEST" "$@"
@@ -935,6 +945,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
done done
exit 99; exit 99;
fi fi
MOUNTS="$MOUNTS $MNTPOINTRW"
;; ;;
esac esac
case x"$fs" in case x"$fs" in
@@ -1059,11 +1070,13 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
x"bfs") x"bfs")
sleep 1 sleep 1
fusermount -u "$MNTPOINTRW" fusermount -u "$MNTPOINTRW"
MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
;; ;;
xlvm*) xlvm*)
sleep 1 sleep 1
for try in $(range 0 20 1); do for try in $(range 0 20 1); do
if umount "$MNTPOINTRW" ; then if umount "$MNTPOINTRW" ; then
MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
break; break;
fi fi
sleep 1; sleep 1;
@@ -1076,6 +1089,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
sleep 1 sleep 1
for try in $(range 0 20 1); do for try in $(range 0 20 1); do
if umount "$MNTPOINTRW" ; then if umount "$MNTPOINTRW" ; then
MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
break; break;
fi fi
sleep 1; sleep 1;
@@ -1088,6 +1102,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
sleep 1 sleep 1
for try in $(range 0 20 1); do for try in $(range 0 20 1); do
if umount "$MNTPOINTRW" ; then if umount "$MNTPOINTRW" ; then
MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
break; break;
fi fi
sleep 1; sleep 1;
@@ -1117,13 +1132,19 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
xlvm*) xlvm*)
vgchange -a y grub_test vgchange -a y grub_test
sleep 1 sleep 1
mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;; mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro
MOUNTS="$MOUNTS $MNTPOINTRO"
;;
xmdraid*) xmdraid*)
mdadm --assemble /dev/md/"${fs}_$NDEVICES" $LODEVICES mdadm --assemble /dev/md/"${fs}_$NDEVICES" $LODEVICES
sleep 1 sleep 1
mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;; mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro
MOUNTS="$MOUNTS $MNTPOINTRO"
;;
*) *)
mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;; mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro
MOUNTS="$MOUNTS $MNTPOINTRO"
;;
esac esac
run_grubfstest ls -- -la run_grubfstest ls -- -la
@@ -1548,6 +1569,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
sleep 1 sleep 1
umount "$MNTPOINTRO" || true umount "$MNTPOINTRO" || true
umount "$MNTPOINTRW" || true umount "$MNTPOINTRW" || true
MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRO||g;")"
MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
esac esac
sleep 1 sleep 1
case x"$fs" in case x"$fs" in