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