2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle. All Rights Reserved.
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.
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
32 # get standard environment, filters and checks
36 # real QA test starts here
40 _require_test_program "punch-alternating"
44 # Format filesystem to get the block size
45 _scratch_mkfs > $seqres.full
46 _scratch_mount >> $seqres.full
48 blksz=$(_get_block_size $SCRATCH_MNT)
49 rextsize=$($XFS_INFO_PROG $SCRATCH_MNT | grep realtime.*extsz | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g')
50 rextblks=$((rextsize / blksz))
52 echo "blksz $blksz rextsize $rextsize rextblks $rextblks" >> $seqres.full
56 # Format filesystem with a realtime volume whose size fits the following:
57 # 1. Longer than (XFS MAXEXTLEN * blocksize) bytes so that a large fallocate
58 # request can create a maximally sized data fork extent mapping and then
59 # ask the allocator for even more blocks.
60 # 2. Exactly a multiple of (NBBY * blksz * rextsize) bytes.
62 rtsize1=$((2097151 * blksz))
63 rtsize2=$((8 * blksz * rextsize))
64 rtsize=$(( $(blockdev --getsz $SCRATCH_RTDEV) * 512 ))
66 echo "rtsize1 $rtsize1 rtsize2 $rtsize2 rtsize $rtsize" >> $seqres.full
68 test $rtsize -gt $rtsize1 || \
69 _notrun "scratch rt device too small, need $rtsize1 bytes"
70 test $rtsize -gt $rtsize2 || \
71 _notrun "scratch rt device too small, need $rtsize2 bytes"
73 rtsize=$((rtsize - (rtsize % rtsize2)))
75 echo "rt size will be $rtsize" >> $seqres.full
77 _scratch_mkfs -r size=$rtsize >> $seqres.full
78 _scratch_mount >> $seqres.full
80 # Make sure the root directory has rtinherit set so our test file will too
81 $XFS_IO_PROG -c 'chattr +t' $SCRATCH_MNT
83 # Allocate some stuff at the start, to force the first falloc of the ouch file
84 # to happen somewhere in the middle of the rt volume
85 $XFS_IO_PROG -f -c 'falloc 0 64m' "$SCRATCH_MNT/b"
86 $here/src/punch-alternating -i $((rextblks * 2)) -s $((rextblks)) "$SCRATCH_MNT/b"
88 avail="$(df -P "$SCRATCH_MNT" | awk 'END {print $4}')"1
89 toobig="$((avail * 2))"
91 # falloc the ouch file in the middle of the rt extent to exercise the near
92 # allocator in the last step.
93 $XFS_IO_PROG -f -c 'falloc 0 1g' "$SCRATCH_MNT/ouch"
95 # Try to get the near allocator to overflow on an allocation that matches
96 # exactly one of the rtsummary size levels. This should return ENOSPC and
98 $XFS_IO_PROG -f -c "falloc 0 ${toobig}k" "$SCRATCH_MNT/ouch"