[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/5] tests: Ensure that mountpoints are unmounted before exiting
From: |
Glenn Washburn |
Subject: |
[PATCH 4/5] tests: Ensure that mountpoints are unmounted before exiting |
Date: |
Sun, 6 Feb 2022 02:02:43 -0600 |
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>
---
tests/util/grub-fs-tester.in | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in
index a1f3f299b..ebd7b1e03 100644
--- a/tests/util/grub-fs-tester.in
+++ b/tests/util/grub-fs-tester.in
@@ -13,6 +13,16 @@ tempdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
# FSLABEL. This is especially needed for the conversion to Joliet UCS-2.
XORRISOFS_CHARSET="-input-charset UTF-8 -output-charset UTF-8"
+MOUNTS=
+cleanup() {
+ for i in $MOUNTS; do
+ umount "$i" || :
+ done
+}
+trap umount_all EXIT INT
+# This is for bash, dash and ash do not recognize ERR
+trap umount_all ERR || :
+
# This wrapper is to ease insertion of valgrind or time statistics
run_it () {
LC_ALL=C "$GRUBFSTEST" "$@"
@@ -934,6 +944,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE"
1); do
done
exit 99;
fi
+ MOUNTS="$MOUNTS $MNTPOINTRW"
;;
esac
case x"$fs" in
@@ -1058,11 +1069,13 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE"
"$MAXLOGSECSIZE" 1); do
x"bfs")
sleep 1
fusermount -u "$MNTPOINTRW"
+ MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
;;
xlvm*)
sleep 1
for try in $(range 0 20 1); do
if umount "$MNTPOINTRW" ; then
+ MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
break;
fi
sleep 1;
@@ -1075,6 +1088,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE"
"$MAXLOGSECSIZE" 1); do
sleep 1
for try in $(range 0 20 1); do
if umount "$MNTPOINTRW" ; then
+ MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
break;
fi
sleep 1;
@@ -1087,6 +1101,7 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE"
"$MAXLOGSECSIZE" 1); do
sleep 1
for try in $(range 0 20 1); do
if umount "$MNTPOINTRW" ; then
+ MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
break;
fi
sleep 1;
@@ -1116,13 +1131,19 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE"
"$MAXLOGSECSIZE" 1); do
xlvm*)
vgchange -a y grub_test
sleep 1
- mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o
${MOUNTOPTS}${SELINUXOPTS}ro ;;
+ mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o
${MOUNTOPTS}${SELINUXOPTS}ro
+ MOUNTS="$MOUNTS $MNTPOINTRO"
+ ;;
xmdraid*)
mdadm --assemble /dev/md/"${fs}_$NDEVICES" $LODEVICES
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
run_grubfstest ls -- -la
@@ -1547,6 +1568,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE"
"$MAXLOGSECSIZE" 1); do
sleep 1
umount "$MNTPOINTRO" || true
umount "$MNTPOINTRW" || true
+ MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRO||g;")"
+ MOUNTS="$(echo ${MOUNTS} | sed "s|$MNTPOINTRW||g;")"
esac
sleep 1
case x"$fs" in
--
2.27.0
- Re: [PATCH 0/5] Various test fixes and improvements, Daniel Kiper, 2022/02/03
- [PATCH 0/5] Various test fixes and improvements, Glenn Washburn, 2022/02/06
- [PATCH 1/5] tests: Do not remove image file on error in pata_test, Glenn Washburn, 2022/02/06
- [PATCH 2/5] tests: Skip pata_test on i386-efi, Glenn Washburn, 2022/02/06
- [PATCH 4/5] tests: Ensure that mountpoints are unmounted before exiting,
Glenn Washburn <=
- [PATCH 5/5] tests: Ensure that loopback devices and zfs devices are cleaned up, Glenn Washburn, 2022/02/06
- [PATCH 3/5] tests: Remove $((BASE#NUM)) bashism in grub-fs-tester, Glenn Washburn, 2022/02/06
- Re: [PATCH 0/5] Various test fixes and improvements, Glenn Washburn, 2022/02/06