lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 033
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 033
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
33 # real QA test starts here
34 rm -f $seqres.full
35
36 # Modify as appropriate.
37 _supported_fs generic
38 _supported_os Linux
39 _require_scratch
40 _require_xfs_io_command "fzero"
41
42 _scratch_mkfs >/dev/null 2>&1
43 _scratch_mount
44
45 file=$SCRATCH_MNT/file.$seq
46 bytes=$((64 * 1024))
47
48 # create sequential delayed allocation
49 $XFS_IO_PROG -f -c "pwrite 0 $bytes" $file >> $seqres.full 2>&1
50
51 # Zero every other 4k range to split the larger delalloc extent into many more
52 # smaller extents. Use zero instead of hole punch because the former does not
53 # force writeback (and hence delalloc conversion). It can simply discard
54 # delalloc blocks and convert the ranges to unwritten.
55 endoff=$((bytes - 4096))
56 for i in $(seq 0 8192 $endoff); do
57         $XFS_IO_PROG -c "fzero -k $i 4k" $file >> $seqres.full 2>&1
58 done
59
60 # now zero the opposite set to remove remaining delalloc extents
61 for i in $(seq 4096 8192 $endoff); do
62         $XFS_IO_PROG -c "fzero -k $i 4k" $file >> $seqres.full 2>&1
63 done
64
65 _scratch_cycle_mount
66 hexdump $file
67
68 status=0
69 exit