2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Roman Penyaev. All Rights Reserved.
7 # Regression test which targets two nasty ext4 bugs in a logic which
10 # 1) 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
12 # An incorrect right shift (insert range) for the first extent in
15 # Test tries to insert many blocks at the same offset to reproduce
16 # the following layout:
19 # |ext0 ext1|ext2 ext3 ...|
21 # insert of a new block
23 # Because of an incorrect range first block is never reached,
24 # thus ext1 is untouched, resulting to a hole at a wrong offset:
29 # |ext0 ext1| ext2 ext3 ...|
31 # hole at a wrong offset
36 # |ext0 ext1|ext2 ext3 ...|
38 # hole at a correct offset
40 # 2) 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
42 # Extents status tree is filled in with outdated offsets while doing
43 # extents shift, that leads to wrong data blocks. That is why test
44 # writes unique block content and checks md5sum of a result file after
48 seqres=$RESULT_DIR/$seq
49 echo "QA output created by $seq"
53 status=1 # failure is the default!
54 trap "_cleanup; exit \$status" 0 1 2 3 15
56 testfile=$TEST_DIR/$seq.file
66 # get standard environment, filters and checks
70 # remove previous $seqres.full before test
73 # real QA test starts here
75 # Modify as appropriate.
79 _require_xfs_io_command "falloc"
80 _require_xfs_io_command "finsert"
82 blksize=`_get_block_size $TEST_DIR`
84 # Generate a block with a repeating number represented as 4 bytes decimal.
85 # The test generates unique pattern for each block in order to observe a
87 function generate_pattern() {
89 printf "%04d" $blkind | awk '{ while (c++ < '$(($blksize/4))') \
90 printf "%s", $0 }' > $pattern
93 $XFS_IO_PROG -f -c "falloc 0 $(($blksize * 2))" $testfile \
96 # First block, has 0001 as a pattern
98 $XFS_IO_PROG -c "pwrite -i $pattern 0 $blksize" $testfile \
101 # Second block, has 0002 as a pattern
103 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
106 # Insert 498 blocks after the first block. We use this quite big
107 # number to increase the reproduction probability.
108 for (( block=3; block<=500; block++ )); do
109 $XFS_IO_PROG -c "finsert $blksize $blksize" $testfile \
112 generate_pattern $block
113 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
116 # Avoid offsets in hexdump output, because block size can vary.
117 # Here we check md5 after each insert to be sure that zero blocks
118 # do not appear, targets this commit:
119 # 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
120 # or blocks are in correct order, this commit:
121 # 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
123 md5=`hexdump -e '16/1 "%_p" "\n"' $testfile | md5sum`
124 printf "#%d %s\n" "$block" "$md5"
127 # Eventually output file has 500 blocks in the following order:
128 # 0001 0500 0499 0498 ... 0002