Skip to contentSkip to conversation

xfstest: Add test case to check various corner cases for collapsing range

PATCH RESEND Superseded Namjae Jeon 2 participants 3 messages Oct 6, 2013 – Oct 10, 2013 VFS

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 5/7 xfstest: Add test case to check various corner cases for collapsing range

From: Namjae Jeon <[email protected]>

This patch checks various corner cases for collapsing a range. This patch is based on generic/255 test case which checks various corner cases for punch hole.

---
 common/collapse      |  264 ++++++++++++++++++++++++++++++++++++++++++++++++++
 common/rc            |   14 +++
 tests/shared/316     |   70 +++++++++++++
 tests/shared/316.out |  221 ++++++++++++++++++++++++++++++++++++++++++
 tests/shared/group   |    2 +-
 5 files changed, 570 insertions(+), 1 deletion(-)
 create mode 100644 common/collapse
 create mode 100644 tests/shared/316
 create mode 100644 tests/shared/316.out
common/collapse new file +264 -0
new file mode 100644
index 0000000..dd3be5e
@@ -0,0 +1,264 @@
+##/bin/bash
+#
+# Copyright (c) 2013 Samsung Electronics.  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
+#
+# Test procedure for checking collapse range feature
+
+# Test different corner cases for collapsing a range:
+#
+#	1. into a hole
+#	2. into allocated space
+#	3. into unwritten space
+#	4. hole -> data
+#	5. hole -> unwritten
+#	6. data -> hole
+#	7. data -> unwritten
+#	8. unwritten -> hole
+#	9. unwritten -> data
+#	10. hole -> data -> hole
+#	11. data -> hole -> data
+#	12. unwritten -> data -> unwritten
+#	13. data -> unwritten -> data
+#	14. data -> hole @ EOF
+#	15. data -> hole @ 0
+#	16. data -> cache cold ->hole
+#
+# Test file is removed, created and sync'd between tests.
+#
+# Use -k flag to keep the file between tests.  This will
+# test the handling of pre-existing holes.
+#
+# Use the -d flag to not sync the file between tests.
+# This will test the handling of delayed extents
+#
+_test_generic_collapse()
+{
+
+	remove_testfile=1
+	sync_cmd="-c fsync"
+	OPTIND=1
+	while getopts 'dk' OPTION
+	do
+		case $OPTION in
+		k)	remove_testfile=
+		;;
+		d)	sync_cmd=
+		;;
+		?)	echo Invalid flag
+		exit 1
+		;;
+		esac
+	done
+	shift $(($OPTIND - 1))
+
+	alloc_cmd=$1
+	collapse_cmd=$2
+	punch_cmd=$3
+	map_cmd=$4
+	filter_cmd=$5
+	testfile=$6
+
+	echo "	1. into a hole"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	2. into allocated space"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "pwrite 0 80k" $sync_cmd \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	3. into unwritten space"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "$alloc_cmd 0 80k" \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	4. hole -> data"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "pwrite 32k 32k" $sync_cmd \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	5. hole -> unwritten"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "$alloc_cmd 32k 32k" \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	6. data -> hole"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "pwrite 0 32k" $sync_cmd \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	7. data -> unwritten"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "pwrite 0 32k" $sync_cmd \
+		-c "$alloc_cmd 32k 32k" \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	8. unwritten -> hole"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "$alloc_cmd 0 32k" \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	9. unwritten -> data"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "$alloc_cmd 0 32k" \
+		-c "pwrite 32k 32k" $sync_cmd \
+		-c "$collapse_cmd 16k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	10. hole -> data -> hole"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "pwrite 32k 16k" $sync_cmd \
+		-c "$collapse_cmd 16k 48k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	11. data -> hole -> data"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "$alloc_cmd 0 80k" \
+		-c "pwrite 0 32k" \
+		-c "pwrite 48k 32k" $sync_cmd \
+		-c "$punch_cmd 32k 16k" \
+		-c "$collapse_cmd 8k 48k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	12. unwritten -> data -> unwritten"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "$alloc_cmd 0 80k" \
+		-c "pwrite 32k 16k" $sync_cmd \
+		-c "$collapse_cmd 16k 48k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	13. data -> unwritten -> data"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "$alloc_cmd 0 80k" \
+		-c "pwrite 0k 32k" $sync_cmd \
+		-c "pwrite 48k 32k" -c "fsync" \
+		-c "$collapse_cmd 16k 48k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	14. data -> hole @ EOF"
+	rm -f $testfile
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "pwrite 0 80k" $sync_cmd \
+		-c "$collapse_cmd 48k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	15. data -> hole @ 0"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+	fi
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "pwrite 0 80k" $sync_cmd \
+		-c "$collapse_cmd 0k 32k" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	[ $? -ne 0 ] && die_now
+	_md5_checksum $testfile
+
+	echo "	16. data -> cache cold ->hole"
+	if [ "$remove_testfile" ]; then
+		rm -f $testfile
+		rm -f $testfile.2
+	else
+		cp $testfile $testfile.2
+	fi
+	$XFS_IO_PROG -f -c "truncate 48k" \
+		-c "pwrite 0k 48k" -c "fsync" $testfile.2 \
+		> /dev/null
+	$XFS_IO_PROG -f -c "truncate 80k" \
+		-c "pwrite 0 80k" $sync_cmd \
+		-c "$collapse_cmd 0k 32k" \
+		-c "fadvise -d" \
+		-c "$map_cmd -v" $testfile | $filter_cmd
+	diff $testfile $testfile.2
+	[ $? -ne 0 ] && die_now
+	rm -f $testfile.2
+	_md5_checksum $testfile
+
+}
common/rc +14 -0
index 77e96c4..1779eed 100644
@@ -1248,6 +1248,20 @@ _require_xfs_io_falloc_punch()
 		_notrun "xfs_io fallocate punch command failed (no fs support?)"
 }
 
