Fix input value to _scratch_mkfs_sized
cover Fix input value to _scratch_mkfs_sized
Function _scratch_mkfs_sized cannot recognize the size descriptor.
For example, we set MKFS_OPTIONS="-b 4k" and then run generic/416 on ext4, will fail with "mkfs.ext4: invalid block size - 4".
The [PATCH 2/2] based on [PATCH 1/2].
Full story is here:
https://lore.kernel.org/fstests/Yre%[email protected]/T/#t
https://lore.kernel.org/fstests/20220621044038.ppvdexgob3kzs46m@zlang-mailbox/T/#t
An Long (2):
common/config: add _check_mkfs_block_options common/rc: fix input value to _scratch_mkfs_sized
README | 4 ++++ common/config | 30 ++++++++++++++++++++++++++++++ common/rc | 16 +--------------- 3 files changed, 35 insertions(+), 15 deletions(-)
base-commit: 568ac9fffeb6afec03e5d6c9936617232fd7fc6d
Signature · 1 line
2.35.3
PATCH 2/2 common/rc: fix input value to _scratch_mkfs_sized
_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 will give errors to ext2/3/4 etc, and brings potential bugs to xfs or btrfs.
This patch depends on patch ("common/config: add _check_mkfs_block_options").
--- common/rc | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
common/rc +1 -15
@@ -1036,21 +1036,7 @@ _scratch_mkfs_sized() local blocksize=$2 local def_blksz - case $FSTYP in - xfs) - def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?size= ?+([0-9]+).*/\1/p'` - ;; - btrfs) - def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-s ?+([0-9]+).*/\1/p'` - ;; - ext2|ext3|ext4|ext4dev|udf|reiser4|ocfs2|reiserfs) - def_blksz=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?+([0-9]+).*/\1/p'` - ;; - jfs) - def_blksz=4096 - ;; - esac - + [ -n "$FS_BLOCK_SIZE" ] && def_blksz=$FS_BLOCK_SIZE [ -n "$def_blksz" ] && blocksize=$def_blksz [ -z "$blocksize" ] && blocksize=4096
Signature · 1 line
2.35.3
PATCH 1/2 common/config: add _check_mkfs_block_options
In reply to An LongAdd a helper to check MKFS_OPTIONS to use pure integer in bytes, and create variable FS_BLOCK_SIZE=blocksize.
For example, set MKFS_OPTIONS="-b 4096" but not "-b 4k", then FS_BLOCK_SIZE=4096.
--- README | 4 ++++ common/config | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
README +4 -0
@@ -241,6 +241,10 @@ Misc: this option is supported for all filesystems currently only -overlay is expected to run without issues. For other filesystems additional patches and fixes to the test suite might be needed. + - If MKFS_OPTIONS contains block size, the value must be an integer number of + bytes without units. And the variable FS_BLOCK_SIZE will be created. + For example, set MKFS_OPTIONS="-b 4096" but not "-b 4k", then + FS_BLOCK_SIZE=4096. ______________________ USING THE FSQA SUITE
common/config +30 -0
@@ -623,6 +623,34 @@ _check_device() esac } +# Check block size in $MKFS_OPTIONS is a valid integer +# And then set the value in $FS_BLOCK_SIZE +_check_mkfs_block_options() +{ + # Avoid that FS_BLOCK_SIZE is different from MKFS_OPTIONS + # Otherwise it will cause confusion + unset FS_BLOCK_SIZE + + case $FSTYP in + xfs) + FS_BLOCK_SIZE=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?size= ?+([0-9]+[a-zA-Z]?).*/\1/p'` + ;; + btrfs) + FS_BLOCK_SIZE=`echo $MKFS_OPTIONS | sed -rn 's/.*-s ?+([0-9]+[a-zA-Z]?).*/\1/p'` + ;; + ext2|ext3|ext4|ext4dev|udf|reiser4|ocfs2|reiserfs) + FS_BLOCK_SIZE=`echo $MKFS_OPTIONS | sed -rn 's/.*-b ?+([0-9]+[a-zA-Z]?).*/\1/p'` + ;; + jfs) + FS_BLOCK_SIZE=4096 + ;; + esac + + if [ -n "$FS_BLOCK_SIZE" ] && ! [[ $FS_BLOCK_SIZE =~ ^[0-9]+$ ]] ; then + _fatal "\$MKFS_OPTIONS: block size \"$FS_BLOCK_SIZE\" not an integer." + fi +} + # check and return a canonical mount point path _canonicalize_mountpoint() {
@@ -896,5 +924,7 @@ else fi fi +_check_mkfs_block_options + # make sure this script returns success /bin/true
Signature · 1 line
2.35.3