This patch adds an option to test FITRIM even if it's not supported on $SCRATCH_DEV. Also introduces _create_loop_device and _destroy_loop_device functions to unify loopback handling. (depends on patch "Use upstream version of fstrim...") Signed-off-by: Tomas Racek <tracek@xxxxxxxxxx> --- 251 | 18 ++++++++++++++++-- 260 | 22 ++++++++++++++++++++-- common.rc | 14 ++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/251 b/251 index dbb6ba7..fb88f2a 100755 --- a/251 +++ b/251 @@ -51,13 +51,18 @@ _scratch_mount _cleanup() { rm -rf $tmp + if [ -n "$loop" ]; then + _scratch_unmount + _destroy_loop_device $loop + rm $img_file + fi } _destroy() { kill $pids $fstrim_pid 2> /dev/null wait $pids $fstrim_pid 2> /dev/null - rm -rf $tmp + _cleanup } _destroy_fstrim() @@ -153,7 +158,16 @@ content=$here # Check for FITRIM support echo -n "Checking FITRIM support: " -_test_batched_discard $SCRATCH_MNT || _notrun "FITRIM not supported on $SCRATCH_DEV" +if ! _test_batched_discard $SCRATCH_MNT; then + _scratch_unmount + img_file=$TEST_DIR/$$.fs + _require_fs_space $TEST_DIR 1048576 + $XFS_IO_PROG -f -c "truncate 1G" $img_file || _fail "Cannot allocate space for $img_file" + loop=$(_create_loop_device $img_file) + SCRATCH_DEV=$loop + _scratch_mkfs >/dev/null 2>&1 + _scratch_mount +fi echo "done." mkdir -p $tmp diff --git a/260 b/260 index ae4740a..cce5137 100755 --- a/260 +++ b/260 @@ -29,7 +29,7 @@ echo "QA output created by $seq" here=`pwd` tmp=`mktemp -d` status=0 -trap "exit \$status" 0 1 2 3 15 +trap "_cleanup; exit \$status" 0 1 3 chpid=0 mypid=$$ @@ -47,7 +47,25 @@ _require_scratch _scratch_mkfs >/dev/null 2>&1 _scratch_mount -_test_batched_discard $SCRATCH_MNT || _notrun "FITRIM not supported on $SCRATCH_DEV" +_cleanup() +{ + if [ -n "$loop" ]; then + _scratch_unmount + _destroy_loop_device $loop + rm $img_file + fi +} + +if ! _test_batched_discard $SCRATCH_MNT; then + _scratch_unmount + img_file=$TEST_DIR/$$.fs + _require_fs_space $TEST_DIR 1048576 + $XFS_IO_PROG -f -c "truncate 1G" $img_file || _fail "Cannot allocate space for $img_file" + loop=$(_create_loop_device $img_file) + SCRATCH_DEV=$loop + _scratch_mkfs >/dev/null 2>&1 + _scratch_mount +fi fssize=$(df -k | grep "$SCRATCH_MNT" | grep "$SCRATCH_DEV" | awk '{print $2}') diff --git a/common.rc b/common.rc index 966fc93..62b982b 100644 --- a/common.rc +++ b/common.rc @@ -1804,6 +1804,20 @@ _test_batched_discard() $FSTRIM_PROG ${1} &>/dev/null } +_create_loop_device() +{ + file=$1 + dev=`losetup -f` + losetup $dev $file || _fail "Cannot associate $file with $dev" + echo $dev +} + +_destroy_loop_device() +{ + dev=$1 + losetup -d $dev || _fail "Cannot destroy loop device $dev" +} + ################################################################################ if [ "$iam" != new -a "$iam" != bench ] -- 1.7.11.4 _______________________________________________ xfs mailing list xfs@xxxxxxxxxxx http://oss.sgi.com/mailman/listinfo/xfs