btrfs: source common/module when requiring module reload
[xfstests-dev.git] / tests / btrfs / 219
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 219
6 #
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
10 #
11 #   btrfs: allow single disk devices to mount with older generations
12 #
13 # But I've added a few other test cases so it's clear what we expect to happen
14 # currently.
15 #
16
17 . ./common/preamble
18 _begin_fstest auto quick volume
19
20 # Override the default cleanup function.
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25         if [ ! -z "$loop_mnt" ]; then
26                 $UMOUNT_PROG $loop_mnt
27                 rm -rf $loop_mnt
28         fi
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
33         _btrfs_rescan_devices
34 }
35
36 # Import common functions.
37 . ./common/filter
38 . ./common/module
39
40 # real QA test starts here
41
42 _supported_fs btrfs
43 _require_test
44 _require_loop
45 _require_btrfs_forget_or_module_loadable
46
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
51
52 mkdir $loop_mnt
53 mkdir $loop_mnt1
54
55 $XFS_IO_PROG -f -c "truncate 256m" $fs_img1 >>$seqres.full 2>&1
56
57 _mkfs_dev $fs_img1 >>$seqres.full 2>&1
58 cp $fs_img1 $fs_img2
59
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
64
65 _btrfs_forget_or_module_reload
66
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
69 # measure.
70 loop_dev=`_create_loop_device $fs_img1`
71
72 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
73         _fail "Failed to mount the second time"
74 $UMOUNT_PROG $loop_mnt
75
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
79
80 _mount $loop_dev $loop_mnt > /dev/null 2>&1 || \
81         _fail "Failed to mount the second time"
82 $UMOUNT_PROG $loop_mnt
83
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
87
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"
92
93 _btrfs_rescan_devices
94 # success, all done
95 echo "Silence is golden"
96 status=0
97 exit