common: Create single function for testing xfs_io commands

Currently there are several function testing various xfs_io commands.
This commit creates _require_xfs_io_command() to test any xfs_command.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
This commit is contained in:
Lukas Czerner
2014-03-13 15:18:56 +11:00
committed by Dave Chinner
parent 9642986b9a
commit 212f48fdf5
+38 -34
View File
@@ -1296,12 +1296,43 @@ _user_do()
fi fi
} }
_require_xfs_io_command()
{
if [ $# -ne 1 ]
then
echo "Usage: _require_xfs_io_command command" 1>&2
exit 1
fi
command=$1
testfile=$TEST_DIR/$$.xfs_io
case $command in
"falloc" )
testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
;;
"fpunch" | "fcollapse" | "zero" )
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
-c "$command 4k 8k" $testfile 2>&1`
;;
"fiemap")
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
-c "fiemap -v" $testfile 2>&1`
;;
*)
testio=`$XFS_IO_PROG -c "$command help" 2>&1`
esac
rm -f $testfile 2>&1 > /dev/null
echo $testio | grep -q "not found" && \
_notrun "xfs_io $command support is missing"
echo $testio | grep -q "Operation not supported" && \
_notrun "xfs_io $command failed (old kernel/wrong fs?)"
}
# check that xfs_io, kernel, and filesystem all support zero # check that xfs_io, kernel, and filesystem all support zero
_require_xfs_io_zero() _require_xfs_io_zero()
{ {
testio=`$XFS_IO_PROG -c "zero help" 2>&1` _require_xfs_io_command "zero"
echo $testio | grep -q 'command "zero" not found' && \
_notrun "zero command not supported"
} }
# check that xfs_io, glibc, kernel, and filesystem all (!) support # check that xfs_io, glibc, kernel, and filesystem all (!) support
@@ -1309,54 +1340,27 @@ _require_xfs_io_zero()
# #
_require_xfs_io_falloc() _require_xfs_io_falloc()
{ {
testfile=$TEST_DIR/$$.falloc _require_xfs_io_command "falloc"
testio=`$XFS_IO_PROG -F -f -c "falloc 0 1m" $testfile 2>&1`
rm -f $testfile 2>&1 > /dev/null
echo $testio | grep -q "not found" && \
_notrun "xfs_io fallocate support is missing"
echo $testio | grep -q "Operation not supported" && \
_notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
} }
# check that xfs_io, kernel and filesystem all support fallocate with hole # check that xfs_io, kernel and filesystem all support fallocate with hole
# punching # punching
_require_xfs_io_falloc_punch() _require_xfs_io_falloc_punch()
{ {
testfile=$TEST_DIR/$$.falloc _require_xfs_io_command "fpunch"
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
-c "fpunch 4k 8k" $testfile 2>&1`
rm -f $testfile 2>&1 > /dev/null
echo $testio | grep -q "not found" && \
_notrun "xfs_io fallocate punch support is missing"
echo $testio | grep -q "Operation not supported" && \
_notrun "xfs_io fallocate punch command failed (no fs support?)"
} }
# check that xfs_io, kernel and filesystem all support fallocate with collapse # check that xfs_io, kernel and filesystem all support fallocate with collapse
# range # range
_require_xfs_io_falloc_collapse() _require_xfs_io_falloc_collapse()
{ {
testfile=$TEST_DIR/$$.falloc _require_xfs_io_command "fcollapse"
testio=`$XFS_IO_PROG -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 # check that xfs_io, kernel and filesystem support fiemap
_require_xfs_io_fiemap() _require_xfs_io_fiemap()
{ {
testfile=$TEST_DIR/$$.fiemap _require_xfs_io_command "fiemap"
testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
-c "fiemap -v" $testfile 2>&1`
rm -f $testfile 2>&1 > /dev/null
echo $testio | grep -q "not found" && \
_notrun "xfs_io fiemap support is missing"
echo $testio | grep -q "Operation not supported" && \
_notrun "xfs_io fiemap command failed (no fs support?)"
} }
# Check that a fs has enough free space (in 1024b blocks) # Check that a fs has enough free space (in 1024b blocks)