@@ -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
@@ -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)}'
+}
@@ -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
@@ -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")