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 _begin_fstest auto quick rw realtime
20 # Import common functions.
23 # real QA test starts here
27 _require_test_program "punch-alternating"
29 # Format filesystem to get the block size
30 _scratch_mkfs > $seqres.full
31 _scratch_mount >> $seqres.full
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))
37 echo "blksz $blksz rextsize $rextsize rextblks $rextblks" >> $seqres.full
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.
47 rtsize1=$((2097151 * blksz))
48 rtsize2=$((8 * blksz * rextsize))
49 rtsize=$(( $(blockdev --getsz $SCRATCH_RTDEV) * 512 ))
51 echo "rtsize1 $rtsize1 rtsize2 $rtsize2 rtsize $rtsize" >> $seqres.full
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"
58 rtsize=$((rtsize - (rtsize % rtsize2)))
60 echo "rt size will be $rtsize" >> $seqres.full
62 _scratch_mkfs -r size=$rtsize >> $seqres.full
63 _scratch_mount >> $seqres.full
65 # Make sure the root directory has rtinherit set so our test file will too
66 _xfs_force_bdev realtime $SCRATCH_MNT
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"
73 avail="$(df -P "$SCRATCH_MNT" | awk 'END {print $4}')"1
74 toobig="$((avail * 2))"
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"
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
83 $XFS_IO_PROG -f -c "falloc 0 ${toobig}k" "$SCRATCH_MNT/ouch"