common/rc: add _scratch_{u}mount_idmapped() helpers
[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 seq=`basename $0`
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
20
21 here=`pwd`
22 tmp=/tmp/$$
23 status=1    # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 _cleanup()
27 {
28         cd /
29         rm -f $tmp.*
30 }
31
32 # get standard environment, filters and checks
33 . ./common/rc
34 . ./common/filter
35
36 # real QA test starts here
37 _supported_fs xfs
38 _require_scratch
39 _require_realtime
40 _require_test_program "punch-alternating"
41
42 rm -f $seqres.full
43
44 # Format filesystem to get the block size
45 _scratch_mkfs > $seqres.full
46 _scratch_mount >> $seqres.full
47
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))
51
52 echo "blksz $blksz rextsize $rextsize rextblks $rextblks" >> $seqres.full
53
54 _scratch_unmount
55
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.
61
62 rtsize1=$((2097151 * blksz))
63 rtsize2=$((8 * blksz * rextsize))
64 rtsize=$(( $(blockdev --getsz $SCRATCH_RTDEV) * 512 ))
65
66 echo "rtsize1 $rtsize1 rtsize2 $rtsize2 rtsize $rtsize" >> $seqres.full
67
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"
72
73 rtsize=$((rtsize - (rtsize % rtsize2)))
74
75 echo "rt size will be $rtsize" >> $seqres.full
76
77 _scratch_mkfs -r size=$rtsize >> $seqres.full
78 _scratch_mount >> $seqres.full
79
80 # Make sure the root directory has rtinherit set so our test file will too
81 $XFS_IO_PROG -c 'chattr +t' $SCRATCH_MNT
82
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"
87
88 avail="$(df -P "$SCRATCH_MNT" | awk 'END {print $4}')"1
89 toobig="$((avail * 2))"
90
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"
94
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
97 # not EFSCORRUPTED.
98 $XFS_IO_PROG -f -c "falloc 0 ${toobig}k" "$SCRATCH_MNT/ouch"
99
100 # success, all done
101 status=0
102 exit