4 # Regression test which targets two nasty ext4 bugs in a logic which
7 # 1) 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
9 # An incorrect right shift (insert range) for the first extent in
12 # Test tries to insert many blocks at the same offset to reproduce
13 # the following layout:
16 # |ext0 ext1|ext2 ext3 ...|
18 # insert of a new block
20 # Because of an incorrect range first block is never reached,
21 # thus ext1 is untouched, resulting to a hole at a wrong offset:
26 # |ext0 ext1| ext2 ext3 ...|
28 # hole at a wrong offset
33 # |ext0 ext1|ext2 ext3 ...|
35 # hole at a correct offset
37 # 2) 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
39 # Extents status tree is filled in with outdated offsets while doing
40 # extents shift, that leads to wrong data blocks. That is why test
41 # writes unique block content and checks md5sum of a result file after
44 #-----------------------------------------------------------------------
45 # Copyright (c) 2017 Roman Penyaev. All Rights Reserved.
47 # This program is free software; you can redistribute it and/or
48 # modify it under the terms of the GNU General Public License as
49 # published by the Free Software Foundation.
51 # This program is distributed in the hope that it would be useful,
52 # but WITHOUT ANY WARRANTY; without even the implied warranty of
53 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54 # GNU General Public License for more details.
56 # You should have received a copy of the GNU General Public License
57 # along with this program; if not, write the Free Software Foundation,
58 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
59 #-----------------------------------------------------------------------
63 seqres=$RESULT_DIR/$seq
64 echo "QA output created by $seq"
68 status=1 # failure is the default!
69 trap "_cleanup; exit \$status" 0 1 2 3 15
71 testfile=$TEST_DIR/$seq.file
81 # get standard environment, filters and checks
85 # remove previous $seqres.full before test
88 # real QA test starts here
90 # Modify as appropriate.
94 _require_xfs_io_command "finsert"
96 blksize=`_get_block_size $TEST_DIR`
98 # Generate a block with a repeating number represented as 4 bytes decimal.
99 # The test generates unique pattern for each block in order to observe a
100 # wrong order if any.
101 function generate_pattern() {
103 printf "%04d" $blkind | awk '{ while (c++ < '$(($blksize/4))') \
104 printf "%s", $0 }' > $pattern
107 $XFS_IO_PROG -f -c "falloc 0 $(($blksize * 2))" $testfile \
110 # First block, has 0001 as a pattern
112 $XFS_IO_PROG -c "pwrite -i $pattern 0 $blksize" $testfile \
115 # Second block, has 0002 as a pattern
117 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
120 # Insert 498 blocks after the first block. We use this quite big
121 # number to increase the reproduction probability.
122 for (( block=3; block<=500; block++ )); do
123 $XFS_IO_PROG -c "finsert $blksize $blksize" $testfile \
126 generate_pattern $block
127 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
130 # Avoid offsets in hexdump output, because block size can vary.
131 # Here we check md5 after each insert to be sure that zero blocks
132 # do not appear, targets this commit:
133 # 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
134 # or blocks are in correct order, this commit:
135 # 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
137 md5=`hexdump -e '16/1 "%_p" "\n"' $testfile | md5sum`
138 printf "#%d %s\n" "$block" "$md5"
141 # Eventually output file has 500 blocks in the following order:
142 # 0001 0500 0499 0498 ... 0002