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