]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common/rc: Add helper to calculate percentage of free space available
authorLukas Herbolt <lukas@herbolt.com>
Thu, 14 May 2026 11:39:09 +0000 (13:39 +0200)
committerZorro Lang <zlang@kernel.org>
Fri, 15 May 2026 16:20:23 +0000 (00:20 +0800)
It calculates percentage of filesystem available space and returns it
in MB. This helper will be used in the following test/generic fixes.

Signed-off-by: Lukas Herbolt <lukas@herbolt.com>
Reviewed-by: Zorro Lang <zlang@kernel.org>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/rc

index 1acaf3535817a7226395a9c5009aa8e2c6556f60..79189e7e6e948728aff7e5c859ed69f5631c7573 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -6234,6 +6234,16 @@ _require_fanotify_ioerrors()
        _notrun "$FSTYP does not support fanotify ioerrors"
 }
 
+# Computes a percentage of the available space in a filesystem and
+# returns that quantity in MB. The percentage must not contain a percent
+# sign ("%").
+# usage example:
+# _mb_pct_of_available_space <mount point> <percent>
+#
+_mb_pct_of_available_space()
+{
+        _df_device $1 | $AWK_PROG -v pct=$2 '{printf "%.f", (($5*(pct/100))/1024)}'
+}
 ################################################################################
 # make sure this script returns success
 /bin/true