]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
fstests: clean up loop device instantiation
authorDave Chinner <dchinner@redhat.com>
Tue, 26 Nov 2024 20:56:57 +0000 (07:56 +1100)
committerZorro Lang <zlang@kernel.org>
Sun, 8 Dec 2024 14:06:46 +0000 (22:06 +0800)
Lots of tests do there own special thing with loop devices rather
than using _create_loop_device() and _destroy_loop_device(). This
oftens means they do not clean up after themselves properly,
leaving stale loop devices around that result in unmountable test or
scratch devices. This is common when tests are killed by user
interrupt.

Even the tests that do use _destroy_loop_device and try to clean up
often do it incorrectly, leading to spurious error messages.

Some tests try to use dynamic instantiation via "mount -o loop",
but then don't clean up in the correct order or hack around to find
the loop device that was instantiated because the test needs to know
the instantiated device name

Clean this up by converting all the tests to use
_create_loop_device() and _destroy_loop_device(). In all the tests,
use the variable "loop_dev" for the device consistently. In
_destroy_loop_device(), test that a device name has been passed
so that we don't try to clean up the same device twice (e.g. once
before test exit and again from the _cleanup() function). When we
destroy a loop device, unset the variable used to hold the loop
device name so that we don't try to destroy it twice.

This results in much more reliable cleanup and clean exit from
fstests when killed by the user.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Zorro lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
26 files changed:
common/metadump
tests/generic/067
tests/generic/361
tests/generic/563
tests/generic/564
tests/generic/590
tests/generic/744
tests/generic/746
tests/xfs/014
tests/xfs/049
tests/xfs/073
tests/xfs/074
tests/xfs/078
tests/xfs/148
tests/xfs/149
tests/xfs/216
tests/xfs/217
tests/xfs/250
tests/xfs/259
tests/xfs/513
tests/xfs/521
tests/xfs/528
tests/xfs/530
tests/xfs/606
tests/xfs/613
tests/xfs/613.out

index 3373edfe92efd6d17174359737c6db92971698ff..3aa7adf76da4bb070caa8c7950a0c852fe668e94 100644 (file)
@@ -25,12 +25,8 @@ _xfs_cleanup_verify_metadump()
        test -n "$XFS_METADUMP_FILE" && rm -f "$XFS_METADUMP_FILE"
 
        if [ -n "$XFS_METADUMP_IMG" ]; then
-               losetup -n -a -O BACK-FILE,NAME | grep "^$XFS_METADUMP_IMG" | while read backing ldev; do
-                       losetup -d "$ldev"
-               done
-
-               # Don't call rm directly with a globbed argument here to avoid
-               # issues issues with variable expansions.
+               [ -b "$md_data_loop_dev" ] && _destroy_loop_device $md_data_loop_dev
+               [ -b "$md_log_loop_dev" ] && _destroy_loop_device $md_log_loop_dev
                for img in "$XFS_METADUMP_IMG"*; do
                        test -e "$img" && rm -f "$img"
                done
@@ -122,25 +118,27 @@ _xfs_verify_metadump_v2()
                _scratch_xfs_mdrestore $metadump_file
 
        # Create loopdev for data device so we can mount the fs
-       data_loop=$(_create_loop_device $data_img)
+       md_data_loop_dev=$(_create_loop_device $data_img)
 
        # Create loopdev for log device if we recovered anything
-       test -s "$log_img" && log_loop=$(_create_loop_device $log_img)
+       test -s "$log_img" && md_log_loop_dev=$(_create_loop_device $log_img)
 
        # Mount fs, run an extra test, fsck, and unmount
-       SCRATCH_DEV=$data_loop SCRATCH_LOGDEV=$log_loop _scratch_mount
+       SCRATCH_DEV=$md_data_loop_dev SCRATCH_LOGDEV=$md_log_loop_dev _scratch_mount
        if [ -n "$extra_test" ]; then
-               SCRATCH_DEV=$data_loop SCRATCH_LOGDEV=$log_loop $extra_test
+               SCRATCH_DEV=$md_data_loop_dev SCRATCH_LOGDEV=$md_log_loop_dev $extra_test
        fi
-       SCRATCH_DEV=$data_loop SCRATCH_LOGDEV=$log_loop _check_xfs_scratch_fs
-       SCRATCH_DEV=$data_loop _scratch_unmount
+       SCRATCH_DEV=$md_data_loop_dev SCRATCH_LOGDEV=$md_log_loop_dev _check_xfs_scratch_fs
+       _unmount $md_data_loop_dev
 
        # Tear down what we created
-       if [ -b "$log_loop" ]; then
-               _destroy_loop_device $log_loop
+       if [ -b "$md_log_loop_dev" ]; then
+               _destroy_loop_device $md_log_loop_dev
+               unset md_log_loop_dev
                rm -f $log_img
        fi
-       _destroy_loop_device $data_loop
+       _destroy_loop_device $md_data_loop_dev
+       unset md_data_loop_dev
        rm -f $data_img
 }
 
index ccb1e3fbbd17c24d85a9be0e31c060ce00efb335..b45ae834f918d22e49844a2cae5445c85689ebd7 100755 (executable)
@@ -37,13 +37,18 @@ mount_nonexistent_mnt()
        $MOUNT_PROG $SCRATCH_DEV $TEST_DIR/nosuchdir >>$seqres.full 2>&1
 }
 
-# fs driver should be able to handle mounting a free loop device gracefully
-# xfs ever hung, "ec53d1d xfs: don't block on buffer read errors" fixed it
+# fs driver should be able to handle mounting a free loop device gracefully xfs
+# ever hung, "ec53d1d xfs: don't block on buffer read errors" fixed it
+#
+# Using 'losetup -f' like this is racy. We might end up mounting a real loop dev
+# here, so unmount $SCRATCH_MNT (not the loop dev we might not own!) and ignore
+# any error it might return.
 mount_free_loopdev()
 {
        echo "# mount a free loop device" >>$seqres.full
        loopdev=`losetup -f`
-       $MOUNT_PROG -t $FSTYP $loopdev $SCRATCH_MNT >>$seqres.full 2>&1
+       _mount $loopdev $SCRATCH_MNT >>$seqres.full 2>&1
+       _unmount $SCRATCH_MNT >> /dev/null 2>&1
 }
 
 # mount with wrong fs type specified.
index 7273dd056d7a61c47a336e2df2ce1a06b482ab1a..e2b7984361e87c9df660090e40c503bf73aba15e 100755 (executable)
@@ -17,7 +17,7 @@ _begin_fstest auto quick
 _cleanup()
 {
        _unmount $fs_mnt
-       _destroy_loop_device $loop_dev
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
        cd /
        rm -f $tmp.*
 }
@@ -54,6 +54,10 @@ $XFS_IO_PROG -fc "pwrite 0 520m" $fs_mnt/testfile >>$seqres.full 2>&1
 # remount should not hang
 $MOUNT_PROG -o remount,ro $fs_mnt >>$seqres.full 2>&1
 
