public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfstests: 251, 260: Use loopdev as fallback if $SCRATCH_DEV doesn't support FITRIM
@ 2012-10-09 15:20 Tomas Racek
  2012-10-09 19:42 ` Dave Chinner
  0 siblings, 1 reply; 2+ messages in thread
From: Tomas Racek @ 2012-10-09 15:20 UTC (permalink / raw)
  To: xfs; +Cc: lczerner, Tomas Racek

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@redhat.com>
---
 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@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xfstests: 251, 260: Use loopdev as fallback if $SCRATCH_DEV doesn't support FITRIM
  2012-10-09 15:20 [PATCH] xfstests: 251, 260: Use loopdev as fallback if $SCRATCH_DEV doesn't support FITRIM Tomas Racek
@ 2012-10-09 19:42 ` Dave Chinner
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Chinner @ 2012-10-09 19:42 UTC (permalink / raw)
  To: Tomas Racek; +Cc: lczerner, xfs

On Tue, Oct 09, 2012 at 05:20:00PM +0200, Tomas Racek wrote:
> 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.

That should be a separate patch.

> (depends on patch "Use upstream version of fstrim...")
> 
> Signed-off-by: Tomas Racek <tracek@redhat.com>

Write a new test that uses the loop device unconditionally and move
common functions into the relevant (or new) common.<foo> file.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-10-09 19:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-09 15:20 [PATCH] xfstests: 251, 260: Use loopdev as fallback if $SCRATCH_DEV doesn't support FITRIM Tomas Racek
2012-10-09 19:42 ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox