]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
generic/{251,260}: compute maximum fitrim offset
authorDarrick J. Wong <djwong@kernel.org>
Thu, 30 Mar 2023 16:46:17 +0000 (09:46 -0700)
committerZorro Lang <zlang@kernel.org>
Thu, 6 Apr 2023 14:05:40 +0000 (22:05 +0800)
FITRIM is a bizarre ioctl.  Callers are allowed to pass in "start" and
"length" parameters, which are clearly some kind of range argument.  No
means is provided to discover the minimum or maximum range.  Although
regular userspace programs default to (start=0, length=-1ULL), this test
tries to exercise different parameters.

However, the test assumes that the "size" column returned by the df
command is the maximum value supported by the FITRIM command, and is
surprised if the number of bytes trimmed by (start=0, length=-1ULL) is
larger than this size quantity.

This is completely wrong on XFS with realtime volumes, because the
statfs output (which is what df reports) will reflect the realtime
volume if the directory argument is a realtime file or a directory
flagged with rtinherit.  This is trivially reproducible by configuring a
rt volume that is much larger than the data volume, setting rtinherit on
the root dir at mkfs time, and running either of these tests.

Refactor the open-coded df logic so that we can determine the value
programmatically for XFS.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/rc
common/xfs
tests/generic/251
tests/generic/260

index 9e4475c0f429fca666a3c898a2766e123ab5e149..e89b0a3794fc96a0fa9d84d5423924d7d069f4d7 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -3927,6 +3927,21 @@ _require_batched_discard()
        fi
 }
 
+# Given a mountpoint and the device associated with that mountpoint, return the
+# maximum start offset that the FITRIM command will accept, in units of 1024
+# byte blocks.
+_discard_max_offset_kb()
+{
+       case "$FSTYP" in
+       xfs)
+               _xfs_discard_max_offset_kb "$1"
+               ;;
+       *)
+               $DF_PROG -k | awk -v dev="$2" -v mnt="$1" '$1 == dev && $7 == mnt { print $3 }'
+               ;;
+       esac
+}
+
 _require_dumpe2fs()
 {
        if [ -z "$DUMPE2FS_PROG" ]; then
index e8e4832cea79ae24bb592dbfc9f086c7ac7dc923..c558e940cdf3e63a7e01d683d1bd76fe0ab820b7 100644 (file)
@@ -1783,3 +1783,11 @@ _require_xfs_scratch_atomicswap()
                _notrun "atomicswap dependencies not supported by scratch filesystem type: $FSTYP"
        _scratch_unmount
 }
+
+# Return the maximum start offset that the FITRIM command will accept, in units
+# of 1024 byte blocks.
+_xfs_discard_max_offset_kb()
+{
+       $XFS_IO_PROG -c 'statfs' "$1" | \
+               awk '{g[$1] = $3} END {print (g["geom.bsize"] * g["geom.datablocks"] / 1024)}'
+}
index 2a271cd126cd5ca6e01ade78ffc68a96d8b4ab94..8ee74980cc8d2d666a6670e45a84fdce58ecc7ce 100755 (executable)
@@ -71,7 +71,7 @@ _guess_max_minlen()
 fstrim_loop()
 {
        trap "_destroy_fstrim; exit \$status" 2 15
-       fsize=$($DF_PROG | grep $SCRATCH_MNT | grep $SCRATCH_DEV  | awk '{print $3}')
+       fsize=$(_discard_max_offset_kb "$SCRATCH_MNT" "$SCRATCH_DEV")
        mmlen=$(_guess_max_minlen)
 
        while true ; do
index 2f653b4af22df01ba2e31a2893a6ed36fc134cf7..08fde46873e3e13487842813b817ee31f21db093 100755 (executable)
@@ -27,7 +27,7 @@ _scratch_mount
 
 _require_batched_discard $SCRATCH_MNT
 
-fssize=$($DF_PROG -k | grep "$SCRATCH_MNT" | grep "$SCRATCH_DEV"  | awk '{print $3}')
+fssize=$(_discard_max_offset_kb "$SCRATCH_MNT" "$SCRATCH_DEV")
 
 beyond_eofs=$(_math "$fssize*2048")
 max_64bit=$(_math "2^64 - 1")