Skip to contentSkip to conversation

xfstests: generic/403: reproduce ext4 bugs in a shift extents logic

PATCH Applied Roman Pen 3 participants 4 messages Jan 11, 2017 – Jan 12, 2017

lore
Share & tools
lore

Roman Pen

author
#0 lore raw

PATCH v3 1/1 xfstests: generic/403: reproduce ext4 bugs in a shift extents logic

Regression test which targets two nasty ext4 bugs in a logic which shifts extents:

1) 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")

Test tries to insert many blocks at the same offset to reproduce the following layout on ext4:

block #0 block #1
|ext0 ext1|ext2 ext3 ...|
^
insert of a new block

Because of an incorrect range first block is never reached, thus ext1 is untouched, resulting to a hole at a wrong offset:

What we got:

block #0 block #1
|ext0 ext1| ext2 ext3 ...|
^
hole at a wrong offset

What we expect:

block #0 block #1
|ext0 ext1|ext2 ext3 ...|
^
hole at a correct offset

2) 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")

Extents status tree is filled in with outdated offsets while doing
extent shift, that leads to wrong data blocks. That's why md5sum
of a result file is being checked after each block insert.

---

v2..v3:

1. Move test from ext3/023 to generic/403
2. Improve test and check md5 after each block insert.
3. Use get_block_size() helper function.
4. Use $seq.file instead of hardcoded test number.
5. Comments tweaks.

v1..v2:

'_require_xfs_io_command "finsert"' line was added to prevent the test to fail on "ext3", "bigalloc" and "bigalloc_1k" configurations.

 tests/generic/403     | 146 +++++++++++++++
 tests/generic/403.out | 499 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/generic/group   |   1 +
 3 files changed, 646 insertions(+)
 create mode 100755 tests/generic/403
 create mode 100644 tests/generic/403.out
tests/generic/403 new file +146 -0
new file mode 100755
index 000000000000..4087411e9f93
@@ -0,0 +1,146 @@
+#! /bin/bash
+# FS QA Test 403
+#
+# Regression test which targets two nasty ext4 bugs in a logic which
+# shifts extents:
+#
+# 1) 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
+#
+# An incorrect right shift (insert range) for the first extent in
+# a range.
+#
+# Test tries to insert many blocks at the same offset to reproduce
+# the following layout:
+#
+#    block #0  block #1
+#    |ext0 ext1|ext2 ext3 ...|
+#         ^
+#      insert of a new block
+#
+# Because of an incorrect range first block is never reached,
+# thus ext1 is untouched, resulting to a hole at a wrong offset:
+#
+# What we got:
+#
+#    block #0   block #1
+#    |ext0 ext1|   ext2 ext3 ...|
+#               ^
+#               hole at a wrong offset
+#
+# What we expect:
+#
+#    block #0    block #1
+#    |ext0   ext1|ext2 ext3 ...|
+#         ^
+#         hole at a correct offset
+#
+# 2) 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
+#
+# Extents status tree is filled in with outdated offsets while doing
+# extents shift, that leads to wrong data blocks.  That is why test
+# writes unique block content and checks md5sum of a result file after
+# each block insert.
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2017 Roman Penyaev.  All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+testfile=$TEST_DIR/$seq.file
+pattern=$tmp.pattern
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+	rm -f $testfile
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_xfs_io_command "finsert"
+
+blksize=`get_block_size $TEST_DIR`
+
+# Generate a block with a repeating number represented as 4 bytes decimal.
+# The test generates unique pattern for each block in order to observe a
+# wrong order if any.
+function generate_pattern() {
+	blkind=$1
+	printf "%04d" $blkind | awk  '{ while (c++ < '$(($blksize/4))') \
+		printf "%s", $0 }' > $pattern
+}
+
+$XFS_IO_PROG -f -c "falloc 0 $(($blksize * 2))" $testfile \
+			 >> $seqres.full 2>&1
+
+# First block, has 0001 as a pattern
+generate_pattern 1
+$XFS_IO_PROG -c "pwrite -i $pattern        0 $blksize" $testfile \
+			 >> $seqres.full 2>&1
+
+# Second block, has 0002 as a pattern
+generate_pattern 2
+$XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
+			 >> $seqres.full 2>&1
+
+# Insert 498 blocks after the first block.  We use this quite big
+# number to increase the reproduction probability.
+for (( block=3; block<=500; block++ )); do
+	$XFS_IO_PROG -c "finsert $blksize $blksize" $testfile \
+				 >> $seqres.full 2>&1
+
+	generate_pattern $block
+	$XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
+				 >> $seqres.full 2>&1
+
+	# Avoid offsets in hexdump output, because block size can vary.
+	# Here we check md5 after each insert to be sure that zero blocks
+	# do not appear, targets this commit:
+	#   14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
+	# or blocks are in correct order, this commit:
+	#   2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
+	#
+	md5=`hexdump -e '16/1 "%_p" "\n"' $testfile | md5sum`
+	printf "#%d %s\n" "$block" "$md5"
+done
+
+# Eventually output file has 500 blocks in the following order:
+#   0001 0500 0499 0498 ... 0002
+
+# success, all done
+status=0
+exit
tests/generic/403.out new file +499 -0

