diff mbox series

[v4,1/5] common/rc: _fs_sysfs_dname fetch fsid using btrfs tool

Message ID d63c4427d1dc9db3c18a07cb9098459de242fbd3.1698712764.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series [v4,1/5] common/rc: _fs_sysfs_dname fetch fsid using btrfs tool | expand

Commit Message

Anand Jain Nov. 2, 2023, 11:28 a.m. UTC
Currently _fs_sysfs_dname gets fsid from the findmnt command however
this command provides the metadata_uuid if the device is mounted with
temp-fsid. So instead, use btrfs filesystem show command to know the fsid.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
---
v3: add local variable fsid

 common/rc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

David Sterba Nov. 2, 2023, 8 p.m. UTC | #1
On Thu, Nov 02, 2023 at 07:28:18PM +0800, Anand Jain wrote:
> Currently _fs_sysfs_dname gets fsid from the findmnt command however
> this command provides the metadata_uuid if the device is mounted with
> temp-fsid. So instead, use btrfs filesystem show command to know the fsid.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> Reviewed-by: Filipe Manana <fdmanana@suse.com>
> ---
> v3: add local variable fsid
> 
>  common/rc | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index 259a1ffb09b9..7f14c19ca89e 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4721,6 +4721,7 @@ _require_statx()
>  _fs_sysfs_dname()
>  {
>  	local dev=$1
> +	local fsid
>  
>  	if [ ! -b "$dev" ]; then
>  		_fail "Usage: _fs_sysfs_dname <mounted_device>"
> @@ -4728,7 +4729,9 @@ _fs_sysfs_dname()
>  
>  	case "$FSTYP" in
>  	btrfs)
> -		findmnt -n -o UUID ${dev} ;;
> +		fsid=$($BTRFS_UTIL_PROG filesystem show ${dev} | grep uuid: | \
> +							$AWK_PROG '{print $NF}')

This could be also added as a subcommand to 'inspect-internal', ie. from
a file to it's filesystem uuid, then it should be easy to get any other
id if needed through the sysfs directory.
Anand Jain Nov. 2, 2023, 11:01 p.m. UTC | #2
On 11/3/23 04:00, David Sterba wrote:
> On Thu, Nov 02, 2023 at 07:28:18PM +0800, Anand Jain wrote:
>> Currently _fs_sysfs_dname gets fsid from the findmnt command however
>> this command provides the metadata_uuid if the device is mounted with
>> temp-fsid. So instead, use btrfs filesystem show command to know the fsid.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> Reviewed-by: Filipe Manana <fdmanana@suse.com>
>> ---
>> v3: add local variable fsid
>>
>>   common/rc | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/common/rc b/common/rc
>> index 259a1ffb09b9..7f14c19ca89e 100644
>> --- a/common/rc
>> +++ b/common/rc
>> @@ -4721,6 +4721,7 @@ _require_statx()
>>   _fs_sysfs_dname()
>>   {
>>   	local dev=$1
>> +	local fsid
>>   
>>   	if [ ! -b "$dev" ]; then
>>   		_fail "Usage: _fs_sysfs_dname <mounted_device>"
>> @@ -4728,7 +4729,9 @@ _fs_sysfs_dname()
>>   
>>   	case "$FSTYP" in
>>   	btrfs)
>> -		findmnt -n -o UUID ${dev} ;;
>> +		fsid=$($BTRFS_UTIL_PROG filesystem show ${dev} | grep uuid: | \
>> +							$AWK_PROG '{print $NF}')
> 
> This could be also added as a subcommand to 'inspect-internal', ie. from
> a file to it's filesystem uuid, then it should be easy to get any other
> id if needed through the sysfs directory.


Thanks for the feedback. I'll create a separate patch for the
'get_btrfs_fsid' helper, making it possible to merge this series
with RB.

Thanks Anand
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 259a1ffb09b9..7f14c19ca89e 100644
--- a/common/rc
+++ b/common/rc
@@ -4721,6 +4721,7 @@  _require_statx()
 _fs_sysfs_dname()
 {
 	local dev=$1
+	local fsid
 
 	if [ ! -b "$dev" ]; then
 		_fail "Usage: _fs_sysfs_dname <mounted_device>"
@@ -4728,7 +4729,9 @@  _fs_sysfs_dname()
 
 	case "$FSTYP" in
 	btrfs)
-		findmnt -n -o UUID ${dev} ;;
+		fsid=$($BTRFS_UTIL_PROG filesystem show ${dev} | grep uuid: | \
+							$AWK_PROG '{print $NF}')
+		echo $fsid ;;
 	*)
 		_short_dev $dev ;;
 	esac