+_unmount $fs_mnt
+_destroy_loop_device $loop_dev
+unset loop_dev
+
 # success, all done
 echo "Silence is golden"
 status=0
index f0d2f404c3d0e9c27825a50a920b0a6f48af89a5..2056470df8259a2d7d2d2408ea1e40e1ab301bcd 100755 (executable)
@@ -19,7 +19,7 @@ _cleanup()
        echo $$ > $cgdir/cgroup.procs
        rmdir $cgdir/$seq-cg* > /dev/null 2>&1
        _unmount $SCRATCH_MNT > /dev/null 2>&1
-       _destroy_loop_device $LOOP_DEV > /dev/null 2>&1
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev > /dev/null 2>&1
        cd /
        rm -f $tmp.*
 
@@ -81,18 +81,18 @@ reset()
        $XFS_IO_PROG -fc "pwrite 0 $iosize" $SCRATCH_MNT/file \
                >> $seqres.full 2>&1
        _unmount $SCRATCH_MNT || _fail "umount failed"
-       _mount $LOOP_DEV $SCRATCH_MNT || _fail "mount failed"
+       _mount $loop_dev $SCRATCH_MNT || _fail "mount failed"
        stat $SCRATCH_MNT/file > /dev/null
 }
 
 # cgroup I/O accounting doesn't work on partitions. Use a loop device to rule
 # that out.
-LOOP_DEV=$(_create_loop_device $SCRATCH_DEV)
-smajor=$((0x`stat -L -c %t $LOOP_DEV`))
-sminor=$((0x`stat -L -c %T $LOOP_DEV`))
+loop_dev=$(_create_loop_device $SCRATCH_DEV)
+smajor=$((0x`stat -L -c %t $loop_dev`))
+sminor=$((0x`stat -L -c %T $loop_dev`))
 
-_mkfs_dev $LOOP_DEV >> $seqres.full 2>&1
-_mount $LOOP_DEV $SCRATCH_MNT || _fail "mount failed"
+_mkfs_dev $loop_dev >> $seqres.full 2>&1
+_mount $loop_dev $SCRATCH_MNT || _fail "mount failed"
 
 blksize=$(_get_block_size "$SCRATCH_MNT")
 
@@ -147,6 +147,10 @@ if [ "$drop_io_cgroup" = 1 ]; then
        echo "-io" > $cgdir/cgroup.subtree_control || _fail "subtree control"
 fi
 
+_unmount $SCRATCH_MNT
+_destroy_loop_device $loop_dev
+unset loop_dev
+
 # success, all done
 status=0
 exit
index 647472d7896bff4d44352ed7826a95719f3a2dae..b66b72496175c247de421e41296df00ec4a384cd 100755 (executable)
@@ -19,7 +19,7 @@ _cleanup()
 {
        cd /
        rm -rf $tmp.*
-       [ -z "$loopdev" ] || _destroy_loop_device $loopdev
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
 }
 
 # Import common functions.
@@ -72,11 +72,11 @@ $XFS_IO_PROG -f -c "copy_range -l 32k $testdir" $testdir/copy
 echo
 echo source/destination as blkdev returns EINVAL
 $XFS_IO_PROG -f -c "truncate 128k" $testdir/img >> $seqres.full 2>&1
-loopdev=`_create_loop_device $testdir/img`
-$XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $loopdev
-$XFS_IO_PROG -f -c "copy_range -l 32k $loopdev" $testdir/copy
-_destroy_loop_device $loopdev
-loopdev=
+loop_dev=`_create_loop_device $testdir/img`
+$XFS_IO_PROG -c "copy_range -l 32k $testdir/file" $loop_dev
+$XFS_IO_PROG -f -c "copy_range -l 32k $loop_dev" $testdir/copy
+_destroy_loop_device $loop_dev
+unset loop_dev
 
 echo
 echo source/destination as chardev returns EINVAL
index 2b7ccfb53e11443acba05c8f0992590dd723fdcd..04d86e78b751eec02b459a5b8e7dd85af24521dc 100755 (executable)
@@ -15,9 +15,10 @@ _begin_fstest auto prealloc preallocrw
 # Override the default cleanup function.
 _cleanup()
 {
+       _scratch_unmount
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
        cd /
        rm -f $tmp.*
-       test -n "$loop" && _destroy_loop_device "$loop"
        rm -f "$TEST_DIR/$seq"
 }
 
@@ -56,9 +57,9 @@ if [[ $FSTYP = xfs ]]; then
                loopsz="$((filesz + (1 << 26)))"
                _require_fs_space "$TEST_DIR" $((loopsz / 1024))
                $XFS_IO_PROG -c "truncate $loopsz" -f "$TEST_DIR/$seq"
-               loop="$(_create_loop_device "$TEST_DIR/$seq")"
+               loop_dev="$(_create_loop_device "$TEST_DIR/$seq")"
                USE_EXTERNAL=yes
-               SCRATCH_RTDEV="$loop"
+               SCRATCH_RTDEV="$loop_dev"
                disabled_features=()
 
                # disable reflink if not supported by realtime devices
@@ -114,6 +115,8 @@ $XFS_IO_PROG -c "truncate 0" -c fsync "$SCRATCH_MNT/file"
 # We need to do this before the loop device gets torn down.
 _scratch_unmount
 _check_scratch_fs
+_destroy_loop_device $loop_dev
+unset loop_dev
 
 echo "Silence is golden"
 status=0
index df8f6ae9b9e84bfb8f67283c81f05a31f7ba61d7..cda10e0f66bafb5583695a5af21725151083239f 100755 (executable)
@@ -17,8 +17,8 @@ _cleanup()
 
        _unmount $mnt2 &> /dev/null
        _unmount $mnt1 &> /dev/null
-       [ -b "$loop_dev2" ] && losetup -d $loop_dev2
-       [ -b "$loop_dev1" ] && losetup -d $loop_dev1
+       [ -b "$loop_dev2" ] && _destroy_loop_device $loop_dev2
+       [ -b "$loop_dev1" ] && _destroy_loop_device $loop_dev1
        [ -n "$seq" ] && rm -rf $TEST_DIR/$seq
 }
 
