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
40 # get standard environment, filters and checks
44 # remove previous $seqres.full before test
47 # real QA test starts here
52 _require_btrfs_forget_or_module_loadable
54 loop_mnt=$TEST_DIR/$seq.mnt
55 loop_mnt1=$TEST_DIR/$seq.mnt1
56 fs_img1=$TEST_DIR/$seq.img1
57 fs_img2=$TEST_DIR/$seq.img2
62 $XFS_IO_PROG -f -c "truncate 256m" $fs_img1 >>$seqres.full 2>&1
64 _mkfs_dev $fs_img1 >>$seqres.full 2>&1
67 # Normal single device case, should pass just fine
68 _mount -o loop $fs_img1 $loop_mnt > /dev/null 2>&1 || \
69 _fail "Couldn't do initial mount"
70 $UMOUNT_PROG $loop_mnt
72 _btrfs_forget_or_module_reload
74 # Now mount the new version again to get the higher generation cached, umount
75 # and try to mount the old version. Mount the new version again just for good
77 loop_dev=`_create_loop_device $fs_img1`
79 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
80 _fail "Failed to mount the second time"
81 $UMOUNT_PROG $loop_mnt
83 _mount -o loop $fs_img2 $loop_mnt > /dev/null 2>&1 || \
84 _fail "We couldn't mount the old generation"
85 $UMOUNT_PROG $loop_mnt
87 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
88 _fail "Failed to mount the second time"
89 $UMOUNT_PROG $loop_mnt
91 # Now we definitely can't mount them at the same time, because we're still tied
92 # to the limitation of one fs_devices per fsid.
93 _btrfs_forget_or_module_reload
95 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
96 _fail "Failed to mount the third time"
97 _mount -o loop $fs_img2 $loop_mnt1 > /dev/null 2>&1 && \
98 _fail "We were allowed to mount when we should have failed"
101 echo "Silence is golden"