499 lines not on this page · raw message

tests/generic/group +1 -0
index fa207e587136..435fffa4943e 100644
@@ -405,3 +405,4 @@
 400 auto quick quota
 401 auto quick
 402 auto quick rw
+403 auto quick insert
Signature · 1 line
2.10.2
Applied
#1 lore raw
Quoted 30 lines · Roman Pen

Regression test which targets two nasty ext4 bugs in a logic which shifts extents:

1) 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")

Test tries to insert many blocks at the same offset to reproduce the following layout on ext4:

block #0 block #1
|ext0 ext1|ext2 ext3 ...|
^
insert of a new block

Because of an incorrect range first block is never reached, thus ext1 is untouched, resulting to a hole at a wrong offset:

What we got:

block #0 block #1
|ext0 ext1| ext2 ext3 ...|
^
hole at a wrong offset

What we expect:

block #0 block #1
|ext0 ext1|ext2 ext3 ...|
^
hole at a correct offset

Quoted 5 lines

2) 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")

Extents status tree is filled in with outdated offsets while doing
extent shift, that leads to wrong data blocks. That's why md5sum
of a result file is being checked after each block insert.

Thanks a lot! I did a minor update and queued it up.

Quoted 8 lines

---

tests/generic/403 line 96

Quoted 7 lines
tests/generic/403 new file +7 -0
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_xfs_io_command "finsert"
+
+blksize=`get_block_size $TEST_DIR`

I merged a patch earlier from Darrick to rename get_block_size to _get_block_size. So I did the rename here too.

Thanks,
Eryu

#2 lore raw
Quoted 47 lines · Eryu Guan
Quoted 30 lines · Roman Pen

Regression test which targets two nasty ext4 bugs in a logic which shifts extents:

1) 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")

Test tries to insert many blocks at the same offset to reproduce the following layout on ext4:

block #0 block #1
|ext0 ext1|ext2 ext3 ...|
^
insert of a new block

Because of an incorrect range first block is never reached, thus ext1 is untouched, resulting to a hole at a wrong offset:

What we got:

block #0 block #1
|ext0 ext1| ext2 ext3 ...|
^
hole at a wrong offset

What we expect:

block #0 block #1
|ext0 ext1|ext2 ext3 ...|
^
hole at a correct offset

Quoted 5 lines

2) 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")

Extents status tree is filled in with outdated offsets while doing
extent shift, that leads to wrong data blocks. That's why md5sum
of a result file is being checked after each block insert.

Thanks a lot! I did a minor update and queued it up.

Quoted 7 lines

---

Quoted 10 lines

tests/generic/403 line 96

Quoted 7 lines
tests/generic/403 new file +7 -0
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_xfs_io_command "finsert"
+
+blksize=`get_block_size $TEST_DIR`

I merged a patch earlier from Darrick to rename get_block_size to _get_block_size. So I did the rename here too.

Thanks. The only thing which worries me is those commits references. These patches are in Theodore's dev branch and I hope SHA1 wont be changed. Or maybe we have to postpone this new test till patches appear in mainline. I do not know.

--
Roman

#3 lore raw
Quoted 59 lines · Roman Penyaev
Quoted 47 lines · Eryu Guan
Quoted 30 lines · Roman Pen

Regression test which targets two nasty ext4 bugs in a logic which shifts extents:

1) 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")

Test tries to insert many blocks at the same offset to reproduce the following layout on ext4:

block #0 block #1
|ext0 ext1|ext2 ext3 ...|
^
insert of a new block

Because of an incorrect range first block is never reached, thus ext1 is untouched, resulting to a hole at a wrong offset:

What we got:

block #0 block #1
|ext0 ext1| ext2 ext3 ...|
^
hole at a wrong offset

What we expect:

block #0 block #1
|ext0 ext1|ext2 ext3 ...|
^
hole at a correct offset

Quoted 5 lines

2) 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")

Extents status tree is filled in with outdated offsets while doing
extent shift, that leads to wrong data blocks. That's why md5sum
of a result file is being checked after each block insert.

Thanks a lot! I did a minor update and queued it up.

Quoted 7 lines

---

Quoted 10 lines

tests/generic/403 line 96

Quoted 7 lines
tests/generic/403 new file +7 -0
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_xfs_io_command "finsert"
+
+blksize=`get_block_size $TEST_DIR`

I merged a patch earlier from Darrick to rename get_block_size to _get_block_size. So I did the rename here too.

Quoted 4 lines

Thanks. The only thing which worries me is those commits references. These patches are in Theodore's dev branch and I hope SHA1 wont be changed. Or maybe we have to postpone this new test till patches appear in mainline. I do not know.

Please cite the subject line of the patch alongside the hash.

e.g. 'This test accompanies 9a1f4e6 ("xfs: inflate colorful balloons").'

--D

Quoted 7 lines

--
Roman
--
To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html