Skip to contentSkip to conversation

xfstests: Use upstream version of fstrim instead of the local one

PATCH Superseded Tomas Racek 2 participants 2 messages Aug 14, 2012

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfstests: Use upstream version of fstrim instead of the local one

Local version of fstrim was dropped so that we depend on upstream version now. _require_fstrim was added to check if fstrim is available in the system and _test_batched_discard to check if we can run fstrim on certain mountpoint.

Also tests 251 and 260 were modified to reflect this change.

---
 .gitignore   |    1 -
 251          |   14 +--
 260          |   36 +++++----
 260.out      |    8 +-
 common.rc    |   11 +++
 src/Makefile |    2 +-
 src/fstrim.c |  257 ----------------------------------------------------------
 7 files changed, 42 insertions(+), 287 deletions(-)
 delete mode 100644 src/fstrim.c
.gitignore +0 -1
index 900ff95..c0e0e4c 100644
@@ -37,7 +37,6 @@ src/fill
 src/fill2
 src/fs_perms
 src/fstest
-src/fstrim
 src/ftrunc
 src/genhashnames
 src/getdevicesize
251 +5 -9
index f46b6e2..cee6735 100755
@@ -44,6 +44,7 @@ mypid=$$
 _supported_fs generic
 _supported_os Linux
 _require_scratch
+_require_fstrim
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount
 
@@ -71,16 +72,11 @@ _fail()
 	kill $mypid 2> /dev/null
 }
 
