Re: [PATCH 04/12] btrfs: create a helper function, check_fsid(), to verify the tempfsid

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



On Thu, Feb 15, 2024 at 02:34:07PM +0800, Anand Jain wrote:
> check_fsid() provides a method to verify if the given device is mounted
> with the tempfsid in the kernel. Function sb() is an internal only
> function.
> 
> Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx>
> ---
>  common/btrfs | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/common/btrfs b/common/btrfs
> index e1b29c613767..5cba9b16b4de 100644
> --- a/common/btrfs
> +++ b/common/btrfs
> @@ -792,3 +792,37 @@ _has_btrfs_sysfs_feature_attr()
>  
>  	test -e /sys/fs/btrfs/features/$feature_attr
>  }
> +
> +# Dump key members of the on-disk super-block from the given disk; helps debug
> +sb()
> +{
> +	local dev1=$1
> +	local parameters="device|devid|^metadata_uuid|^fsid|^incom|^generation|\
> +		^flags| \|$| \)$|compat_flags|compat_ro_flags|dev_item.uuid"
> +
> +	$BTRFS_UTIL_PROG inspect-internal dump-super $dev1 | egrep "$parameters"

Please don't use "egrep", it's deprecated, might hit a warning output.
Replace it with "grep -E" :)

> +}
> +
> +check_fsid()
> +{
> +	local dev1=$1
> +	local fsid
> +
> +	# on disk fsid
> +	fsid=$(sb $dev1 | grep ^fsid | awk -d" " '{print $2}')
> +	echo -e "On disk fsid:\t\t$fsid" | sed -e "s/$fsid/FSID/g"
> +
> +	echo -e -n "Metadata uuid:\t\t"
> +	cat /sys/fs/btrfs/$fsid/metadata_uuid | sed -e "s/$fsid/FSID/g"
> +
> +	# This returns the temp_fsid if set
> +	tempfsid=$(_btrfs_get_fsid $dev1)
> +	if [[ $tempfsid == $fsid ]]; then
> +		echo -e "Temp fsid:\t\tFSID"
> +	else
> +		echo -e "Temp fsid:\t\tTEMPFSID"
> +	fi
> +
> +	echo -e -n "Tempfsid status:\t"
> +	cat /sys/fs/btrfs/$tempfsid/temp_fsid
> +}
> -- 
> 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