e9b0649b8972bdd4a467a31adc39446d78b00f38
[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
57 DROP_WRITES="drop_writes"
58 # replace "drop_writes" with "fail_writes" for old kernel
59 if [ -f /sys/fs/xfs/$(_short_dev $TEST_DEV)/fail_writes ];then
60         DROP_WRITES="fail_writes"
61 fi
62 _require_xfs_sysfs $(_short_dev $TEST_DEV)/${DROP_WRITES}
63
64 _scratch_mkfs >/dev/null 2>&1
65 _scratch_mount
66
67 sdev=$(_short_dev $SCRATCH_DEV)
68 file=$SCRATCH_MNT/file.$seq
69 bytes=$((64 * 1024))
70
71 # create sequential delayed allocation
72 $XFS_IO_PROG -f -c "pwrite 0 $bytes" $file >> $seqres.full 2>&1
73
74 # Enable write drops. All buffered writes are dropped from this point on.
75 echo 1 > /sys/fs/xfs/$sdev/$DROP_WRITES
76
77 # Write every other 4k range to split the larger delalloc extent into many more
78 # smaller extents. Use pwrite because with write failures enabled, all
79 # preexisting delalloc blocks in the range of the I/O are tossed without
80 # discretion. This allows manipulation of the delalloc extent without conversion
81 # to real blocks (and thus releasing the indirect reservation).
82 endoff=$((bytes - 4096))
83 for i in $(seq 0 8192 $endoff); do
84         $XFS_IO_PROG -c "pwrite $i 4k" $file >> $seqres.full 2>&1
85 done
86
87 # now pwrite the opposite set to remove remaining delalloc extents
88 for i in $(seq 4096 8192 $endoff); do
89         $XFS_IO_PROG -c "pwrite $i 4k" $file >> $seqres.full 2>&1
90 done
91
92 echo 0 > /sys/fs/xfs/$sdev/$DROP_WRITES
93
94 _scratch_cycle_mount
95 $XFS_IO_PROG -c 'bmap -vp' $file | _filter_bmap
96
97 # Now test a buffered write workload with larger extents. Write a 100m extent,
98 # split it at the 3/4 mark, then write another 100m extent that is contiguous
99 # with the 1/4 portion of the split extent. Repeat several times. This pattern
100 # is known to prematurely exhaust indirect reservations and cause warnings and
101 # assert failures.
102 rm -f $file
103 for offset in $(seq 0 100 500); do
104         $XFS_IO_PROG -fc "pwrite ${offset}m 100m" $file >> $seqres.full 2>&1
105
106         punchoffset=$((offset + 75))
107         echo 1 > /sys/fs/xfs/$sdev/$DROP_WRITES
108         $XFS_IO_PROG -c "pwrite ${punchoffset}m 4k" $file >> $seqres.full 2>&1
109         echo 0 > /sys/fs/xfs/$sdev/$DROP_WRITES
110 done
111
112 echo "Silence is golden."
113
114 status=0
115 exit