-_check_fstrim_support()
-{
-	$here/src/fstrim -l 10M $SCRATCH_MNT &> /dev/null
-}
-
 _guess_max_minlen()
 {
 	mmlen=100000
 	while [ $mmlen -gt 1 ]; do
-		$here/src/fstrim -l $(($mmlen*2))k -m ${mmlen}k $SCRATCH_MNT &> /dev/null && break
+		fstrim -l $(($mmlen*2))k -m ${mmlen}k $SCRATCH_MNT &> /dev/null && break
 		mmlen=$(($mmlen/2))
 	done
 	echo $mmlen
@@ -102,12 +98,12 @@ fstrim_loop()
 		minlen=$(((RANDOM*($RANDOM%2+1))%$mmlen))
 		start=$RANDOM
 		if [ $((RANDOM%10)) -gt 7 ]; then
-			$here/src/fstrim $SCRATCH_MNT &
+			fstrim $SCRATCH_MNT &
 			fpid=$!
 			wait $fpid
 		fi
 		while [ $start -lt $fsize ] ; do
-			$here/src/fstrim -m ${minlen}k -s ${start}k -l ${step}k $SCRATCH_MNT &
+			fstrim -m ${minlen}k -o ${start}k -l ${step}k $SCRATCH_MNT &
 			fpid=$!
 			wait $fpid
 			start=$(( $start + $step ))
@@ -157,7 +153,7 @@ content=$here
 
 # Check for FITRIM support
 echo -n "Checking FITRIM support: "
-_check_fstrim_support || _notrun "FSTRIM is not supported"
+_test_batched_discard $SCRATCH_MNT || _notrun "FITRIM not supported on $SCRATCH_DEV"
 echo "done."
 
 mkdir -p $tmp
260 +21 -15
index b005cd3..9a769ba 100755
@@ -41,13 +41,13 @@ mypid=$$
 _supported_fs generic
 _supported_os Linux
 _require_math
+_require_fstrim
 
 _require_scratch
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount
 
-FSTRIM="$here/src/fstrim"
-"$FSTRIM" -l 10M $SCRATCH_MNT &> /dev/null || _notrun "FSTRIM is not supported"
+_test_batched_discard $SCRATCH_MNT || _notrun "FITRIM not supported on $SCRATCH_DEV"
 
 fssize=$(df -k | grep "$SCRATCH_MNT" | grep "$SCRATCH_DEV"  | awk '{print $2}')
 
@@ -59,20 +59,24 @@ max_64bit=$(_math "2^64 - 1")
 # the file system
 
 echo "[+] Start beyond the end of fs (should fail)"
-"$FSTRIM" -s $beyond_eofs $SCRATCH_MNT
+out=$(fstrim -o $beyond_eofs $SCRATCH_MNT 2>&1)
 [ $? -eq 0 ] && status=1
+echo -n $out | cut -d ":" -f3-
 
 echo "[+] Start beyond the end of fs with len set (should fail)"
-"$FSTRIM" -s $beyond_eofs -l1M $SCRATCH_MNT
+out=$(fstrim -o $beyond_eofs -l1M $SCRATCH_MNT 2>&1)
 [ $? -eq 0 ] && status=1
+echo -n $out | cut -d ":" -f3-
 
 echo "[+] Start = 2^64-1 (should fail)"
-"$FSTRIM" -s $max_64bit $SCRATCH_MNT
+out=$(fstrim -o $max_64bit $SCRATCH_MNT 2>&1)
 [ $? -eq 0 ] && status=1
+echo -n $out | cut -d ":" -f3-
 
 echo "[+] Start = 2^64-1 and len is set (should fail)"
-"$FSTRIM" -s $max_64bit -l1M $SCRATCH_MNT
+out=$(fstrim -o $max_64bit -l1M $SCRATCH_MNT 2>&1)
 [ $? -eq 0 ] && status=1
+echo -n $out | cut -d ":" -f3-
 
 _scratch_unmount
 _scratch_mkfs >/dev/null 2>&1
@@ -82,16 +86,16 @@ _scratch_mount
 # since the length should be truncated
 
 echo "[+] Default length (should succeed)"
-"$FSTRIM" $SCRATCH_MNT
+fstrim $SCRATCH_MNT
 [ $? -ne 0 ] && status=1
 echo "[+] Default length with start set (should succeed)"
-"$FSTRIM" -s10M $SCRATCH_MNT
+fstrim -o10M $SCRATCH_MNT
 [ $? -ne 0 ] && status=1
 echo "[+] Length beyond the end of fs (should succeed)"
-"$FSTRIM" -l $beyond_eofs $SCRATCH_MNT
+fstrim -l $beyond_eofs $SCRATCH_MNT
 [ $? -ne 0 ] && status=1
 echo "[+] Length beyond the end of fs with start set (should succeed)"
-"$FSTRIM" -s10M -l $beyond_eofs $SCRATCH_MNT
+fstrim -o10M -l $beyond_eofs $SCRATCH_MNT
 [ $? -ne 0 ] && status=1
 
 _scratch_unmount
@@ -101,8 +105,9 @@ _scratch_mount
 # This is a bit fuzzy, but since the file system is fresh
 # there should be at least (fssize/2) free space to trim.
 # This is supposed to catch wrong FITRIM argument handling
-out=$("$FSTRIM" -v -s10M $SCRATCH_MNT)
-bytes=${out%% *}
+out=$(fstrim -v -o10M $SCRATCH_MNT)
+nopref=${out##*: }
+bytes=${nopref%% *}
 
 if [ $bytes -gt $(_math "$fssize*1024") ]; then
 	status=1
@@ -155,7 +160,7 @@ _scratch_unmount
 _scratch_mkfs >/dev/null 2>&1
 _scratch_mount
 # It should fail since $start is beyond the end of file system
-"$FSTRIM" -s$start -l10M $SCRATCH_MNT &> /dev/null
+fstrim -o$start -l10M $SCRATCH_MNT &> /dev/null
 if [ $? -eq 0 ]; then
 	status=1
 	echo "It seems that fs logic handling start"\
@@ -173,8 +178,9 @@ _scratch_mount
 # It is because btrfs does not have not-yet-used parts of the device
 # mapped and since we got here right after the mkfs, there is not
 # enough free extents in the root tree.
-out=$("$FSTRIM" -v -l$len $SCRATCH_MNT)
-bytes=${out%% *}
+out=$(fstrim -v -l$len $SCRATCH_MNT)
+nopref=${out##*: }
+bytes=${nopref%% *}
 if [ $bytes -le $(_math "$fssize*512") ] && [ $FSTYP != "btrfs" ]; then
 	status=1
 	echo "It seems that fs logic handling len argument overflows"
260.out +4 -4
index 199320a..cf0b14e 100644
@@ -1,12 +1,12 @@
 QA output created by 260
 [+] Start beyond the end of fs (should fail)
-fstrim: FSTRIM: Invalid argument
+ FITRIM ioctl failed: Invalid argument
 [+] Start beyond the end of fs with len set (should fail)
-fstrim: FSTRIM: Invalid argument
+ FITRIM ioctl failed: Invalid argument
 [+] Start = 2^64-1 (should fail)
-fstrim: FSTRIM: Invalid argument
+ FITRIM ioctl failed: Invalid argument
 [+] Start = 2^64-1 and len is set (should fail)
-fstrim: FSTRIM: Invalid argument
+ FITRIM ioctl failed: Invalid argument
 [+] Default length (should succeed)
 [+] Default length with start set (should succeed)
 [+] Length beyond the end of fs (should succeed)
common.rc +11 -0
index 602513a..1836c27 100644
@@ -1778,6 +1778,17 @@ _devmgt_add()
 	echo ${tdl} >  /sys/class/scsi_host/host${h}/scan || _fail "Add disk failed"
 }
 
+_require_fstrim()
+{
+	which fstrim &>/dev/null || _notrun "This test requires fstrim utility."
+}
+
+_test_batched_discard()
+{
+	_require_fstrim
+	fstrim ${1} &>/dev/null
+}
+
 ################################################################################
 
 if [ "$iam" != new -a "$iam" != bench ]
src/Makefile +1 -1
index 67250ee..9671a38 100644
@@ -17,7 +17,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \
 	locktest unwritten_mmap bulkstat_unlink_test t_stripealign \
 	bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \
-	stale_handle pwrite_mmap_blocked fstrim t_dir_offset2
+	stale_handle pwrite_mmap_blocked t_dir_offset2
 
 SUBDIRS =
 
src/fstrim.c deleted +0 -257

257 lines not on this page · raw message

Signature · 6 lines
1.7.7.6

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

Local version of fstrim was dropped so that we depend on upstream version now. _require_fstrim was added to check if fstrim is available in the system and _test_batched_discard to check if we can run fstrim on certain mountpoint.

Also tests 251 and 260 were modified to reflect this change.

Looks OK, but the only thing I'd suggest is using a $FSTRIM_PROG variable rather than fsttrim directly. see how $XFS_IO_PROG is set up in common.rc and copy that.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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