xfs: Add test for too-small device with stripe geometry
[xfstests-dev.git] / tests / btrfs / 131
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 131
6 #
7 # Test free space tree mount options.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 # real QA test starts here
32
33 _supported_fs btrfs
34 _require_scratch
35 _require_btrfs_command inspect-internal dump-super
36 _require_btrfs_fs_feature free_space_tree
37
38 mkfs_v1()
39 {
40         _scratch_mkfs >/dev/null 2>&1
41         # Future proof against btrfs-progs making space_cache=v2 filesystems by
42         # default.
43         _scratch_mount -o clear_cache,space_cache=v1
44         _scratch_unmount
45 }
46
47 mkfs_v2()
48 {
49         _scratch_mkfs >/dev/null 2>&1
50         _scratch_mount -o space_cache=v2
51         _scratch_unmount
52 }
53
54 check_fst_compat()
55 {
56         compat_ro="$($BTRFS_UTIL_PROG inspect-internal dump-super "$SCRATCH_DEV" | \
57                      sed -rn 's/^compat_ro_flags\s+(.*)$/\1/p')"
58         if ((compat_ro & 0x1)); then
59                 echo "free space tree is enabled"
60         else
61                 echo "free space tree is disabled"
62         fi
63 }
64
65 # Mount options might interfere.
66 export MOUNT_OPTIONS=""
67
68 # When the free space tree is not enabled:
69 # -o space_cache=v1: keep using the old free space cache
70 # -o space_cache=v2: enable the free space tree
71 # -o clear_cache,space_cache=v2: clear the free space cache and enable the free space tree
72 # We don't check the no options case or plain space_cache as that will change
73 # in the future to turn on space_cache=v2.
74
75 mkfs_v1
76 echo "Using free space cache"
77 _scratch_mount -o space_cache=v1
78 check_fst_compat
79 _scratch_unmount
80
81 mkfs_v1
82 echo "Enabling free space tree"
83 _scratch_mount -o space_cache=v2
84 check_fst_compat
85 _scratch_unmount
86
87 mkfs_v1
88 echo "Disabling free space cache and enabling free space tree"
89 _scratch_mount -o clear_cache,space_cache=v2
90 check_fst_compat
91 _scratch_unmount
92
93 # When the free space tree is enabled:
94 # -o nospace_cache, -o space_cache=v1: error
95 # no options, -o space_cache=v2: keep using the free space tree
96 # -o clear_cache, -o clear_cache,space_cache=v2: clear and recreate the free space tree
97 # -o clear_cache,nospace_cache: clear the free space tree
98 # -o clear_cache,space_cache=v1: clear the free space tree, enable the free space cache
99
100 mkfs_v2
101 echo "Trying to mount without free space tree"
102 _try_scratch_mount -o nospace_cache >/dev/null 2>&1 || echo "mount failed"
103 _try_scratch_mount -o space_cache=v1 >/dev/null 2>&1 || echo "mount failed"
104
105 mkfs_v2
106 echo "Mounting existing free space tree"
107 _scratch_mount
108 check_fst_compat
109 _scratch_unmount
110 _scratch_mount -o space_cache=v2
111 check_fst_compat
112 _scratch_unmount
113
114 mkfs_v2
115 echo "Recreating free space tree"
116 _scratch_mount -o clear_cache,space_cache=v2
117 check_fst_compat
118 _scratch_unmount
119 mkfs_v2
120 _scratch_mount -o clear_cache
121 check_fst_compat
122 _scratch_unmount
123
124 mkfs_v2
125 echo "Disabling free space tree"
126 _scratch_mount -o clear_cache,nospace_cache
127 check_fst_compat
128 _scratch_unmount
129
130 mkfs_v2
131 echo "Reverting to free space cache"
132 _scratch_mount -o clear_cache,space_cache=v1
133 check_fst_compat
134 _scratch_unmount
135
136 # success, all done
137 status=0
138 exit