]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
xfs: refactor statfs field extraction
authorDarrick J. Wong <djwong@kernel.org>
Tue, 27 Aug 2024 18:46:54 +0000 (11:46 -0700)
committerZorro Lang <zlang@kernel.org>
Mon, 2 Sep 2024 20:50:28 +0000 (04:50 +0800)
Prepare for the next patch by refactoring the open-coded bits that call
statfs on a mounted xfs filesystem to extract a status field.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/xfs
tests/xfs/176
tests/xfs/187
tests/xfs/541

index 6370f175236b52654dfa335ee46a458005ea91ef..7ee6fbec84672b8a9f841770278054ca97224f64 100644 (file)
@@ -1818,3 +1818,9 @@ _require_xfs_parent()
                || _notrun "kernel does not support parent pointers"
        _scratch_unmount
 }
+
+# Extract a statfs attribute of the given mounted XFS filesystem.
+_xfs_statfs_field()
+{
+       $XFS_IO_PROG -c 'statfs' "$1" | grep -E "$2" | cut -d ' ' -f 3
+}
index db7001a5b9fd3393ce9b030c65fec0e18f63108b..8d58590fd9daaf80e46a20967ce5f447bc9d3b91 100755 (executable)
@@ -47,7 +47,7 @@ fi
 
 _scratch_mount
 _xfs_force_bdev data $SCRATCH_MNT
-old_dblocks=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep geom.datablocks)
+old_dblocks=$(_xfs_statfs_field "$SCRATCH_MNT" geom.datablocks)
 
 mkdir $SCRATCH_MNT/save/ $SCRATCH_MNT/urk/
 sino=$(stat -c '%i' $SCRATCH_MNT/save)
@@ -170,7 +170,7 @@ for ((ino = target_ino; ino >= icluster_ino; ino--)); do
        res=$?
 
        # Make sure shrink did not work
-       new_dblocks=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep geom.datablocks)
+       new_dblocks=$(_xfs_statfs_field "$SCRATCH_MNT" geom.datablocks)
        if [ "$new_dblocks" != "$old_dblocks" ]; then
                echo "should not have shrank $old_dblocks -> $new_dblocks"
                break
index 04ff9a81b6adbf0e03e362998374881116dff02b..56a9adc164eab258cf9793caea00919929453ed3 100755 (executable)
@@ -77,8 +77,8 @@ _xfs_force_bdev realtime $SCRATCH_MNT
 
 # Set the extent size hint larger than the realtime extent size.  This is
 # necessary to exercise the minlen constraints on the realtime allocator.
-fsbsize=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep geom.bsize | awk '{print $3}')
-rtextsize_blks=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep geom.rtextsize | awk '{print $3}')
+fsbsize=$(_xfs_statfs_field "$SCRATCH_MNT" geom.bsize)
+rtextsize_blks=$(_xfs_statfs_field "$SCRATCH_MNT" geom.rtextsize)
 extsize=$((2 * rtextsize_blks * fsbsize))
 
 echo "rtextsize_blks=$rtextsize_blks extsize=$extsize" >> $seqres.full
@@ -133,7 +133,7 @@ punch_off=$((bigfile_sz - frag_sz))
 $here/src/punch-alternating $SCRATCH_MNT/bigfile -o $((punch_off / fsbsize)) -i $((rtextsize_blks * 2)) -s $rtextsize_blks
 
 # Make sure we have some free rtextents.
-free_rtx=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | grep statfs.f_bavail | awk '{print $3}')
+free_rtx=$(_xfs_statfs_field "$SCRATCH_MNT" statfs.f_bavail)
 if [ $free_rtx -eq 0 ]; then
        echo "Expected fragmented free rt space, found none."
 fi
index f18b801cfec81faebfa6359aaefb8a2b0c4c68b8..518373fa8902266b92ead5e79dc8b04aebc7155f 100755 (executable)
@@ -81,13 +81,11 @@ test $grow_extszhint -eq 0 || \
        echo "expected post-grow extszhint 0, got $grow_extszhint"
 
 # Check that we now have rt extents.
-rtextents=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | \
-       grep 'geom.rtextents' | cut -d ' ' -f 3)
+rtextents=$(_xfs_statfs_field "$SCRATCH_MNT" geom.rtextents)
 test $rtextents -gt 0 || echo "expected rtextents > 0"
 
 # Check the new rt extent size.
-after_rtextsz_blocks=$($XFS_IO_PROG -c 'statfs' $SCRATCH_MNT | \
-       grep 'geom.rtextsize' | cut -d ' ' -f 3)
+after_rtextsz_blocks=$(_xfs_statfs_field "$SCRATCH_MNT" geom.rtextsize)
 test $after_rtextsz_blocks -eq $new_rtextsz_blocks || \
        echo "expected rtextsize $new_rtextsz_blocks, got $after_rtextsz_blocks"