xfs: stress XFS delalloc indirect block reservations
[xfstests-dev.git] / tests / xfs / 196
1 #! /bin/bash
2 # FS QA Test No. 196
3 #
4 # This test stresses indirect block reservation for delayed allocation extents.
5 # XFS reserves extra blocks for deferred allocation of delalloc extents. These
6 # reserved blocks can be divided among more extents than anticipated if the
7 # original extent for which the blocks were reserved is split into multiple
8 # delalloc extents. If this scenario repeats, eventually some extents are left
9 # without any indirect block reservation whatsoever. This leads to assert
10 # failures and possibly other problems in XFS.
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2017 Red Hat, Inc.  All Rights Reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28 #
29
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         cd /
42         rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/punch
48
49 # real QA test starts here
50 rm -f $seqres.full
51
52 # Modify as appropriate.
53 _supported_fs generic
54 _supported_os Linux
55 _require_scratch
56 _require_xfs_sysfs $(_short_dev $TEST_DEV)/drop_writes
57
58 _scratch_mkfs >/dev/null 2>&1
59 _scratch_mount
60
61 sdev=$(_short_dev $SCRATCH_DEV)
62 file=$SCRATCH_MNT/file.$seq
63 bytes=$((64 * 1024))
64
65 # create sequential delayed allocation
66 $XFS_IO_PROG -f -c "pwrite 0 $bytes" $file >> $seqres.full 2>&1
67
68 # Enable write drops. All buffered writes are dropped from this point on.
69 echo 1 > /sys/fs/xfs/$sdev/drop_writes
70
71 # Write every other 4k range to split the larger delalloc extent into many more
72 # smaller extents. Use pwrite because with write failures enabled, all
73 # preexisting delalloc blocks in the range of the I/O are tossed without
74 # discretion. This allows manipulation of the delalloc extent without conversion
75 # to real blocks (and thus releasing the indirect reservation).
76 endoff=$((bytes - 4096))
77 for i in $(seq 0 8192 $endoff); do
78         $XFS_IO_PROG -c "pwrite $i 4k" $file >> $seqres.full 2>&1
79 done
80
81 # now pwrite the opposite set to remove remaining delalloc extents
82 for i in $(seq 4096 8192 $endoff); do
83         $XFS_IO_PROG -c "pwrite $i 4k" $file >> $seqres.full 2>&1
84 done
85
86 echo 0 > /sys/fs/xfs/$sdev/drop_writes
87
88 _scratch_cycle_mount
89 $XFS_IO_PROG -c 'bmap -vp' $file | _filter_bmap
90
91 # Now test a buffered write workload with larger extents. Write a 100m extent,
92 # split it at the 3/4 mark, then write another 100m extent that is contiguous
93 # with the 1/4 portion of the split extent. Repeat several times. This pattern
94 # is known to prematurely exhaust indirect reservations and cause warnings and
95 # assert failures.
96 rm -f $file
97 for offset in $(seq 0 100 500); do
98         $XFS_IO_PROG -fc "pwrite ${offset}m 100m" $file >> $seqres.full 2>&1
99
100         punchoffset=$((offset + 75))
101         echo 1 > /sys/fs/xfs/$sdev/drop_writes
102         $XFS_IO_PROG -c "pwrite ${punchoffset}m 4k" $file >> $seqres.full 2>&1
103         echo 0 > /sys/fs/xfs/$sdev/drop_writes
104 done
105
106 echo "Silence is golden."
107
108 status=0
109 exit