fstests: _fail test by default when _scratch_mount fails
[xfstests-dev.git] / tests / btrfs / 131
1 #! /bin/bash
2 # FS QA Test 131
3 #
4 # Test free space tree mount options.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2016 Facebook.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35         cd /
36         rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # remove previous $seqres.full before test
44 rm -f $seqres.full
45
46 # real QA test starts here
47
48 _supported_fs btrfs
49 _supported_os Linux
50 _require_scratch
51 _require_btrfs_command inspect-internal dump-super
52
53 mkfs_v1()
54 {
55         _scratch_mkfs >/dev/null 2>&1
56         # Future proof against btrfs-progs making space_cache=v2 filesystems by
57         # default.
58         _scratch_mount -o clear_cache,space_cache=v1
59         _scratch_unmount
60 }
61
62 mkfs_v2()
63 {
64         _scratch_mkfs >/dev/null 2>&1
65         _scratch_mount -o space_cache=v2
66         _scratch_unmount
67 }
68
69 check_fst_compat()
70 {
71         compat_ro="$($BTRFS_UTIL_PROG inspect-internal dump-super "$SCRATCH_DEV" | \
72                      sed -rn 's/^compat_ro_flags\s+(.*)$/\1/p')"
73         if ((compat_ro & 0x1)); then
74                 echo "free space tree is enabled"
75         else
76                 echo "free space tree is disabled"
77         fi
78 }
79
80 # Mount options might interfere.
81 export MOUNT_OPTIONS=""
82
83 # When the free space tree is not enabled:
84 # -o space_cache=v1: keep using the old free space cache
85 # -o space_cache=v2: enable the free space tree
86 # -o clear_cache,space_cache=v2: clear the free space cache and enable the free space tree
87 # We don't check the no options case or plain space_cache as that will change
88 # in the future to turn on space_cache=v2.
89
90 mkfs_v1
91 echo "Using free space cache"
92 _scratch_mount -o space_cache=v1
93 check_fst_compat
94 _scratch_unmount
95
96 mkfs_v1
97 echo "Enabling free space tree"
98 _scratch_mount -o space_cache=v2
99 check_fst_compat
100 _scratch_unmount
101
102 mkfs_v1
103 echo "Disabling free space cache and enabling free space tree"
104 _scratch_mount -o clear_cache,space_cache=v2
105 check_fst_compat
106 _scratch_unmount
107
108 # When the free space tree is enabled:
109 # -o nospace_cache, -o space_cache=v1: error
110 # no options, -o space_cache=v2: keep using the free space tree
111 # -o clear_cache, -o clear_cache,space_cache=v2: clear and recreate the free space tree
112 # -o clear_cache,nospace_cache: clear the free space tree
113 # -o clear_cache,space_cache=v1: clear the free space tree, enable the free space cache
114
115 mkfs_v2
116 echo "Trying to mount without free space tree"
117 _try_scratch_mount -o nospace_cache >/dev/null 2>&1 || echo "mount failed"
118 _try_scratch_mount -o space_cache=v1 >/dev/null 2>&1 || echo "mount failed"
119
120 mkfs_v2
121 echo "Mounting existing free space tree"
122 _scratch_mount
123 check_fst_compat
124 _scratch_unmount
125 _scratch_mount -o space_cache=v2
126 check_fst_compat
127 _scratch_unmount
128
129 mkfs_v2
130 echo "Recreating free space tree"
131 _scratch_mount -o clear_cache,space_cache=v2
132 check_fst_compat
133 _scratch_unmount
134 mkfs_v2
135 _scratch_mount -o clear_cache
136 check_fst_compat
137 _scratch_unmount
138
139 mkfs_v2
140 echo "Disabling free space tree"
141 _scratch_mount -o clear_cache,nospace_cache
142 check_fst_compat
143 _scratch_unmount
144
145 mkfs_v2
146 echo "Reverting to free space cache"
147 _scratch_mount -o clear_cache,space_cache=v1
148 check_fst_compat
149 _scratch_unmount
150
151 # success, all done
152 status=0
153 exit