+# check that xfs_io, kernel and filesystem all support fallocate with collapse
+# range
+_require_xfs_io_falloc_collapse()
+{
+	testfile=$TEST_DIR/$$.falloc
+	testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
+		-c "fcollapse 4k 8k" $testfile 2>&1`
+	rm -f $testfile 2>&1 > /dev/null
+	echo $testio | grep -q "not found" && \
+		_notrun "xfs_io fallocate collapse range support is missing"
+	echo $testio | grep -q "Operation not supported" && \
+		_notrun "xfs_io fallocate collapse range failed (no fs support?)"
+}
+
 # check that xfs_io, kernel and filesystem support fiemap
 _require_xfs_io_fiemap()
 {
tests/shared/316 new file +70 -0

70 lines not on this page · raw message

tests/shared/316.out new file +221 -0

221 lines not on this page · raw message

tests/shared/group +1 -1
index 0ad640b..3a69294 100644
@@ -11,4 +11,4 @@
 289 auto quick
 298 auto trim
 305 aio dangerous enospc rw stress
-
+316 auto quick collapse
Signature · 6 lines
1.7.9.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 63 lines · Namjae Jeon

From: Namjae Jeon <[email protected]>

This patch checks various corner cases for collapsing a range. This patch is based on generic/255 test case which checks various corner cases for punch hole.

---
 common/collapse      |  264 ++++++++++++++++++++++++++++++++++++++++++++++++++
 common/rc            |   14 +++
 tests/shared/316     |   70 +++++++++++++
 tests/shared/316.out |  221 ++++++++++++++++++++++++++++++++++++++++++
 tests/shared/group   |    2 +-
 5 files changed, 570 insertions(+), 1 deletion(-)
 create mode 100644 common/collapse
 create mode 100644 tests/shared/316
 create mode 100644 tests/shared/316.out
common/collapse new file +38 -0
new file mode 100644
index 0000000..dd3be5e
@@ -0,0 +1,264 @@
+##/bin/bash
+#
+# Copyright (c) 2013 Samsung Electronics.  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
+#
+# Test procedure for checking collapse range feature
+
+# Test different corner cases for collapsing a range:
+#
+#	1. into a hole
+#	2. into allocated space
+#	3. into unwritten space
+#	4. hole -> data
+#	5. hole -> unwritten
+#	6. data -> hole
+#	7. data -> unwritten
+#	8. unwritten -> hole
+#	9. unwritten -> data
+#	10. hole -> data -> hole
+#	11. data -> hole -> data
+#	12. unwritten -> data -> unwritten
+#	13. data -> unwritten -> data
+#	14. data -> hole @ EOF
+#	15. data -> hole @ 0
+#	16. data -> cache cold ->hole
+#

common/collapse line 48

Quoted 10 lines
common/collapse new file +10 -0
+# Test file is removed, created and sync'd between tests.
+#
+# Use -k flag to keep the file between tests.  This will
+# test the handling of pre-existing holes.
+#
+# Use the -d flag to not sync the file between tests.
+# This will test the handling of delayed extents
+#
+_test_generic_collapse()
+{

This function is just a copy and paste of _test_generic_punch() with all the ranges increased by a factor of 4. Why can't you simply use _test_generic_punch() and pass in a different $zero_cmd?

common/collapse line 55

Quoted 8 lines
common/collapse new file +7 -0
+# check that xfs_io, kernel and filesystem all support fallocate with collapse
+# range
+_require_xfs_io_falloc_collapse()
+{
+	testfile=$TEST_DIR/$$.falloc
+	testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
+		-c "fcollapse 4k 8k" $testfile 2>&1`

No need for the -F parameter anymore.

tests/shared/316

Quoted 15 lines
common/collapse new file +7 -0
+	rm -f $testfile 2>&1 > /dev/null
+	echo $testio | grep -q "not found" && \
+		_notrun "xfs_io fallocate collapse range support is missing"
+	echo $testio | grep -q "Operation not supported" && \
+		_notrun "xfs_io fallocate collapse range failed (no fs support?)"
+}
+
 # check that xfs_io, kernel and filesystem support fiemap
 _require_xfs_io_fiemap()
 {
tests/shared/316 new file +0 -0
new file mode 100644
index 0000000..66a8489

You don't need to number this 316. shared/001 is not taken, so start there....

tests/shared/316 line 4

Quoted 5 lines
tests/shared/316 new file +4 -0
@@ -0,0 +1,70 @@
+#! /bin/bash
+# FS QA Test No. 316
+#
+# Test fallocate collapse range

A more verbose test description is preferred. A paragraph describing that the test exercises boundary conditions across different extent types for the FALLOC_FL_COLLAPSE_RANGE operation would be ideal.

Quoted 9 lines
tests/shared/316 new file +9 -0
+trap "_cleanup ; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+# we need to include common/punch to get defination fo filter functions
+. ./common/rc
+. ./common/filter
+. ./common/punch
+. ./common/collapse
+

tests/shared/316 line 56

Quoted 10 lines
tests/shared/316 new file +10 -0
+# real QA test starts here
+_supported_fs xfs ext4
+_supported_os Linux
+
+_require_xfs_io_falloc_punch
+_require_xfs_io_falloc
+_require_xfs_io_fiemap
+_require_xfs_io_falloc_collapse
+
+testfile=$TEST_DIR/316.$$

If you are going to use the test number to identify the file, you should use $seq rather than hard coding the number....

tests/shared/316 line 68

Quoted 11 lines
tests/shared/316 new file +11 -0
+# Standard collapse range tests
+_test_generic_collapse falloc fcollapse fpunch fiemap _filter_hole_fiemap $testfile
+
+# Delayed allocation collapse range tests
+_test_generic_collapse -d falloc fcollapse fpunch fiemap _filter_hole_fiemap $testfile
+
+# Multi collapse tests
+_test_generic_collapse -k falloc fcollapse fpunch fiemap _filter_hole_fiemap $testfile
+
+# Delayed allocation multi collapse range tests
+_test_generic_collapse -d -k falloc fcollapse fpunch fiemap _filter_hole_fiemap $testfile

What I'd prefer is each of these is a separate unit test. i.e:

shared/001: Standard collapse range tests shared/002: Delayed allocation collapse range tests shared/003: Multi collapse tests
shared/004: Delayed allocation multi collapse range tests

The reason for doing this is that it means that:

a) we can track failures of the different types of tests independently; and
b) the filesystem the tests are being run on is checked for consistency between each test

