xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 146
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 146
6 #
7 # This is a regression test for commit 2a6ca4baed62 ("xfs: make sure the rt
8 # allocator doesn't run off the end") which fixes an overflow error in the
9 # _near realtime allocator.  If the rt bitmap ends exactly at the end of a
10 # block and the number of rt extents is large enough to allow an allocation
11 # request larger than the maximum extent size, it's possible that during a
12 # large allocation request, the allocator will fail to constrain maxlen on the
13 # second run through the loop, and the rt bitmap range check will run right off
14 # the end of the rtbitmap file.  When this happens, xfs triggers a verifier
15 # error and returns EFSCORRUPTED.
16
17 . ./common/preamble
18 _begin_fstest auto quick rw realtime
19
20 # Import common functions.
21 . ./common/filter
22
23 # real QA test starts here
24 _supported_fs xfs
25 _require_scratch
26 _require_realtime
27 _require_test_program "punch-alternating"
28
29 # Format filesystem to get the block size
30 _scratch_mkfs > $seqres.full
31 _scratch_mount >> $seqres.full
32
33 blksz=$(_get_block_size $SCRATCH_MNT)
34 rextsize=$($XFS_INFO_PROG $SCRATCH_MNT | grep realtime.*extsz | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g')
35 rextblks=$((rextsize / blksz))
36
37 echo "blksz $blksz rextsize $rextsize rextblks $rextblks" >> $seqres.full
38
39 _scratch_unmount
40
41 # Format filesystem with a realtime volume whose size fits the following:
42 # 1. Longer than (XFS MAXEXTLEN * blocksize) bytes so that a large fallocate
43 #    request can create a maximally sized data fork extent mapping and then
44 #    ask the allocator for even more blocks.
45 # 2. Exactly a multiple of (NBBY * blksz * rextsize) bytes.
46
47 rtsize1=$((2097151 * blksz))
48 rtsize2=$((8 * blksz * rextsize))
49 rtsize=$(( $(blockdev --getsz $SCRATCH_RTDEV) * 512 ))
50
51 echo "rtsize1 $rtsize1 rtsize2 $rtsize2 rtsize $rtsize" >> $seqres.full
52
53 test $rtsize -gt $rtsize1 || \
54         _notrun "scratch rt device too small, need $rtsize1 bytes"
55 test $rtsize -gt $rtsize2 || \
56         _notrun "scratch rt device too small, need $rtsize2 bytes"
57
58 rtsize=$((rtsize - (rtsize % rtsize2)))
59
60 echo "rt size will be $rtsize" >> $seqres.full
61
62 _scratch_mkfs -r size=$rtsize >> $seqres.full
63 _scratch_mount >> $seqres.full
64
65 # Make sure the root directory has rtinherit set so our test file will too
66 _xfs_force_bdev realtime $SCRATCH_MNT
67
68 # Allocate some stuff at the start, to force the first falloc of the ouch file
69 # to happen somewhere in the middle of the rt volume
70 $XFS_IO_PROG -f -c 'falloc 0 64m' "$SCRATCH_MNT/b"
71 $here/src/punch-alternating -i $((rextblks * 2)) -s $((rextblks)) "$SCRATCH_MNT/b"
72
73 avail="$(df -P "$SCRATCH_MNT" | awk 'END {print $4}')"1
74 toobig="$((avail * 2))"
75
76 # falloc the ouch file in the middle of the rt extent to exercise the near
77 # allocator in the last step.
78 $XFS_IO_PROG -f -c 'falloc 0 1g' "$SCRATCH_MNT/ouch"
79
80 # Try to get the near allocator to overflow on an allocation that matches
81 # exactly one of the rtsummary size levels.  This should return ENOSPC and
82 # not EFSCORRUPTED.
83 $XFS_IO_PROG -f -c "falloc 0 ${toobig}k" "$SCRATCH_MNT/ouch"
84
85 # success, all done
86 status=0
87 exit