Skip to contentSkip to conversation

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

PATCH Superseded Namjae Jeon 1 participant 1 message Sep 2, 2013 VFS

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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