I know, the punch tests you copied this from lump them all into the one test, but I'd really like to get away from the complex tests that aggregate lots of different things into a single pass/fail test as it makes it hard to isolate failures and track them over the long term...

tests/shared/316 line 36

Quoted 2 lines
tests/shared/316 new file +2 -0
+
+status=0 ; exit

separate lines

tests/shared/group line 14

Quoted 10 lines
tests/shared/group +1 -1
index 0ad640b..3a69294 100644
@@ -11,4 +11,4 @@
 289 auto quick
 298 auto trim
 305 aio dangerous enospc rw stress
-
+316 auto quick collapse

I'd put this in the prealloc group rather than create a new one called "collapse".

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#2 lore raw
Quoted 7 lines

common/collapse line 48

Quoted 3 lines
common/collapse new file +3 -0
+#
+_test_generic_collapse()
+{

This function is just a copy and paste of _test_generic_punch() with all the ranges increased by a factor of 4. Why can't you simply use _test_generic_punch() and pass in a different $zero_cmd?

Yes, you're right. We can use test_generic_punch as you said. I will update.

Quoted 12 lines

common/rc _require_xfs_io_falloc_punch() · line 1257

Quoted 10 lines
common/rc +7 -0
+# check that xfs_io, kernel and filesystem all support fallocate with collapse
+# range
+_require_xfs_io_falloc_collapse()
+{
+     testfile=$TEST_DIR/$$.falloc
+     testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
+             -c "fcollapse 4k 8k" $testfile 2>&1`

No need for the -F parameter anymore.

Okay.

Quoted 11 lines
Quoted 11 lines
common/rc +7 -0
+     rm -f $testfile 2>&1 > /dev/null
+     echo $testio | grep -q "not found" && \
+             _notrun "xfs_io fallocate collapse range support is missing"
+     echo $testio | grep -q "Operation not supported" && \
+             _notrun "xfs_io fallocate collapse range failed (no fs support?)"
+}
+
 # check that xfs_io, kernel and filesystem support fiemap
 _require_xfs_io_fiemap()
 {
Quoted 8 lines

tests/shared/316

Quoted 5 lines
tests/shared/316 new file +0 -0
new file mode 100644
index 0000000..66a8489

You don't need to number this 316. shared/001 is not taken, so start there....

okay.

Quoted 10 lines

tests/shared/316 line 4

Quoted 6 lines
tests/shared/316 new file +4 -0
@@ -0,0 +1,70 @@
+#! /bin/bash
+# FS QA Test No. 316
+#
+# Test fallocate collapse range

A more verbose test description is preferred. A paragraph describing that the test exercises boundary conditions across different extent types for the FALLOC_FL_COLLAPSE_RANGE operation would be ideal.

Okay.

Quoted 15 lines
Quoted 15 lines
tests/shared/316 new file +14 -0
+trap "_cleanup ; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+# we need to include common/punch to get defination fo filter functions
+. ./common/rc
+. ./common/filter
+. ./common/punch
+. ./common/collapse
+
+# real QA test starts here
+_supported_fs xfs ext4
+_supported_os Linux
+
+_require_xfs_io_falloc_punch
Quoted 8 lines

tests/shared/316 line 56

Quoted 5 lines
tests/shared/316 new file +5 -0
+_require_xfs_io_falloc
+_require_xfs_io_fiemap
+_require_xfs_io_falloc_collapse
+
+testfile=$TEST_DIR/316.$$

If you are going to use the test number to identify the file, you should use $seq rather than hard coding the number....

Okay.

Quoted 27 lines

tests/shared/316 line 68

Quoted 12 lines
tests/shared/316 new file +11 -0
+# Standard collapse range tests
+_test_generic_collapse falloc fcollapse fpunch fiemap _filter_hole_fiemap $testfile
+
+# Delayed allocation collapse range tests
+_test_generic_collapse -d falloc fcollapse fpunch fiemap _filter_hole_fiemap $testfile
+
+# Multi collapse tests
+_test_generic_collapse -k falloc fcollapse fpunch fiemap _filter_hole_fiemap $testfile
+
+# Delayed allocation multi collapse range tests
+_test_generic_collapse -d -k falloc fcollapse fpunch fiemap _filter_hole_fiemap $testfile

What I'd prefer is each of these is a separate unit test. i.e:

shared/001: Standard collapse range tests shared/002: Delayed allocation collapse range tests shared/003: Multi collapse tests
shared/004: Delayed allocation multi collapse range tests

The reason for doing this is that it means that:

a) we can track failures of the different types of tests independently; and
b) the filesystem the tests are being run on is checked for consistency between each test

Quoted 6 lines

I know, the punch tests you copied this from lump them all into the one test, but I'd really like to get away from the complex tests that aggregate lots of different things into a single pass/fail test as it makes it hard to isolate failures and track them over the long term...

Okay, I will do it as your suggestion.

Quoted 5 lines

tests/shared/316 line 36

Quoted 2 lines
tests/shared/316 new file +2 -0
+
+status=0 ; exit

separate lines

Quoted 13 lines

tests/shared/group line 14

Quoted 10 lines
tests/shared/group +1 -1
index 0ad640b..3a69294 100644
@@ -11,4 +11,4 @@
 289 auto quick
 298 auto trim
 305 aio dangerous enospc rw stress
-
+316 auto quick collapse

I'd put this in the prealloc group rather than create a new one called "collapse".

Okay.

Thanks for review.

Quoted 7 lines

Cheers,

Dave.
--
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs