btrfs/012: check free size of scratch device before copying files
[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 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26         cd /
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/punch
33 . ./common/inject
34
35 # real QA test starts here
36 rm -f $seqres.full
37
38 # Modify as appropriate.
39 _supported_fs generic
40 _require_scratch
41 _require_xfs_io_error_injection "drop_writes"
42
43 _scratch_mkfs >/dev/null 2>&1
44 _scratch_mount
45
46 sdev=$(_short_dev $SCRATCH_DEV)
47 file=$SCRATCH_MNT/file.$seq
48 bytes=$((64 * 1024))
49
50 # create sequential delayed allocation
51 $XFS_IO_PROG -f -c "pwrite 0 $bytes" $file >> $seqres.full 2>&1
52 $XFS_IO_PROG -c "bmap -elpv" $file | grep -q delalloc || \
53         _notrun "Unable to create delayed allocations"
54
55 # Enable write drops. All buffered writes are dropped from this point on.
56 _scratch_inject_error "drop_writes" 1
57
58 # Write every other 4k range to split the larger delalloc extent into many more
59 # smaller extents. Use pwrite because with write failures enabled, all
60 # preexisting delalloc blocks in the range of the I/O are tossed without
61 # discretion. This allows manipulation of the delalloc extent without conversion
62 # to real blocks (and thus releasing the indirect reservation).
63 endoff=$((bytes - 4096))
64 for i in $(seq 0 8192 $endoff); do
65         $XFS_IO_PROG -c "pwrite $i 4k" $file >> $seqres.full 2>&1
66 done
67
68 # now pwrite the opposite set to remove remaining delalloc extents
69 for i in $(seq 4096 8192 $endoff); do
70         $XFS_IO_PROG -c "pwrite $i 4k" $file >> $seqres.full 2>&1
71 done
72
73 _scratch_inject_error "drop_writes" 0
74
75 _scratch_cycle_mount
76 $XFS_IO_PROG -c 'bmap -vp' $file | _filter_bmap
77
78 # Now test a buffered write workload with larger extents. Write a 100m extent,
79 # split it at the 3/4 mark, then write another 100m extent that is contiguous
80 # with the 1/4 portion of the split extent. Repeat several times. This pattern
81 # is known to prematurely exhaust indirect reservations and cause warnings and
82 # assert failures.
83 rm -f $file
84 for offset in $(seq 0 100 500); do
85         $XFS_IO_PROG -fc "pwrite ${offset}m 100m" $file >> $seqres.full 2>&1
86
87         punchoffset=$((offset + 75))
88         _scratch_inject_error "drop_writes"
89         $XFS_IO_PROG -c "pwrite ${punchoffset}m 4k" $file >> $seqres.full 2>&1
90         _scratch_inject_error "drop_writes" 0
91 done
92
93 echo "Silence is golden."
94
95 status=0
96 exit