From: Anand Jain Date: Wed, 8 Nov 2023 04:28:57 +0000 (+0800) Subject: common/btrfs: add _btrfs_get_fsid() helper X-Git-Tag: v2023.11.19~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=59372e8d3f961eb20d911e715777af06de921891;p=xfstests-dev.git common/btrfs: add _btrfs_get_fsid() helper We have two instances of reading the btrfs fsid by using the command 'btrfs filesystem show ' turn this into an easy-to-use helper function and also use it. Suggested-by: David Sterba Signed-off-by: Anand Jain Reviewed-by: Zorro Lang Signed-off-by: Zorro Lang --- diff --git a/common/btrfs b/common/btrfs index fbc26181..f91f8dd8 100644 --- a/common/btrfs +++ b/common/btrfs @@ -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 diff --git a/common/rc b/common/rc index 7f14c19c..b2e06b12 100644 --- 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 " @@ -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