index 67191060681737dda1718245bcff8d7f956da53b..ba8ed25e84577652823e0a3841b4e73a98788fa9 100755 (executable)
@@ -39,7 +39,7 @@ esac
 _cleanup()
 {
        _unmount $loop_mnt &> /dev/null
-       _destroy_loop_device $loop_dev
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
        if [ $status -eq 0 ]; then
                rm -rf $tmp
                rm $img_file
@@ -223,5 +223,9 @@ while read line; do
 done < $fiemap_after
 echo "done."
 
+_unmount $loop_mnt
+_destroy_loop_device $loop_dev
+unset loop_dev
+
 status=0
 exit
index f638e4b161a28a1d6d3fc71490f5f6c24bb82b25..39ea40e2a3882a8a9b6bb3725f0dc7dc2ee12d97 100755 (executable)
@@ -23,6 +23,7 @@ _cleanup()
 {
        cd /
        _unmount $LOOP_MNT 2>/dev/null
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
        _scratch_unmount 2>/dev/null
        rm -f $tmp.*
 }
@@ -166,19 +167,21 @@ LOOP_FILE=$SCRATCH_MNT/$seq.fs
 LOOP_MNT=$SCRATCH_MNT/$seq.mnt
 
 $MKFS_XFS_PROG -d "file=1,name=$LOOP_FILE,size=10g" >> $seqres.full 2>&1
+loop_dev=$(_create_loop_device $LOOP_FILE)
 
 mkdir -p $LOOP_MNT
-_mount -o uquota,gquota $LOOP_FILE $LOOP_MNT || \
+_mount -o uquota,gquota $loop_dev $LOOP_MNT || \
        _fail "Failed to mount loop fs."
 
 _test_enospc $LOOP_MNT
 _test_edquot $LOOP_MNT
 
 _unmount $LOOP_MNT
+_destroy_loop_device $loop_dev
+unset loop_dev
 
 echo $orig_sp_time > /proc/sys/fs/xfs/speculative_prealloc_lifetime
 
 _scratch_unmount
-
 status=0
 exit
index 4163a144f34a7c0fd1e8ff388b6144494bbd5013..cdcddf76498cf4bafca64224464003c6f09d0805 100755 (executable)
@@ -12,16 +12,17 @@ _begin_fstest rw auto quick
 # Override the default cleanup function.
 _cleanup()
 {
-    cd /
-    umount $SCRATCH_MNT/test2 > /dev/null 2>&1
-    umount $SCRATCH_MNT/test > /dev/null 2>&1
-    rm -f $tmp.*
-
-    if [ -w $seqres.full ]
-    then
-        echo "--- mounts at end (after cleanup)" >> $seqres.full
-        mount >> $seqres.full
-    fi
+       cd /
+       _unmount $SCRATCH_MNT/test2 > /dev/null 2>&1
+       _unmount $SCRATCH_MNT/test > /dev/null 2>&1
+       [ -n "$loop_dev2" ] && _destroy_loop_device $loop_dev2
+       [ -n "$loop_dev1" ] && _destroy_loop_device $loop_dev1
+       rm -f $tmp.*
+
+       if [ -w $seqres.full ]; then
+               echo "--- mounts at end (after cleanup)" >> $seqres.full
+               mount >> $seqres.full
+       fi
 }
 
 # Import common functions.
@@ -64,7 +65,8 @@ mkdir $SCRATCH_MNT/test $SCRATCH_MNT/test2 >> $seqres.full 2>&1 \
     || _fail "!!! failed to make mount points"
 
 _log "Mount xfs via loop"
-mount -t xfs -o loop $SCRATCH_MNT/test.xfs $SCRATCH_MNT/test >> $seqres.full 2>&1 \
+loop_dev1=$(_create_loop_device $SCRATCH_MNT/test.xfs)
+_mount $loop_dev1 $SCRATCH_MNT/test >> $seqres.full 2>&1 \
     || _fail "!!! failed to loop mount xfs"
 
 _log "stress"
@@ -80,11 +82,12 @@ dd if=/dev/zero of=$SCRATCH_MNT/test/test.ext2 bs=1024 count=10240 >> $seqres.fu
     || _fail "!!! create file failed"
 
 _log "Create ext2 fs in file on looped xfs"
-echo y | mkfs -t ext2 $SCRATCH_MNT/test/test.ext2 >> $seqres.full 2>&1 \
+loop_dev2=$(_create_loop_device $SCRATCH_MNT/test/test.ext2)
+echo y | mkfs -t ext2 $loop_dev2 >> $seqres.full 2>&1 \
     || _fail "!!! failed to mkfs ext2 on xfs"
 
 _log "Mount ext2 on xfs via loop"
-mount -t ext2 -o loop $SCRATCH_MNT/test/test.ext2 $SCRATCH_MNT/test2 >> $seqres.full 2>&1 \
+_mount $loop_dev2 $SCRATCH_MNT/test2 >> $seqres.full 2>&1 \
     || _fail "!!! failed to loop mount xfs"
 
 _log "stress ext2 on xfs via loop"
@@ -96,12 +99,16 @@ rm -rf $SCRATCH_MNT/test/* >> $seqres.full 2>&1 \
     || _fail "!!! clean failed"
 
 _log "umount ext2 on xfs"
-umount $SCRATCH_MNT/test2 >> $seqres.full 2>&1 \
+_unmount $SCRATCH_MNT/test2 >> $seqres.full 2>&1 \
     || _fail "!!! umount ext2 failed"
+_destroy_loop_device $loop_dev2
+unset loop_dev2
 
 _log "umount xfs"
-umount $SCRATCH_MNT/test >> $seqres.full 2>&1 \
+_unmount $SCRATCH_MNT/test >> $seqres.full 2>&1 \
     || _fail "!!! umount xfs failed"
+_destroy_loop_device $loop_dev1
+unset loop_dev1
 
 echo "--- mounts at end (before cleanup)" >> $seqres.full
 mount >> $seqres.full
index e4b17c5e7f2fc6f593378b0302f0e1fa5c160e28..2274079ef43b137c9a6cfa5a0d745f37349cafbc 100755 (executable)
@@ -23,6 +23,8 @@ _cleanup()
        _scratch_unmount 2>/dev/null
        _unmount $imgs.loop 2>/dev/null
        _unmount $imgs.source_dir 2>/dev/null
+       [ -n "$loop_dev1" ] && _destroy_loop_device $loop_dev1
+       [ -n "$loop_dev2" ] && _destroy_loop_device $loop_dev2
        [ -d $imgs.loop ] && rmdir $imgs.loop
        [ -d $imgs.source_dir ] && rm -rf $imgs.source_dir
        rm -f $imgs.* $tmp.* /var/tmp/xfs_copy.log.*
@@ -65,10 +67,11 @@ _verify_copy()
        rmdir $target_dir 2>/dev/null
        mkdir $target_dir
 
-       _mount -t xfs -o loop $target $target_dir 2>/dev/null
+       loop_dev1=$(_create_loop_device $target)
+       _mount $loop_dev1 $target_dir 2>/dev/null
        if [ $? -ne 0 ]; then
                echo retrying mount with nouuid option >>$seqres.full
-               _mount -t xfs -o loop -o nouuid $target $target_dir
+               _mount -o nouuid $loop_dev1 $target_dir
                if [ $? -ne 0 ]; then
                        echo mount failed - evil!
                        return
@@ -100,6 +103,8 @@ _verify_copy()
        echo unmounting and removing new image
        _unmount $source_dir
        _unmount $target_dir > /dev/null 2>&1
+       _destroy_loop_device $loop_dev1
+       unset loop_dev1
        rm -f $target
 }
 
@@ -134,18 +139,15 @@ ${MKFS_XFS_PROG} -dfile,name=$imgs.source,size=100g \
 rmdir $imgs.source_dir 2>/dev/null
 mkdir $imgs.source_dir
 
-_mount -t xfs -o loop $imgs.source $imgs.source_dir
-loop2=`mount | grep $imgs.source | grep -o -e 'loop=.*[^),]' | grep -o -e '/.*$'`
+loop_dev2=$(_create_loop_device $imgs.source)
+_mount $loop_dev2 $imgs.source_dir
 cp -a $here $imgs.source_dir
-_mount -t xfs -o remount,ro $imgs.source $imgs.source_dir
-$XFS_COPY_PROG $imgs.source $imgs.image | _filter_copy '#' $imgs.image '#' '#'
+_mount -o remount,ro $loop_dev2 $imgs.source_dir
+$XFS_COPY_PROG $loop_dev2 $imgs.image 2> /dev/null | _filter_copy '#' $imgs.image '#' '#'
 _verify_copy $imgs.image $imgs.source $imgs.source_dir
 
-# HACK WARNING:
-#
-# We're done with the nested loop mount, now we have to clean
-# up the pieces that mount is incapable of doing.
-losetup -d $loop2 > /dev/null 2>&1
+_destroy_loop_device $loop_dev2
+unset loop_dev2
 
 echo
 echo === copying scratch device to multiple targets
index 6a03c81114edeb72ed3849b4cfad4bc55f0ecea3..5df864fad3b16a12f168962514a6a0925cdd9e23 100755 (executable)
@@ -26,7 +26,7 @@ _begin_fstest quick auto prealloc rw
 _cleanup()
 {
        cd /
-       _destroy_loop_device $LOOP_DEV
+       [ -n "$loop_dev" ] &&_destroy_loop_device $loop_dev
        rm -f $tmp.* $LOOP_FILE
 }
 
@@ -45,10 +45,10 @@ LOOP_FILE=$TEST_DIR/$seq.img
 LOOP_MNT=$TEST_DIR/$seq.mnt
 mkdir -p $LOOP_MNT
 $XFS_IO_PROG -ft -c "truncate 1t" $LOOP_FILE >> $seqres.full
-LOOP_DEV=`_create_loop_device $LOOP_FILE`
+loop_dev=`_create_loop_device $LOOP_FILE`
 
-_mkfs_dev -d size=260g,agcount=2 $LOOP_DEV
-_mount $LOOP_DEV $LOOP_MNT
+_mkfs_dev -d size=260g,agcount=2 $loop_dev
+_mount $loop_dev $LOOP_MNT
 
 BLOCK_SIZE=$(_get_file_block_size $LOOP_MNT)
 
@@ -59,11 +59,11 @@ $XFS_IO_PROG -ft \
        -c "falloc 0 $(($BLOCK_SIZE * 2097152))" \
        $LOOP_MNT/foo >> $seqres.full
 
-umount $LOOP_MNT
-_check_xfs_filesystem $LOOP_DEV none none
+_unmount $LOOP_MNT
+_check_xfs_filesystem $loop_dev none none
 
-_mkfs_dev -f $LOOP_DEV
-_mount $LOOP_DEV $LOOP_MNT
+_mkfs_dev -f $loop_dev
+_mount $loop_dev $LOOP_MNT
 
 # check we trim both ends of the extent approproiately; this will fail
 # on 1k block size filesystems without the correct fixes in place.
@@ -73,7 +73,10 @@ $XFS_IO_PROG -ft \
        $LOOP_MNT/foo >> $seqres.full
 
 _unmount $LOOP_MNT
-_check_xfs_filesystem $LOOP_DEV none none
+_check_xfs_filesystem $loop_dev none none
+
+_destroy_loop_device $loop_dev
+unset loop_dev
 
 # success, all done
 echo "Silence is golden"
index 6b325e05f6433a6b364e2bea338bb3ff9a5fd438..0d3c2eb23e51cee52d190bc48fb0c508941b3416 100755 (executable)
@@ -17,7 +17,7 @@ _cleanup()
        cd /
        rm -f $tmp.*
        _unmount $LOOP_MNT 2>/dev/null
-       [ -n "$LOOP_DEV" ] && _destroy_loop_device $LOOP_DEV 2>/dev/null
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev 2>/dev/null
        # try to keep the image file if test fails
        [ $status -eq 0 ] && rm -f $LOOP_IMG
        rmdir $LOOP_MNT
@@ -55,7 +55,7 @@ _grow_loop()
        agsize=$5
 
        $XFS_IO_PROG -f -c "truncate $original" $LOOP_IMG
-       LOOP_DEV=`_create_loop_device $LOOP_IMG`
+       loop_dev=`_create_loop_device $LOOP_IMG`
 
        dparam=""
        if [ -n "$agsize" ]; then
@@ -67,15 +67,15 @@ _grow_loop()
        echo
 
        echo "*** mkfs loop file (size=$original)"
-       $MKFS_XFS_PROG -b size=$bsize $dparam $LOOP_DEV | \
+       $MKFS_XFS_PROG -b size=$bsize $dparam $loop_dev | \
                _filter_mkfs 2>/dev/null
 
        echo "*** extend loop file"
-       _destroy_loop_device $LOOP_DEV
+       _destroy_loop_device $loop_dev
        $XFS_IO_PROG -c "pwrite $new_size $bsize" $LOOP_IMG | _filter_io
-       LOOP_DEV=`_create_loop_device $LOOP_IMG`
+       loop_dev=`_create_loop_device $LOOP_IMG`
        echo "*** mount loop filesystem"
-       _mount -t xfs $LOOP_DEV $LOOP_MNT
+       _mount $loop_dev $LOOP_MNT
 
        echo "*** grow loop filesystem"
        $XFS_GROWFS_PROG $LOOP_MNT 2>&1 |  _filter_growfs 2>&1
@@ -87,9 +87,11 @@ _grow_loop()
        if [ "$check" -gt "0" ]
        then
                echo "*** check"
-               _check_xfs_filesystem $LOOP_IMG none none
+               _check_xfs_filesystem $loop_dev none none
        fi
 
+       _destroy_loop_device $loop_dev
+       unset loop_dev
        rm -f $LOOP_IMG
 }
 
index c42c9b119a76ac36bc6369b5ff9825bf95a16e32..4d2f7a80855cbbdda2676372be9b6387f8169b34 100755 (executable)
@@ -15,7 +15,7 @@ _cleanup()
 {
        cd /
        _unmount $mntpt > /dev/null 2>&1
-       _destroy_loop_device $loopdev > /dev/null 2>&1
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
        rm -r -f $tmp.*
 }
 
@@ -48,12 +48,12 @@ rm -f $imgfile $imgfile.old
 # even when security xattrs are present so we are always doing name matches on
 # lookup and not name hash compares as leaf/node forms will do.
 $XFS_IO_PROG -f -c 'truncate 40m' $imgfile
-loopdev=$(_create_loop_device $imgfile)
-MKFS_OPTIONS="-m crc=0 -i size=512" _mkfs_dev $loopdev >> $seqres.full
+loop_dev=$(_create_loop_device $imgfile)
+MKFS_OPTIONS="-m crc=0 -i size=512" _mkfs_dev $loop_dev >> $seqres.full
 
 # Mount image file
 mkdir -p $mntpt
-_mount $loopdev $mntpt
+_mount $loop_dev $mntpt
 
 echo "creating entries" >> $seqres.full
 
@@ -91,7 +91,8 @@ cat $tmp.log | _filter_test_dir
 
 # Corrupt the entries
 _unmount $mntpt
-_destroy_loop_device $loopdev
+_destroy_loop_device $loop_dev
+unset loop_dev
 cp $imgfile $imgfile.old
 sed -b \
        -e "s/$nullstr/too_many\x00beans/g" \
@@ -99,8 +100,9 @@ sed -b \
        -i $imgfile
 test "$(md5sum < $imgfile)" != "$(md5sum < $imgfile.old)" ||
        _fail "sed failed to change the image file?"
-loopdev=$(_create_loop_device $imgfile)
-_mount $loopdev $mntpt
+
+loop_dev=$(_create_loop_device $imgfile)
+_mount $loop_dev $mntpt
 
 # Try to access the corrupt metadata
 echo "++ ACCESSING BAD METADATA" | tee -a $seqres.full
@@ -111,7 +113,7 @@ cat $tmp.log | _filter_test_dir | sed -e '/Could not list/d'
 echo "does scrub complain?" >> $seqres.full
 
 # Does scrub complain about this?
-if _supports_xfs_scrub $mntpt $loopdev; then
+if _supports_xfs_scrub $mntpt $loop_dev; then
        $XFS_SCRUB_PROG -n $mntpt >> $seqres.full 2>&1
        res=$?
        test $((res & 1)) -eq 0 && \
@@ -122,11 +124,14 @@ echo "does repair complain?" >> $seqres.full
 
 # Does repair complain about this?
 _unmount $mntpt
-$XFS_REPAIR_PROG -n $loopdev >> $seqres.full 2>&1
+$XFS_REPAIR_PROG -n $loop_dev >> $seqres.full 2>&1
 res=$?
 test $res -eq 1 || \
        echo "repair failed to report corruption ($res)"
 
+_destroy_loop_device $loop_dev
+unset loop_dev
+
 # success, all done
 status=0
 exit
index f2187109b4876cf93bd3dde0cf620e7ef04359bc..9a96f82ede17610c46359a82439f9c09f3725cb0 100755 (executable)
@@ -84,6 +84,10 @@ $XFS_GROWFS_PROG -D 16384 $loop_symlink > /dev/null
 echo "=== xfs_growfs - check device node ==="
 $XFS_GROWFS_PROG -D 20480 $loop_dev > /dev/null
 
+_unmount $mntdir
+_destroy_loop_device $loop_dev
+unset loop_dev
+
 # success, all done
 status=0
 exit
index 6b8b2eb2210d8606086d329661fed578bf1435b6..091c11d0864247579fa196f72e51bcbd95cdc168 100755 (executable)
@@ -15,6 +15,7 @@ _begin_fstest log metadata auto quick
 _cleanup()
 {
        _unmount $LOOP_MNT > /dev/null 2>&1
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
        cd /
        rm -f $tmp.*
 }
@@ -24,7 +25,7 @@ _scratch_mkfs_xfs >/dev/null 2>&1
 _scratch_mount
 
 _require_loop
-LOOP_DEV=$SCRATCH_MNT/test_fs
+LOOP_IMG=$SCRATCH_MNT/test_fs
 LOOP_MNT=$SCRATCH_MNT/test_fs_dir
 
 loop_mkfs_opts=
@@ -55,22 +56,26 @@ _do_mkfs()
        for i in $*; do
                echo -n "fssize=${i}g "
                $MKFS_XFS_PROG -f -b size=4096 -l version=2 \
-                       -d name=$LOOP_DEV,size=${i}g $loop_mkfs_opts |grep log
-               _mount -o loop -t xfs $LOOP_DEV $LOOP_MNT
+                       -d size=${i}g $loop_mkfs_opts $loop_dev |grep log
+               _mount $loop_dev $LOOP_MNT
                echo "test write" > $LOOP_MNT/test
                _unmount $LOOP_MNT > /dev/null 2>&1
        done
 }
 # make large holey file
-$XFS_IO_PROG -f -c "truncate 256g" $LOOP_DEV
+$XFS_IO_PROG -f -c "truncate 256g" $LOOP_IMG
 
-choose_golden_output $0 $LOOP_DEV
+choose_golden_output $0 $LOOP_IMG
 
 #make loopback mount dir
 mkdir $LOOP_MNT
 
+loop_dev=$(_create_loop_device $LOOP_IMG)
+
 # walk over standard sizes (up to 256GB)
 _do_mkfs 1 2 4 8 16 32 64 128 256
 
+_destroy_loop_device $loop_dev
+unset loop_dev
 status=0
 exit
index b2eb34490ee1b58d077acb966bf9874d3d8dfdfb..dae6ce55f475dfd399fb697281233a707e5b6c6a 100755 (executable)
@@ -12,6 +12,12 @@ _begin_fstest log metadata auto
 # Import common functions.
 . ./common/filter
 
+_cleanup()
+{
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
+       cd /
+       rm -f $tmp.*
+}
 
 _require_scratch
 _scratch_mkfs_xfs >/dev/null 2>&1
@@ -20,7 +26,7 @@ _scratch_mount
 _require_fs_space $SCRATCH_MNT 2202000
 
 _require_loop
-LOOP_DEV=$SCRATCH_MNT/test_fs
+LOOP_IMG=$SCRATCH_MNT/test_fs
 LOOP_MNT=$SCRATCH_MNT/test_fs_dir
 
 _do_mkfs()
@@ -28,28 +34,30 @@ _do_mkfs()
        for i in $*; do
                echo -n "fssize=${i}g "
                $MKFS_XFS_PROG -f -b size=4096 -l version=2 \
-                       -d name=$LOOP_DEV,size=${i}g |grep log
-               _mount -o loop -t xfs $LOOP_DEV $LOOP_MNT
+                       -d size=${i}g $loop_dev |grep log
+               _mount $loop_dev $LOOP_MNT
                echo "test write" > $LOOP_MNT/test
                _unmount $LOOP_MNT > /dev/null 2>&1
 
                # punch out the previous blocks so that we keep the amount of
                # disk space the test requires down to a minimum.
-               $XFS_IO_PROG -f -c "unresvsp 0 16383g" $LOOP_DEV
+               $XFS_IO_PROG -f -c "unresvsp 0 16383g" $LOOP_IMG
        done
 }
 # make large holey file
-$XFS_IO_PROG -f -c "truncate 16383g" $LOOP_DEV
+$XFS_IO_PROG -f -c "truncate 16383g" $LOOP_IMG
 
 #make loopback mount dir
 mkdir $LOOP_MNT
 
 # test if large logs are supported
-$MKFS_XFS_PROG -f -l size=256m -d name=$LOOP_DEV,size=10g > /dev/null 2>&1
+$MKFS_XFS_PROG -f -l size=256m -d name=$LOOP_IMG,size=10g > /dev/null 2>&1
 if [ $? -ne 0 ]; then
        _notrun "large log sizes not supported by mkfs"
 fi
 
+loop_dev=$(_create_loop_device $LOOP_IMG)
+
 #
 # walk over "new" sizes supported by recent xfsprogs.
 # Note that the last test is for 16TB-1GB as 32bit platforms only support
@@ -57,5 +65,7 @@ fi
 #
 _do_mkfs 512 1024 2048 4096 8192 16383
 
+_destroy_loop_device $loop_dev
+unset loop_dev
 status=0
 exit
index 4e3473ebcef69c0c4e2d0d1cc6b201c4fda4fcb5..2554e1e91c4c6f0366467b0544d9f607e42e08e7 100755 (executable)
@@ -14,7 +14,8 @@ _cleanup()
 {
        cd /
        _unmount $LOOP_MNT 2>/dev/null
-       rm -f $LOOP_DEV
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
+       rm -f $LOOP_IMG
        rmdir $LOOP_MNT
        rm -f $tmp.*
 }
@@ -26,7 +27,7 @@ _require_test
 _require_loop
 _require_xfs_io_command "falloc"
 
-LOOP_DEV=$TEST_DIR/$seq.fs
+LOOP_IMG=$TEST_DIR/$seq.fs
 LOOP_MNT=$TEST_DIR/$seq.mnt
 
 _filter_io()
@@ -45,7 +46,7 @@ _test_loop()
        agsize=$2
        fsize=$3
 
-       dparam="file,name=$LOOP_DEV,size=$size"
+       dparam="file,name=$LOOP_IMG,size=$size"
        if [ -n "$agsize" ]; then
                dparam="$dparam,agsize=$agsize"
        fi
@@ -55,7 +56,8 @@ _test_loop()
                | _filter_mkfs 2>/dev/null
 
        echo "*** mount loop filesystem"
-       _mount -t xfs -o loop $LOOP_DEV $LOOP_MNT
+       loop_dev=$(_create_loop_device $LOOP_IMG)
+       mount $loop_dev $LOOP_MNT
 
        echo "*** preallocate large file"
        $XFS_IO_PROG -f -c "resvsp 0 $fsize" $LOOP_MNT/foo | _filter_io
@@ -64,7 +66,9 @@ _test_loop()
        _unmount $LOOP_MNT > /dev/null 2>&1
 
        echo "*** check loop filesystem"
-        _check_xfs_filesystem $LOOP_DEV none none
+       _check_xfs_filesystem $loop_dev none none
+       _destroy_loop_device $loop_dev
+       unset loop_dev
 }
 
 _test_loop 50g 16m 40G
index 0c8d6eb5673b7b7e96c68c97f948c2e8bcc974e0..c2d26381a91c029325b2aefba3f4468223b901e7 100755 (executable)
@@ -12,7 +12,10 @@ _begin_fstest auto quick
 # Override the default cleanup function.
 _cleanup()
 {
-    rm -f "$testfile"
+       [ -n "$loop_dev" ] && _destroy_loop_device $testfile
+       rm -f "$testfile"
+       cd /
+       rm -f $tmp.*
 }
 
 # Import common functions.
@@ -45,13 +48,13 @@ for del in $sizes_to_check; do
                rm -f "$testfile"
                dd if=/dev/zero "of=$testfile" bs=1 count=0 seek=$ddseek \
                        >/dev/null 2>&1 || echo "dd failed"
-               lofile=$(losetup -f)
-               losetup $lofile "$testfile"
-               $MKFS_XFS_PROG -l size=32m -b size=$bs $lofile |  _filter_mkfs \
+               loop_dev=$(_create_loop_device $testfile)
+               $MKFS_XFS_PROG -l size=32m -b size=$bs $loop_dev |  _filter_mkfs \
                        >/dev/null 2> $tmp.mkfs || echo "mkfs failed!"
                . $tmp.mkfs
                sync
-               losetup -d $lofile
+               _destroy_loop_device $loop_dev
+               unset loop_dev
        done
 done
 
index 5895e6e2df2921dffeb785e11eba63788cd35657..d3be3ced68a10c601c234d77785c1f3f7bf984b3 100755 (executable)
@@ -15,12 +15,8 @@ _cleanup()
        cd /
        rm -f $tmp.*
        _unmount $LOOP_MNT 2>/dev/null
-       if [ -n "$LOOP_DEV" ];then
-               _destroy_loop_device $LOOP_DEV 2>/dev/null
-       fi
-       if [ -n "$LOOP_SPARE_DEV" ];then
-               _destroy_loop_device $LOOP_SPARE_DEV 2>/dev/null
-       fi
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
+       [ -n "$loop_spare_dev" ] && _destroy_loop_device $loop_spare_dev
        rm -f $LOOP_IMG
        rm -f $LOOP_SPARE_IMG
        rmdir $LOOP_MNT
@@ -42,11 +38,11 @@ LOOP_MNT=$TEST_DIR/$seq.mnt
 
 echo "** create loop device"
 $XFS_IO_PROG -f -c "truncate 32g" $LOOP_IMG
-LOOP_DEV=`_create_loop_device $LOOP_IMG`
+loop_dev=`_create_loop_device $LOOP_IMG`
 
 echo "** create loop log device"
 $XFS_IO_PROG -f -c "truncate 1g" $LOOP_SPARE_IMG
-LOOP_SPARE_DEV=`_create_loop_device $LOOP_SPARE_IMG`
+loop_spare_dev=`_create_loop_device $LOOP_SPARE_IMG`
 
 echo "** create loop mount point"
 rmdir $LOOP_MNT 2>/dev/null
@@ -55,8 +51,8 @@ mkdir -p $LOOP_MNT || _fail "cannot create loopback mount point"
 filter_loop()
 {
        sed -e "s,\B$LOOP_MNT,LOOP_MNT,g" \
-           -e "s,\B$LOOP_DEV,LOOP_DEV,g" \
-           -e "s,\B$LOOP_SPARE_DEV,LOOP_SPARE_DEV,g"
+           -e "s,\B$loop_dev,LOOP_DEV,g" \
+           -e "s,\B$loop_spare_dev,LOOP_SPARE_DEV,g"
 }
 
 filter_xfs_opt()
@@ -69,22 +65,22 @@ MKFS_OPTIONS=""
 do_mkfs()
 {
        echo "FORMAT: $@" | filter_loop | tee -a $seqres.full
-       $MKFS_XFS_PROG -f $* $LOOP_DEV | _filter_mkfs >>$seqres.full 2>$tmp.mkfs
+       $MKFS_XFS_PROG -f $* $loop_dev | _filter_mkfs >>$seqres.full 2>$tmp.mkfs
        if [ "${PIPESTATUS[0]}" -ne 0 ]; then
-               _fail "Fails on _mkfs_dev $* $LOOP_DEV"
+               _fail "Fails on _mkfs_dev $* $loop_dev"
        fi
        . $tmp.mkfs
 }
 
 is_dev_mounted()
 {
-       findmnt --source $LOOP_DEV >/dev/null
+       findmnt --source $loop_dev >/dev/null
        return $?
 }
 
 get_mount_info()
 {
-       findmnt --source $LOOP_DEV -o OPTIONS -n
+       findmnt --source $loop_dev -o OPTIONS -n
 }
 
 force_unmount()
@@ -103,29 +99,29 @@ _do_test()
        local info
 
        # mount test
-       _mount $LOOP_DEV $LOOP_MNT $opts 2>>$seqres.full
+       _mount $loop_dev $LOOP_MNT $opts 2>>$seqres.full
        rc=$?
        if [ $rc -eq 0 ];then
                if [ "${mounted}" = "fail" ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: expect mount to fail, but it succeeded"
                        return 1
                fi
                is_dev_mounted
                if [ $? -ne 0 ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: fs not mounted even mount return 0"
                        return 1
                fi
        else
                if [ "${mounted}" = "pass" ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: expect mount to succeed, but it failed"
                        return 1
                fi
                is_dev_mounted
                if [ $? -eq 0 ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: fs is mounted even mount return non-zero"
                        return 1
                fi
@@ -141,13 +137,13 @@ _do_test()
        rc=$?
        if [ $rc -eq 0 ];then
                if [ "$found" != "true" ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: expected to find \"$key\" in mount info \"$info\""
                        return 1
                fi
        else
                if [ "$found" != "false" ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: did not expect to find \"$key\" in \"$info\""
                        return 1
                fi
@@ -253,9 +249,9 @@ do_test "-o logbsize=512k" fail
 # Test logdev
 do_mkfs
 do_test "" pass "logdev" "false"
-do_test "-o logdev=$LOOP_SPARE_DEV" fail
-do_mkfs -l logdev=$LOOP_SPARE_DEV
-do_test "-o logdev=$LOOP_SPARE_DEV" pass "logdev=$LOOP_SPARE_DEV" "true"
+do_test "-o logdev=$loop_spare_dev" fail
+do_mkfs -l logdev=$loop_spare_dev
+do_test "-o logdev=$loop_spare_dev" pass "logdev=$loop_spare_dev" "true"
 do_test "" fail
 
 # Test noalign
index 13982c440b077498cd24cbc8503630afdd6efd3d..c92c621a2fd45b081d1157aaf574c66b53621e73 100755 (executable)
@@ -21,7 +21,7 @@ _cleanup()
 {
        cd /
        _scratch_unmount >> $seqres.full 2>&1
-       test -e "$rtdev" && losetup -d $rtdev >> $seqres.full 2>&1
+       [ -n "$rt_loop_dev" ] && _destroy_loop_device $rt_loop_dev
        rm -f $tmp.* $TEST_DIR/$seq.rtvol
 }
 
@@ -35,7 +35,7 @@ _require_no_large_scratch_dev
 
 echo "Create fake rt volume"
 truncate -s 400m $TEST_DIR/$seq.rtvol
-rtdev=$(_create_loop_device $TEST_DIR/$seq.rtvol)
+rt_loop_dev=$(_create_loop_device $TEST_DIR/$seq.rtvol)
 
 echo "Format and mount 100m rt volume"
 export USE_EXTERNAL=yes
@@ -69,6 +69,10 @@ cp -p $testdir/original $testdir/copy3
 echo "Check filesystem"
 _check_scratch_fs
 
+_scratch_unmount
+_destroy_loop_device $rt_loop_dev
+unset rt_loop_dev
+
 # success, all done
 status=0
 exit
index 6ca9a23702e9d81ebfd1855a0f9f389710c40bc0..a1efbbd27b96ce21295ba73409248e2592f9ba43 100755 (executable)
@@ -15,7 +15,7 @@ _cleanup()
 {
        cd /
        _scratch_unmount >> $seqres.full 2>&1
-       test -e "$rtdev" && losetup -d $rtdev >> $seqres.full 2>&1
+       [ -n "$rt_loop_dev" ] && _destroy_loop_device $rt_loop_dev
        rm -f $tmp.* $TEST_DIR/$seq.rtvol
 }
 
@@ -155,11 +155,11 @@ test_ops() {
 
 echo "Create fake rt volume"
 $XFS_IO_PROG -f -c "truncate 400m" $TEST_DIR/$seq.rtvol
-rtdev=$(_create_loop_device $TEST_DIR/$seq.rtvol)
+rt_loop_dev=$(_create_loop_device $TEST_DIR/$seq.rtvol)
 
 echo "Make sure synth rt volume works"
 export USE_EXTERNAL=yes
-export SCRATCH_RTDEV=$rtdev
+export SCRATCH_RTDEV=$rt_loop_dev
 _scratch_mkfs > $seqres.full
 _try_scratch_mount || \
        _notrun "Could not mount with synthetic rt volume"
@@ -170,6 +170,10 @@ test_ops 262144
 # not a power of two
 test_ops 327680
 
+_scratch_unmount
+_destroy_loop_device $rt_loop_dev
+unset rt_loop_dev
+
 # success, all done
 status=0
 exit
index 8a182bd6a3928ab788724ea06166f9ae2eb27062..d0d0e2665070f821f2f1a174c89e082aa6b10b47 100755 (executable)
@@ -15,7 +15,7 @@ _cleanup()
 {
        cd /
        _scratch_unmount >> $seqres.full 2>&1
-       test -e "$rtdev" && losetup -d $rtdev >> $seqres.full 2>&1
+       [ -n "$rt_loop_dev" ] && _destroy_loop_device $rt_loop_dev
        rm -f $tmp.* $TEST_DIR/$seq.rtvol
 }
 
@@ -52,12 +52,12 @@ fi
 
 rtdevsz=$((nr_bits * rtextsz))
 truncate -s $rtdevsz $TEST_DIR/$seq.rtvol
-rtdev=$(_create_loop_device $TEST_DIR/$seq.rtvol)
+rt_loop_dev=$(_create_loop_device $TEST_DIR/$seq.rtvol)
 
 echo "Format and mount rt volume"
 
 export USE_EXTERNAL=yes
-export SCRATCH_RTDEV=$rtdev
+export SCRATCH_RTDEV=$rt_loop_dev
 _scratch_mkfs -d size=$((1024 * 1024 * 1024)) \
              -r size=${rtextsz},extsize=${rtextsz} >> $seqres.full
 _try_scratch_mount || _notrun "Couldn't mount fs with synthetic rt volume"
@@ -116,8 +116,9 @@ done
 echo "Check filesystem"
 _check_scratch_fs
 
-losetup -d $rtdev
-rm -f $TEST_DIR/$seq.rtvol
+_scratch_unmount
+_destroy_loop_device $rt_loop_dev
+unset rt_loop_dev
 
 # success, all done
 status=0
index f958bddd8f171c7d0410235b463661f4568e42fc..b537ea145f3d6185abd69bc77cce714a2e4a06a5 100755 (executable)
@@ -13,10 +13,8 @@ _begin_fstest auto quick growfs
 
 _cleanup()
 {
-       local dev
        _unmount $LOOP_MNT 2>/dev/null
-       dev=$(losetup -j testfile | cut -d: -f1)
-       losetup -d $dev 2>/dev/null
+       [ -n "$loop_dev" ] && _destroy_loop_device $loop_dev
        rm -rf $LOOP_IMG $LOOP_MNT
        cd /
        rm -f $tmp.*
@@ -40,7 +38,9 @@ $MKFS_XFS_PROG -f $LOOP_IMG >$seqres.full
 # Extend by just 8K, expected to start with the last full-size AG ends of
 # above 1G block device.
 $XFS_IO_PROG -f -c "truncate 1073750016" $LOOP_IMG
-_mount -oloop $LOOP_IMG $LOOP_MNT
+
+loop_dev=$(_create_loop_device $LOOP_IMG)
+_mount $loop_dev $LOOP_MNT
 # A known bug shows "XFS_IOC_FSGROWFSDATA xfsctl failed: No space left on
 # device" at here, refer to _fixed_by_kernel_commit above
 $XFS_GROWFS_PROG $LOOP_MNT >$seqres.full
@@ -48,6 +48,10 @@ if [ $? -ne 0 ];then
        echo "xfs_growfs fails!"
 fi
 
+_unmount $LOOP_MNT
+_destroy_loop_device $loop_dev
+unset loop_dev
+
 echo "Silence is golden"
 # success, all done
 status=0
index 6ba3d87bf6e9f866004e6f0938f3c825ad2165a4..c034ef60d28bad2d521a5400434c67d93385608e 100755 (executable)
@@ -15,14 +15,8 @@ _cleanup()
        cd /
        rm -f $tmp.*
        _unmount $LOOP_MNT 2>/dev/null
-       if [ -n "$LOOP_DEV" ];then
-               _destroy_loop_device $LOOP_DEV 2>/dev/null
-       fi
-       if [ -n "$LOOP_SPARE_DEV" ];then
-               _destroy_loop_device $LOOP_SPARE_DEV 2>/dev/null
-       fi
+       [ -n "$loop_dev" ] &&_destroy_loop_device $loop_dev
        rm -f $LOOP_IMG
-       rm -f $LOOP_SPARE_IMG
        rmdir $LOOP_MNT
 }
 
@@ -38,16 +32,11 @@ _require_loop
 _require_xfs_io_command "falloc"
 
 LOOP_IMG=$TEST_DIR/$seq.dev
-LOOP_SPARE_IMG=$TEST_DIR/$seq.logdev
 LOOP_MNT=$TEST_DIR/$seq.mnt
 
 echo "** create loop device"
 $XFS_IO_PROG -f -c "truncate 32g" $LOOP_IMG
-LOOP_DEV=`_create_loop_device $LOOP_IMG`
-
-echo "** create loop log device"
-$XFS_IO_PROG -f -c "truncate 1g" $LOOP_SPARE_IMG
-LOOP_SPARE_DEV=`_create_loop_device $LOOP_SPARE_IMG`
+loop_dev=`_create_loop_device $LOOP_IMG`
 
 echo "** create loop mount point"
 rmdir $LOOP_MNT 2>/dev/null
@@ -56,8 +45,7 @@ mkdir -p $LOOP_MNT || _fail "cannot create loopback mount point"
 filter_loop()
 {
        sed -e "s,\B$LOOP_MNT,LOOP_MNT,g" \
-           -e "s,\B$LOOP_DEV,LOOP_DEV,g" \
-           -e "s,\B$LOOP_SPARE_DEV,LOOP_SPARE_DEV,g"
+           -e "s,\B$loop_dev,LOOP_DEV,g"
 }
 
 filter_xfs_opt()
@@ -70,22 +58,22 @@ MKFS_OPTIONS=""
 do_mkfs()
 {
        echo "FORMAT: $@" | filter_loop | tee -a $seqres.full
-       $MKFS_XFS_PROG -f $* $LOOP_DEV | _filter_mkfs >>$seqres.full 2>$tmp.mkfs
+       $MKFS_XFS_PROG -f $* $loop_dev | _filter_mkfs >>$seqres.full 2>$tmp.mkfs
        if [ "${PIPESTATUS[0]}" -ne 0 ]; then
-               _fail "Fails on _mkfs_dev $* $LOOP_DEV"
+               _fail "Fails on _mkfs_dev $* $loop_dev"
        fi
        . $tmp.mkfs
 }
 
 is_dev_mounted()
 {
-       findmnt --source $LOOP_DEV >/dev/null
+       findmnt --source $loop_dev >/dev/null
        return $?
 }
 
 get_mount_info()
 {
-       findmnt --source $LOOP_DEV -o OPTIONS -n
+       findmnt --source $loop_dev -o OPTIONS -n
 }
 
 force_unmount()
@@ -104,29 +92,29 @@ _do_test()
        local info
 
        # mount test
-       _mount $LOOP_DEV $LOOP_MNT $opts 2>>$seqres.full
+       _mount $loop_dev $LOOP_MNT $opts 2>>$seqres.full
        rc=$?
        if [ $rc -eq 0 ];then
                if [ "${mounted}" = "fail" ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: expect mount to fail, but it succeeded"
                        return 1
                fi
                is_dev_mounted
                if [ $? -ne 0 ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: fs not mounted even mount return 0"
                        return 1
                fi
        else
                if [ "${mounted}" = "pass" ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: expect mount to succeed, but it failed"
                        return 1
                fi
                is_dev_mounted
                if [ $? -eq 0 ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: fs is mounted even mount return non-zero"
                        return 1
                fi
@@ -142,13 +130,13 @@ _do_test()
        rc=$?
        if [ $rc -eq 0 ];then
                if [ "$found" != "true" ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: expected to find \"$key\" in mount info \"$info\""
                        return 1
                fi
        else
                if [ "$found" != "false" ];then
-                       echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
+                       echo "[FAILED]: mount $loop_dev $LOOP_MNT $opts"
                        echo "ERROR: did not expect to find \"$key\" in \"$info\""
                        return 1
                fi
index 1624617ee4bb253d20a3b33be744161cb31bb5ff..2a693c53c5842c985710461923b02b5e4ddaf833 100644 (file)
@@ -1,6 +1,5 @@
 QA output created by 613
 ** create loop device
-** create loop log device
 ** create loop mount point
 ** start xfs mount testing ...
 FORMAT: -m crc=0