2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Facebook. All Rights Reserved.
7 # Test a variety of stale device usecases. We cache the device and generation
8 # to make sure we do not allow stale devices, which can end up with some wonky
9 # behavior for loop back devices. This was changed with
11 # btrfs: allow single disk devices to mount with older generations
13 # But I've added a few other test cases so it's clear what we expect to happen
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
30 if [ ! -z "$loop_mnt" ]; then
31 $UMOUNT_PROG $loop_mnt
34 [ ! -z "$loop_mnt1" ] && rm -rf $loop_mnt1
35 [ ! -z "$fs_img1" ] && rm -rf $fs_img1
36 [ ! -z "$fs_img2" ] && rm -rf $fs_img2
37 [ ! -z "$loop_dev" ] && _destroy_loop_device $loop_dev
41 # get standard environment, filters and checks
45 # remove previous $seqres.full before test
48 # real QA test starts here
53 _require_btrfs_forget_or_module_loadable
55 loop_mnt=$TEST_DIR/$seq.mnt
56 loop_mnt1=$TEST_DIR/$seq.mnt1
57 fs_img1=$TEST_DIR/$seq.img1
58 fs_img2=$TEST_DIR/$seq.img2
63 $XFS_IO_PROG -f -c "truncate 256m" $fs_img1 >>$seqres.full 2>&1
65 _mkfs_dev $fs_img1 >>$seqres.full 2>&1
68 # Normal single device case, should pass just fine
69 _mount -o loop $fs_img1 $loop_mnt > /dev/null 2>&1 || \
70 _fail "Couldn't do initial mount"
71 $UMOUNT_PROG $loop_mnt
73 _btrfs_forget_or_module_reload
75 # Now mount the new version again to get the higher generation cached, umount
76 # and try to mount the old version. Mount the new version again just for good
78 loop_dev=`_create_loop_device $fs_img1`
80 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
81 _fail "Failed to mount the second time"
82 $UMOUNT_PROG $loop_mnt
84 _mount -o loop $fs_img2 $loop_mnt > /dev/null 2>&1 || \
85 _fail "We couldn't mount the old generation"
86 $UMOUNT_PROG $loop_mnt
88 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
89 _fail "Failed to mount the second time"
90 $UMOUNT_PROG $loop_mnt
92 # Now we definitely can't mount them at the same time, because we're still tied
93 # to the limitation of one fs_devices per fsid.
94 _btrfs_forget_or_module_reload
96 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
97 _fail "Failed to mount the third time"
98 _mount -o loop $fs_img2 $loop_mnt1 > /dev/null 2>&1 && \
99 _fail "We were allowed to mount when we should have failed"
101 _btrfs_rescan_devices
103 echo "Silence is golden"