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 _begin_fstest auto quick insert
50 testfile=$TEST_DIR/$seq.file
53 # Override the default cleanup function.
61 # Import common functions.
64 # real QA test starts here
66 # Modify as appropriate.
69 _require_xfs_io_command "falloc"
70 _require_xfs_io_command "finsert"
72 blksize=`_get_block_size $TEST_DIR`
74 # Generate a block with a repeating number represented as 4 bytes decimal.
75 # The test generates unique pattern for each block in order to observe a
77 function generate_pattern() {
79 printf "%04d" $blkind | awk '{ while (c++ < '$(($blksize/4))') \
80 printf "%s", $0 }' > $pattern
83 $XFS_IO_PROG -f -c "falloc 0 $(($blksize * 2))" $testfile \
86 # First block, has 0001 as a pattern
88 $XFS_IO_PROG -c "pwrite -i $pattern 0 $blksize" $testfile \
91 # Second block, has 0002 as a pattern
93 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
96 # Insert 498 blocks after the first block. We use this quite big
97 # number to increase the reproduction probability.
98 for (( block=3; block<=500; block++ )); do
99 $XFS_IO_PROG -c "finsert $blksize $blksize" $testfile \
102 generate_pattern $block
103 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
106 # Avoid offsets in hexdump output, because block size can vary.
107 # Here we check md5 after each insert to be sure that zero blocks
108 # do not appear, targets this commit:
109 # 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
110 # or blocks are in correct order, this commit:
111 # 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
113 md5=`hexdump -e '16/1 "%_p" "\n"' $testfile | md5sum`
114 printf "#%d %s\n" "$block" "$md5"
117 # Eventually output file has 500 blocks in the following order:
118 # 0001 0500 0499 0498 ... 0002