]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common/btrfs: add _btrfs_get_fsid() helper
authorAnand Jain <anand.jain@oracle.com>
Wed, 8 Nov 2023 04:28:57 +0000 (12:28 +0800)
committerZorro Lang <zlang@kernel.org>
Thu, 16 Nov 2023 02:52:12 +0000 (10:52 +0800)
We have two instances of reading the btrfs fsid by using the command
'btrfs filesystem show <mnt>' turn this into an easy-to-use helper
function and also use it.

Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/btrfs
common/rc

index fbc26181f7bc5e487d48caa1eca45fcd8ca5230f..f91f8dd869a1ce2f84c0c7e91013549dfc0be67f 100644 (file)
@@ -457,13 +457,23 @@ _scratch_btrfs_is_zoned()
        return 1
 }
 
-_require_btrfs_sysfs_fsid()
+_btrfs_get_fsid()
 {
        local fsid
+       local mnt=$1
 
-       fsid=$($BTRFS_UTIL_PROG filesystem show $TEST_DIR |grep uuid: |\
+       fsid=$($BTRFS_UTIL_PROG filesystem show $mnt |grep uuid: |\
               $AWK_PROG '{print $NF}')
 
+       echo $fsid
+}
+
+_require_btrfs_sysfs_fsid()
+{
+       local fsid
+
+       fsid=$(_btrfs_get_fsid $TEST_DIR)
+
        # Check if the kernel has sysfs fsid support.
        # Following kernel patch adds it:
        #   btrfs: sysfs add devinfo/fsid to retrieve fsid from the device
index 7f14c19ca89e5841203da0a98ab009b404e566d5..b2e06b12732186c74046aaf4627b66baf32d66cf 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -4721,7 +4721,6 @@ _require_statx()
 _fs_sysfs_dname()
 {
        local dev=$1
-       local fsid
 
        if [ ! -b "$dev" ]; then
                _fail "Usage: _fs_sysfs_dname <mounted_device>"
@@ -4729,9 +4728,7 @@ _fs_sysfs_dname()
 
        case "$FSTYP" in
        btrfs)
-               fsid=$($BTRFS_UTIL_PROG filesystem show ${dev} | grep uuid: | \
-                                                       $AWK_PROG '{print $NF}')
-               echo $fsid ;;
+               _btrfs_get_fsid $dev ;;
        *)
                _short_dev $dev ;;
        esac