[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/5] tests: Ensure that loopback devices and zfs devices are clea
From: |
Glenn Washburn |
Subject: |
[PATCH 5/5] tests: Ensure that loopback devices and zfs devices are cleaned up |
Date: |
Wed, 12 Jan 2022 21:59:43 -0600 |
ZFS file systems are not unmounted using umount, but instead by exporting
them. So export the ZFS file system that has the same label as the one that
was created during the test, if such one exists. This is required to delete
the loopback device that uses the ZFS image file. Otherwise the added code
to delete all loopback devices setup during the test run will never be able
to finish because the loopback device can not be deleted while in use.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
tests/util/grub-fs-tester.in | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in
index b39831f27..5c23c41a1 100644
--- a/tests/util/grub-fs-tester.in
+++ b/tests/util/grub-fs-tester.in
@@ -14,15 +14,32 @@ tempdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` ||
XORRISOFS_CHARSET="-input-charset UTF-8 -output-charset UTF-8"
MOUNTS=
-umount_all() {
+LODEVICES=
+cleanup() {
+ if [ -n "$fs" -a -z "${fs##*zfs*}" -a -n "$FSLABEL" ]; then
+ zpool list "$FSLABEL" 2>/dev/null &&
+ while ! zpool export "$FSLABEL" ; do
+ sleep 1;
+ done
+ fi
+
for MOUNT in $MOUNTS; do
umount "$MOUNT" &&
MOUNTS="$(echo ${MOUNTS} | sed "s|$MOUNT||g;")"
done
+
+ for lodev in $LODEVICES; do
+ local i=600
+ while losetup -l -O NAME | grep -q "^$lodev\$"; do
+ losetup -d "$lodev" || sleep 1
+ [ "$((i--))" = "0" ] && break
+ done
+ done
+ return 0
}
-trap umount_all EXIT INT
+trap cleanup EXIT INT
# This is for bash, dash and ash do not recognize ERR
-trap umount_all ERR || :
+trap cleanup ERR || :
# This wrapper is to ease insertion of valgrind or time statistics
run_it () {
--
2.27.0