xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 513
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 513
6 #
7 # XFS mount options sanity check, refer to 'man 5 xfs'.
8 #
9 . ./common/preamble
10 _begin_fstest auto mount
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         cd /
16         rm -f $tmp.*
17         $UMOUNT_PROG $LOOP_MNT 2>/dev/null
18         if [ -n "$LOOP_DEV" ];then
19                 _destroy_loop_device $LOOP_DEV 2>/dev/null
20         fi
21         if [ -n "$LOOP_SPARE_DEV" ];then
22                 _destroy_loop_device $LOOP_SPARE_DEV 2>/dev/null
23         fi
24         rm -f $LOOP_IMG
25         rm -f $LOOP_SPARE_IMG
26         rmdir $LOOP_MNT
27 }
28
29 # Import common functions.
30 . ./common/filter
31
32 # real QA test starts here
33 _supported_fs xfs
34 _require_test
35 _require_loop
36 _require_xfs_io_command "falloc"
37
38 LOOP_IMG=$TEST_DIR/$seq.dev
39 LOOP_SPARE_IMG=$TEST_DIR/$seq.logdev
40 LOOP_MNT=$TEST_DIR/$seq.mnt
41
42 echo "** create loop device"
43 $XFS_IO_PROG -f -c "truncate 32g" $LOOP_IMG
44 LOOP_DEV=`_create_loop_device $LOOP_IMG`
45
46 echo "** create loop log device"
47 $XFS_IO_PROG -f -c "truncate 1g" $LOOP_SPARE_IMG
48 LOOP_SPARE_DEV=`_create_loop_device $LOOP_SPARE_IMG`
49
50 echo "** create loop mount point"
51 rmdir $LOOP_MNT 2>/dev/null
52 mkdir -p $LOOP_MNT || _fail "cannot create loopback mount point"
53
54 filter_loop()
55 {
56         sed -e "s,\B$LOOP_MNT,LOOP_MNT,g" \
57             -e "s,\B$LOOP_DEV,LOOP_DEV,g" \
58             -e "s,\B$LOOP_SPARE_DEV,LOOP_SPARE_DEV,g"
59 }
60
61 filter_xfs_opt()
62 {
63         sed -e "s,allocsize=$pagesz,allocsize=PAGESIZE,g"
64 }
65
66 # avoid the effection from MKFS_OPTIONS
67 MKFS_OPTIONS=""
68 do_mkfs()
69 {
70         echo "FORMAT: $@" | filter_loop | tee -a $seqres.full
71         $MKFS_XFS_PROG -f $* $LOOP_DEV | _filter_mkfs >>$seqres.full 2>$tmp.mkfs
72         if [ "${PIPESTATUS[0]}" -ne 0 ]; then
73                 _fail "Fails on _mkfs_dev $* $LOOP_DEV"
74         fi
75         . $tmp.mkfs
76 }
77
78 is_dev_mounted()
79 {
80         findmnt --source $LOOP_DEV >/dev/null
81         return $?
82 }
83
84 get_mount_info()
85 {
86         findmnt --source $LOOP_DEV -o OPTIONS -n
87 }
88
89 force_unmount()
90 {
91         $UMOUNT_PROG $LOOP_MNT >/dev/null 2>&1
92 }
93
94 # _do_test <mount options> <should be mounted?> [<key string> <key should be found?>]
95 _do_test()
96 {
97         local opts="$1"
98         local mounted="$2"      # pass or fail
99         local key="$3"
100         local found="$4"        # true or false
101         local rc
102         local info
103
104         # mount test
105         _mount $LOOP_DEV $LOOP_MNT $opts 2>>$seqres.full
106         rc=$?
107         if [ $rc -eq 0 ];then
108                 if [ "${mounted}" = "fail" ];then
109                         echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
110                         echo "ERROR: expect mount to fail, but it succeeded"
111                         return 1
112                 fi
113                 is_dev_mounted
114                 if [ $? -ne 0 ];then
115                         echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
116                         echo "ERROR: fs not mounted even mount return 0"
117                         return 1
118                 fi
119         else
120                 if [ "${mounted}" = "pass" ];then
121                         echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
122                         echo "ERROR: expect mount to succeed, but it failed"
123                         return 1
124                 fi
125                 is_dev_mounted
126                 if [ $? -eq 0 ];then
127                         echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
128                         echo "ERROR: fs is mounted even mount return non-zero"
129                         return 1
130                 fi
131         fi
132
133         # Skip below checking if "$key" argument isn't specified
134         if [ -z "$key" ];then
135                 return 0
136         fi
137         # Check the mount options after fs mounted.
138         info=`get_mount_info`
139         echo ${info} | grep -q "${key}"
140         rc=$?
141         if [ $rc -eq 0 ];then
142                 if [ "$found" != "true" ];then
143                         echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
144                         echo "ERROR: expected to find \"$key\" in mount info \"$info\""
145                         return 1
146                 fi
147         else
148                 if [ "$found" != "false" ];then
149                         echo "[FAILED]: mount $LOOP_DEV $LOOP_MNT $opts"
150                         echo "ERROR: did not expect to find \"$key\" in \"$info\""
151                         return 1
152                 fi
153         fi
154
155         return 0
156 }
157
158 do_test()
159 {
160         # Print each argument, include nil ones
161         echo -n "TEST:" | tee -a $seqres.full
162         for i in "$@";do
163                 echo -n " \"$i\"" | filter_loop | filter_xfs_opt | tee -a $seqres.full
164         done
165         echo | tee -a $seqres.full
166
167         # force unmount before testing
168         force_unmount
169         _do_test "$@"
170         # force unmount after testing
171         force_unmount
172 }
173
174 echo "** start xfs mount testing ..."
175 # Test allocsize=size
176 # Valid values for this option are page size (typically 4KiB) through to 1GiB
177 do_mkfs
178 pagesz=$(get_page_size)
179 if [ $pagesz -ge 1024 ];then
180         pagesz="$((pagesz / 1024))k"
181 fi
182 do_test "" pass "allocsize" "false"
183 do_test "-o allocsize=$pagesz" pass "allocsize=$pagesz" "true"
184 do_test "-o allocsize=1048576k" pass "allocsize=1048576k" "true"
185 do_test "-o allocsize=$((dbsize / 2))" fail
186 do_test "-o allocsize=2g" fail
187
188 # Test attr2
189 do_mkfs -m crc=1
190 do_test "" pass "attr2" "true"
191 do_test "-o attr2" pass "attr2" "true"
192 do_test "-o noattr2" fail
193 do_mkfs -m crc=0
194 do_test "" pass "attr2" "true"
195 do_test "-o attr2" pass "attr2" "true"
196 do_test "-o noattr2" pass "attr2" "false"
197
198 # Test discard
199 do_mkfs
200 do_test "" pass "discard" "false"
201 do_test "-o discard" pass "discard" "true"
202 do_test "-o nodiscard" pass "discard" "false"
203
204 # Test grpid|bsdgroups|nogrpid|sysvgroups
205 do_test "" pass "grpid" "false"
206 do_test "-o grpid" pass "grpid" "true"
207 do_test "-o bsdgroups" pass "grpid" "true"
208 do_test "-o nogrpid" pass "grpid" "false"
209 do_test "-o sysvgroups" pass "grpid" "false"
210
211 # Test filestreams
212 do_test "" pass "filestreams" "false"
213 do_test "-o filestreams" pass "filestreams" "true"
214
215 # Test ikeep
216 do_test "" pass "ikeep" "false"
217 do_test "-o ikeep" pass "ikeep" "true"
218 do_test "-o noikeep" pass "ikeep" "false"
219
220 # Test inode32|inode64
221 do_test "" pass "inode64" "true"
222 do_test "-o inode32" pass "inode32" "true"
223 do_test "-o inode64" pass "inode64" "true"
224
225 # Test largeio
226 do_test "" pass "largeio" "false"
227 do_test "-o largeio" pass "largeio" "true"
228 do_test "-o nolargeio" pass "largeio" "false"
229
230 # Test logbufs=value. Valid numbers range from 2–8 inclusive.
231 # New kernel (refer to 4f62282a3696 xfs: cleanup xlog_get_iclog_buffer_size)
232 # prints "logbufs=N" in /proc/mounts, but old kernel not. So the default
233 # 'display' about logbufs can't be expected, disable this test.
234 #do_test "" pass "logbufs" "false"
235 do_test "-o logbufs=8" pass "logbufs=8" "true"
236 do_test "-o logbufs=2" pass "logbufs=2" "true"
237 do_test "-o logbufs=1" fail
238 do_test "-o logbufs=9" fail
239 do_test "-o logbufs=99999999999999" fail
240
241 # Test logbsize=value.
242 do_mkfs -m crc=1 -l version=2
243 # New kernel (refer to 4f62282a3696 xfs: cleanup xlog_get_iclog_buffer_size)
244 # prints "logbsize=N" in /proc/mounts, but old kernel not. So the default
245 # 'display' about logbsize can't be expected, disable this test.
246 #do_test "" pass "logbsize" "false"
247 do_test "-o logbsize=16384" pass "logbsize=16k" "true"
248 do_test "-o logbsize=16k" pass "logbsize=16k" "true"
249 do_test "-o logbsize=32k" pass "logbsize=32k" "true"
250 do_test "-o logbsize=64k" pass "logbsize=64k" "true"
251 do_test "-o logbsize=128k" pass "logbsize=128k" "true"
252 do_test "-o logbsize=256k" pass "logbsize=256k" "true"
253 do_test "-o logbsize=8k" fail
254 do_test "-o logbsize=512k" fail
255 do_mkfs -m crc=0 -l version=1
256 # New kernel (refer to 4f62282a3696 xfs: cleanup xlog_get_iclog_buffer_size)
257 # prints "logbsize=N" in /proc/mounts, but old kernel not. So the default
258 # 'display' about logbsize can't be expected, disable this test.
259 #do_test "" pass "logbsize" "false"
260 do_test "-o logbsize=16384" pass "logbsize=16k" "true"
261 do_test "-o logbsize=16k" pass "logbsize=16k" "true"
262 do_test "-o logbsize=32k" pass "logbsize=32k" "true"
263 do_test "-o logbsize=64k" fail
264
265 # Test logdev
266 do_mkfs
267 do_test "" pass "logdev" "false"
268 do_test "-o logdev=$LOOP_SPARE_DEV" fail
269 do_mkfs -l logdev=$LOOP_SPARE_DEV
270 do_test "-o logdev=$LOOP_SPARE_DEV" pass "logdev=$LOOP_SPARE_DEV" "true"
271 do_test "" fail
272
273 # Test noalign
274 do_mkfs
275 do_test "" pass "noalign" "false"
276 do_test "-o noalign" pass "noalign" "true"
277
278 # Test norecovery
279 do_test "" pass "norecovery" "false"
280 do_test "-o norecovery,ro" pass "norecovery" "true"
281 do_test "-o norecovery" fail
282
283 # Test nouuid
284 do_test "" pass "nouuid" "false"
285 do_test "-o nouuid" pass "nouuid" "true"
286
287 # Test noquota
288 do_test "" pass "noquota" "true"
289 do_test "-o noquota" pass "noquota" "true"
290
291 # Test uquota/usrquota/quota/uqnoenforce/qnoenforce
292 do_test "" pass "usrquota" "false"
293 do_test "-o uquota" pass "usrquota" "true"
294 do_test "-o usrquota" pass "usrquota" "true"
295 do_test "-o quota" pass "usrquota" "true"
296 do_test "-o uqnoenforce" pass "uqnoenforce" "true"
297 do_test "-o qnoenforce" pass "uqnoenforce" "true"
298
299 # Test gquota/grpquota/gqnoenforce
300 do_test "" pass "grpquota" "false"
301 do_test "-o gquota" pass "grpquota" "true"
302 do_test "-o grpquota" pass "grpquota" "true"
303 do_test "-o gqnoenforce" pass "gqnoenforce" "true"
304
305 # Test pquota/prjquota/pqnoenforce
306 do_test "" pass "prjquota" "false"
307 do_test "-o pquota" pass "prjquota" "true"
308 do_test "-o prjquota" pass "prjquota" "true"
309 do_test "-o pqnoenforce" pass "pqnoenforce" "true"
310
311 # Test sunit=value and swidth=value
312 do_mkfs -d sunit=128,swidth=128
313 do_test "-o sunit=8,swidth=8" pass "sunit=8,swidth=8" "true"
314 do_test "-o sunit=8,swidth=64" pass "sunit=8,swidth=64" "true"
315 do_test "-o sunit=128,swidth=128" pass "sunit=128,swidth=128" "true"
316 do_test "-o sunit=256,swidth=256" pass "sunit=256,swidth=256" "true"
317 do_test "-o sunit=2,swidth=2" fail
318
319 # Test swalloc
320 do_mkfs
321 do_test "" pass "swalloc" "false"
322 do_test "-o swalloc" pass "swalloc" "true"
323
324 # Test wsync
325 do_test "" pass "wsync" "false"
326 do_test "-o wsync" pass "wsync" "true"
327
328 echo "** end of testing"
329 # success, all done
330 status=0
331 exit