reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 033
1 #! /bin/bash
2 # FS QA Test No. 033
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) 2014 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
48 # real QA test starts here
49 rm -f $seqres.full
50
51 # Modify as appropriate.
52 _supported_fs generic
53 _supported_os Linux
54 _require_scratch
55 _require_xfs_io_command "fzero"
56
57 _scratch_mkfs >/dev/null 2>&1
58 _scratch_mount
59
60 file=$SCRATCH_MNT/file.$seq
61 bytes=$((64 * 1024))
62
63 # create sequential delayed allocation
64 $XFS_IO_PROG -f -c "pwrite 0 $bytes" $file >> $seqres.full 2>&1
65
66 # Zero every other 4k range to split the larger delalloc extent into many more
67 # smaller extents. Use zero instead of hole punch because the former does not
68 # force writeback (and hence delalloc conversion). It can simply discard
69 # delalloc blocks and convert the ranges to unwritten.
70 endoff=$((bytes - 4096))
71 for i in $(seq 0 8192 $endoff); do
72         $XFS_IO_PROG -c "fzero -k $i 4k" $file >> $seqres.full 2>&1
73 done
74
75 # now zero the opposite set to remove remaining delalloc extents
76 for i in $(seq 4096 8192 $endoff); do
77         $XFS_IO_PROG -c "fzero -k $i 4k" $file >> $seqres.full 2>&1
78 done
79
80 _scratch_remount
81 hexdump $file
82
83 status=0
84 exit