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 "finsert"
81 blksize=`_get_block_size $TEST_DIR`
83 # Generate a block with a repeating number represented as 4 bytes decimal.
84 # The test generates unique pattern for each block in order to observe a
86 function generate_pattern() {
88 printf "%04d" $blkind | awk '{ while (c++ < '$(($blksize/4))') \
89 printf "%s", $0 }' > $pattern
92 $XFS_IO_PROG -f -c "falloc 0 $(($blksize * 2))" $testfile \
95 # First block, has 0001 as a pattern
97 $XFS_IO_PROG -c "pwrite -i $pattern 0 $blksize" $testfile \
100 # Second block, has 0002 as a pattern
102 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
105 # Insert 498 blocks after the first block. We use this quite big
106 # number to increase the reproduction probability.
107 for (( block=3; block<=500; block++ )); do
108 $XFS_IO_PROG -c "finsert $blksize $blksize" $testfile \
111 generate_pattern $block
112 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
115 # Avoid offsets in hexdump output, because block size can vary.
116 # Here we check md5 after each insert to be sure that zero blocks
117 # do not appear, targets this commit:
118 # 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
119 # or blocks are in correct order, this commit:
120 # 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
122 md5=`hexdump -e '16/1 "%_p" "\n"' $testfile | md5sum`
123 printf "#%d %s\n" "$block" "$md5"
126 # Eventually output file has 500 blocks in the following order:
127 # 0001 0500 0499 0498 ... 0002