diff mbox series

common/btrfs: add _btrfs_get_fsid() helper

Message ID 887706aa6c981aff219b0b2faca614e8ee2323b3.1699417639.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series common/btrfs: add _btrfs_get_fsid() helper | expand

Commit Message

Anand Jain Nov. 8, 2023, 4:28 a.m. UTC
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>
---
 common/btrfs | 14 ++++++++++++--
 common/rc    |  5 +----
 2 files changed, 13 insertions(+), 6 deletions(-)

Comments

Zorro Lang Nov. 16, 2023, 2:51 a.m. UTC | #1
On Wed, Nov 08, 2023 at 12:28:57PM +0800, Anand Jain wrote:
> 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>
> ---

It looks good to me, will merge it with:
  [PATCH v4 0/5] btrfs/219 cloned-device mount capability update

Reviewed-by: Zorro Lang <zlang@redhat.com>


>  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
> 
>
diff mbox series

Patch

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