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 _begin_fstest auto quick volume
20 # Override the default cleanup function.
25 if [ ! -z "$loop_mnt" ]; then
26 $UMOUNT_PROG $loop_mnt
29 [ ! -z "$loop_mnt1" ] && rm -rf $loop_mnt1
30 [ ! -z "$fs_img1" ] && rm -rf $fs_img1
31 [ ! -z "$fs_img2" ] && rm -rf $fs_img2
32 [ ! -z "$loop_dev" ] && _destroy_loop_device $loop_dev
36 # Import common functions.
40 # real QA test starts here
45 _require_btrfs_forget_or_module_loadable
47 loop_mnt=$TEST_DIR/$seq.mnt
48 loop_mnt1=$TEST_DIR/$seq.mnt1
49 fs_img1=$TEST_DIR/$seq.img1
50 fs_img2=$TEST_DIR/$seq.img2
55 $XFS_IO_PROG -f -c "truncate 256m" $fs_img1 >>$seqres.full 2>&1
57 _mkfs_dev $fs_img1 >>$seqres.full 2>&1
60 # Normal single device case, should pass just fine
61 _mount -o loop $fs_img1 $loop_mnt > /dev/null 2>&1 || \
62 _fail "Couldn't do initial mount"
63 $UMOUNT_PROG $loop_mnt
65 _btrfs_forget_or_module_reload
67 # Now mount the new version again to get the higher generation cached, umount
68 # and try to mount the old version. Mount the new version again just for good
70 loop_dev=`_create_loop_device $fs_img1`
72 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
73 _fail "Failed to mount the second time"
74 $UMOUNT_PROG $loop_mnt
76 _mount -o loop $fs_img2 $loop_mnt > /dev/null 2>&1 || \
77 _fail "We couldn't mount the old generation"
78 $UMOUNT_PROG $loop_mnt
80 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
81 _fail "Failed to mount the second time"
82 $UMOUNT_PROG $loop_mnt
84 # Now we definitely can't mount them at the same time, because we're still tied
85 # to the limitation of one fs_devices per fsid.
86 _btrfs_forget_or_module_reload
88 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
89 _fail "Failed to mount the third time"
90 _mount -o loop $fs_img2 $loop_mnt1 > /dev/null 2>&1 && \
91 _fail "We were allowed to mount when we should have failed"
95 echo "Silence is golden"