Re: [PATCH 2/2] common/rc: fix input value to _scratch_mkfs_sized

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



On Tue, Jun 14, 2022 at 01:08:43PM +0800, An Long wrote:
> _scratch_mkfs_sized only receive integer number of bytes as a valid
> input. But if the MKFS_OPTIONS variable exists, it will use the value of
> block size in MKFS_OPTIONS to override input. In case of
> MKFS_OPTIONS="-b 4k", would result in blocksize=4 but not 4096. This

Hi An,

Good catch. Can you provide an example that a case fails on this issue, and
then it tests passed after having this patch? I'm wondering why no one notice
that before.

> will give errors to ext2/3/4 etc, and brings potential bugs to xfs or
> btrfs.
> 
> In addition, since we can receive various strings, so remove integer
> number check.
> 
> Signed-off-by: An Long <lan@xxxxxxxx>
> ---
>  common/rc | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/common/rc b/common/rc
> index 22050bc2..026007d3 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -1077,7 +1077,7 @@ _parse_size_from_string()
>  }
>  
>  # Create fs of certain size on scratch device
> -# _scratch_mkfs_sized <size in bytes> [optional blocksize]
> +# _scratch_mkfs_sized <size> [optional blocksize]
>  _scratch_mkfs_sized()
>  {
>  	local fssize=$1
> @@ -1086,13 +1086,13 @@ _scratch_mkfs_sized()
>  
>  	case $FSTYP in
>  	xfs)
> -		def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'`
> +		def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?size= ?+([0-9]+[a-zA-Z]?).*/\1/p'`
>  		;;
>  	btrfs)
> -		def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-s ?+([0-9]+).*/\1/p'`
> +		def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-s ?+([0-9]+[a-zA-Z]?).*/\1/p'`
>  		;;
>  	ext2|ext3|ext4|ext4dev|udf|reiser4|ocfs2|reiserfs)
> -		def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?+([0-9]+).*/\1/p'`
> +		def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?+([0-9]+[a-zA-Z]?).*/\1/p'`
>  		;;
>  	jfs)
>  		def_blksz=4096
> @@ -1101,14 +1101,8 @@ _scratch_mkfs_sized()
>  
>  	[ -n "$def_blksz" ] && blocksize=$def_blksz
>  	[ -z "$blocksize" ] && blocksize=4096
> -
> -	local re='^[0-9]+$'
> -	if ! [[ $fssize =~ $re ]] ; then
> -		_notrun "error: _scratch_mkfs_sized: fs size \"$fssize\" not an integer."
> -	fi
> -	if ! [[ $blocksize =~ $re ]] ; then
> -		_notrun "error: _scratch_mkfs_sized: block size \"$blocksize\" not an integer."
> -	fi
> +	blocksize=$(_parse_size_from_string $blocksize)
> +	fssize=$(_parse_size_from_string $fssize)

For now, the _parse_size_from_string is only used for this patch, I think these
two patches can be merged into one patch, as it trys to fix one single problem.

Thanks,
Zorro

>  
>  	local blocks=`expr $fssize / $blocksize`
>  
> -- 
> 2.35.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