generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 196
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 196
6 #
7 # This test stresses indirect block reservation for delayed allocation extents.
8 # XFS reserves extra blocks for deferred allocation of delalloc extents. These
9 # reserved blocks can be divided among more extents than anticipated if the
10 # original extent for which the blocks were reserved is split into multiple
11 # delalloc extents. If this scenario repeats, eventually some extents are left
12 # without any indirect block reservation whatsoever. This leads to assert
13 # failures and possibly other problems in XFS.
14 #
15 . ./common/preamble
16 _begin_fstest auto quick rw
17
18 # Import common functions.
19 . ./common/punch
20 . ./common/inject
21
22 # real QA test starts here
23
24 # Modify as appropriate.
25 _supported_fs generic
26 _require_scratch
27 _require_xfs_io_error_injection "drop_writes"
28
29 _scratch_mkfs >/dev/null 2>&1
30 _scratch_mount
31
32 sdev=$(_short_dev $SCRATCH_DEV)
33 file=$SCRATCH_MNT/file.$seq
34 bytes=$((64 * 1024))
35
36 # create sequential delayed allocation
37 $XFS_IO_PROG -f -c "pwrite 0 $bytes" $file >> $seqres.full 2>&1
38 $XFS_IO_PROG -c "bmap -elpv" $file | grep -q delalloc || \
39         _notrun "Unable to create delayed allocations"
40
41 # Enable write drops. All buffered writes are dropped from this point on.
42 _scratch_inject_error "drop_writes" 1
43
44 # Write every other 4k range to split the larger delalloc extent into many more
45 # smaller extents. Use pwrite because with write failures enabled, all
46 # preexisting delalloc blocks in the range of the I/O are tossed without
47 # discretion. This allows manipulation of the delalloc extent without conversion
48 # to real blocks (and thus releasing the indirect reservation).
49 endoff=$((bytes - 4096))
50 for i in $(seq 0 8192 $endoff); do
51         $XFS_IO_PROG -c "pwrite $i 4k" $file >> $seqres.full 2>&1
52 done
53
54 # now pwrite the opposite set to remove remaining delalloc extents
55 for i in $(seq 4096 8192 $endoff); do
56         $XFS_IO_PROG -c "pwrite $i 4k" $file >> $seqres.full 2>&1
57 done
58
59 _scratch_inject_error "drop_writes" 0
60
61 _scratch_cycle_mount
62 $XFS_IO_PROG -c 'bmap -vp' $file | _filter_bmap
63
64 # Now test a buffered write workload with larger extents. Write a 100m extent,
65 # split it at the 3/4 mark, then write another 100m extent that is contiguous
66 # with the 1/4 portion of the split extent. Repeat several times. This pattern
67 # is known to prematurely exhaust indirect reservations and cause warnings and
68 # assert failures.
69 rm -f $file
70 for offset in $(seq 0 100 500); do
71         $XFS_IO_PROG -fc "pwrite ${offset}m 100m" $file >> $seqres.full 2>&1
72
73         punchoffset=$((offset + 75))
74         _scratch_inject_error "drop_writes"
75         $XFS_IO_PROG -c "pwrite ${punchoffset}m 4k" $file >> $seqres.full 2>&1
76         _scratch_inject_error "drop_writes" 0
77 done
78
79 echo "Silence is golden."
80
81 status=0
82 exit