[PATCH] common/btrfs: add _btrfs_get_fsid() helper

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



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@xxxxxxx>
Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx>
---
 common/btrfs | 14 ++++++++++++--
 common/rc    |  5 +----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/common/btrfs b/common/btrfs
index fbc26181f7bc..f91f8dd869a1 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 7f14c19ca89e..b2e06b127321 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 <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
-- 
2.39.3





[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux