summaryrefslogtreecommitdiff
path: root/common/xfs
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2022-10-28 10:42:05 -0700
committerZorro Lang <zlang@kernel.org>2022-10-30 18:39:20 +0800
commit898ace3b1835553a379822df7386f27961c9cdb3 (patch)
treed9906f202fff9f23179571dfacb88d0b456f4b94 /common/xfs
parente33f8bfd0d7042b403ab9560186d23d93593098a (diff)
xfs: refactor filesystem realtime geometry detection logic
There are a lot of places where we open-code detecting the realtime extent size and extent count of a specific filesystem. Refactor this into a couple of helpers to clean up the code. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Zorro Lang <zlang@redhat.com> Signed-off-by: Zorro Lang <zlang@kernel.org>
Diffstat (limited to 'common/xfs')
-rw-r--r--common/xfs31
1 files changed, 29 insertions, 2 deletions
diff --git a/common/xfs b/common/xfs
index 426297d0..a95f6349 100644
--- a/common/xfs
+++ b/common/xfs
@@ -174,6 +174,24 @@ _scratch_mkfs_xfs()
return $mkfs_status
}
+# Get the number of realtime extents of a mounted filesystem.
+_xfs_get_rtextents()
+{
+ local path="$1"
+
+ $XFS_INFO_PROG "$path" | grep 'rtextents' | \
+ sed -e 's/^.*rtextents=\([0-9]*\).*$/\1/g'
+}
+
+# Get the realtime extent size of a mounted filesystem.
+_xfs_get_rtextsize()
+{
+ local path="$1"
+
+ $XFS_INFO_PROG "$path" | grep 'realtime.*extsz' | \
+ sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g'
+}
+
# Get the size of an allocation unit of a file. Normally this is just the
# block size of the file, but for realtime files, this is the realtime extent
# size.
@@ -191,7 +209,7 @@ _xfs_get_file_block_size()
while ! $XFS_INFO_PROG "$path" &>/dev/null && [ "$path" != "/" ]; do
path="$(dirname "$path")"
done
- $XFS_INFO_PROG "$path" | grep realtime | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g'
+ _xfs_get_rtextsize "$path"
}
# Get the directory block size of a mounted filesystem.
@@ -427,13 +445,22 @@ _require_xfs_crc()
# third option is -v, echo 1 for success and 0 for not.
#
# Starting with xfsprogs 4.17, this also works for unmounted filesystems.
+# The feature 'realtime' looks for rtextents > 0.
_xfs_has_feature()
{
local fs="$1"
local feat="$2"
local verbose="$3"
+ local feat_regex="1"
+
+ case "$feat" in
+ "realtime")
+ feat="rtextents"
+ feat_regex="[1-9][0-9]*"
+ ;;
+ esac
- local answer="$($XFS_INFO_PROG "$fs" 2>&1 | grep -w -c "$feat=1")"
+ local answer="$($XFS_INFO_PROG "$fs" 2>&1 | grep -E -w -c "$feat=$feat_regex")"
if [ "$answer" -ne 0 ]; then
test "$verbose" = "-v" && echo 1
return 0