]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
xfs: refactor filesystem realtime geometry detection logic
authorDarrick J. Wong <djwong@kernel.org>
Fri, 28 Oct 2022 17:42:05 +0000 (10:42 -0700)
committerZorro Lang <zlang@kernel.org>
Sun, 30 Oct 2022 10:39:20 +0000 (18:39 +0800)
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>
common/populate
common/xfs
tests/xfs/146
tests/xfs/147
tests/xfs/530

index 23b2fecf695afc3deee0e2cfed74493cd678857b..d9d4c6c3002e0a34ee5aee542dedaa1db604d29a 100644 (file)
@@ -323,7 +323,7 @@ _scratch_xfs_populate() {
        fi
 
        # Realtime Reverse-mapping btree
-       is_rt="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep -c 'rtextents=[1-9]')"
+       is_rt="$(_xfs_get_rtextents "$SCRATCH_MNT")"
        if [ $is_rmapbt -gt 0 ] && [ $is_rt -gt 0 ]; then
                echo "+ rtrmapbt btree"
                nr="$((blksz * 2 / 32))"
index 426297d0c0ddbdb075d009c26f05f0c49ee67088..a95f63499ff66414618cf1d17076140033c34e6d 100644 (file)
@@ -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
index 5516d396bf7189e186cbb62f04a92d62b56c00c6..123bdff59f7797421532a1cbf30adb5082ef6fc4 100755 (executable)
@@ -31,7 +31,7 @@ _scratch_mkfs > $seqres.full
 _scratch_mount >> $seqres.full
 
 blksz=$(_get_block_size $SCRATCH_MNT)
-rextsize=$($XFS_INFO_PROG $SCRATCH_MNT | grep realtime.*extsz | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g')
+rextsize=$(_xfs_get_rtextsize "$SCRATCH_MNT")
 rextblks=$((rextsize / blksz))
 
 echo "blksz $blksz rextsize $rextsize rextblks $rextblks" >> $seqres.full
index e21fdd330cb35314dcf2837d14465378fd57cd63..33b3c99633cfe29aed64ccca1acb1e2bb040703b 100755 (executable)
@@ -29,7 +29,7 @@ _scratch_mkfs -r extsize=256k > $seqres.full
 _scratch_mount >> $seqres.full
 
 blksz=$(_get_block_size $SCRATCH_MNT)
-rextsize=$($XFS_INFO_PROG $SCRATCH_MNT | grep realtime.*extsz | sed -e 's/^.*extsz=\([0-9]*\).*$/\1/g')
+rextsize=$(_xfs_get_rtextsize "$SCRATCH_MNT")
 rextblks=$((rextsize / blksz))
 
 echo "blksz $blksz rextsize $rextsize rextblks $rextblks" >> $seqres.full
index c960738db7f12687f27fce3941d97fce92046f92..56f5e7ebdbdba34f309272bb0c5da7fd30e8e9b0 100755 (executable)
@@ -73,8 +73,7 @@ _try_scratch_mount || _notrun "Couldn't mount fs with synthetic rt volume"
 formatted_blksz="$(_get_block_size $SCRATCH_MNT)"
 test "$formatted_blksz" -ne "$dbsize" && \
        _notrun "Tried to format with $dbsize blocksize, got $formatted_blksz."
-$XFS_INFO_PROG $SCRATCH_MNT | grep -E -q 'realtime.*blocks=0' && \
-       _notrun "Filesystem should have a realtime volume"
+_require_xfs_has_feature "$SCRATCH_MNT" realtime
 
 echo "Consume free space"
 fillerdir=$SCRATCH_MNT/fillerdir