Skip to contentSkip to conversation

_scratch_mkfs_geom: Fix regex used for matching block size option

PATCH In review Chandan Babu R 2 participants 2 messages Sep 25, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 _scratch_mkfs_geom: Fix regex used for matching block size option

The regular expression used by _scratch_mkfs_geom() to match mkfs.xfs' block size argument interprets the character 'b' as optional. It should actually interpret whitespace as optional.

This causes generic/223 to fail when testing an XFS filesystem which uses an external log device along with the -lsize option. In this case, the original value of -lsize is replaced with the value of $blocksize.

_scratch_mkfs_sized() also uses the same incorrect regex.

---
 common/rc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/rc +3 -3
index 5c4429ed..991a5731 100644
@@ -971,7 +971,7 @@ _scratch_mkfs_sized()
 	case $FSTYP in
 	xfs)
 		# don't override MKFS_OPTIONS that set a block size.
-		echo $MKFS_OPTIONS |grep -E -q "b?size="
+		echo $MKFS_OPTIONS |grep -E -q "b\s*size="
 		if [ $? -eq 0 ]; then
 			_scratch_mkfs_xfs -d size=$fssize $rt_ops
 		else
@@ -1063,8 +1063,8 @@ _scratch_mkfs_geom()
 
     case $FSTYP in
     xfs)
-	if echo "$MKFS_OPTIONS" | grep -E -q "b?size="; then
-		MKFS_OPTIONS=$(echo "$MKFS_OPTIONS" | sed -r "s/(b?size=)[0-9]+k?/\1$blocksize/")
+	if echo "$MKFS_OPTIONS" | grep -E -q "b\s*size="; then
+		MKFS_OPTIONS=$(echo "$MKFS_OPTIONS" | sed -r "s/(b\s*size=)[0-9]+k?/\1$blocksize/")
 	else
 		MKFS_OPTIONS+=" -b size=$blocksize"
 	fi
Signature · 1 line
2.39.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Chandan Babu R

The regular expression used by _scratch_mkfs_geom() to match mkfs.xfs' block size argument interprets the character 'b' as optional. It should actually interpret whitespace as optional.

This causes generic/223 to fail when testing an XFS filesystem which uses an external log device along with the -lsize option. In this case, the original value of -lsize is replaced with the value of $blocksize.

_scratch_mkfs_sized() also uses the same incorrect regex.

Heh. :(

--D

Quoted 31 lines
---
 common/rc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/rc +3 -3
index 5c4429ed..991a5731 100644
@@ -971,7 +971,7 @@ _scratch_mkfs_sized()
 	case $FSTYP in
 	xfs)
 		# don't override MKFS_OPTIONS that set a block size.
-		echo $MKFS_OPTIONS |grep -E -q "b?size="
+		echo $MKFS_OPTIONS |grep -E -q "b\s*size="
 		if [ $? -eq 0 ]; then
 			_scratch_mkfs_xfs -d size=$fssize $rt_ops
 		else
@@ -1063,8 +1063,8 @@ _scratch_mkfs_geom()
 
     case $FSTYP in
     xfs)
-	if echo "$MKFS_OPTIONS" | grep -E -q "b?size="; then
-		MKFS_OPTIONS=$(echo "$MKFS_OPTIONS" | sed -r "s/(b?size=)[0-9]+k?/\1$blocksize/")
+	if echo "$MKFS_OPTIONS" | grep -E -q "b\s*size="; then
+		MKFS_OPTIONS=$(echo "$MKFS_OPTIONS" | sed -r "s/(b\s*size=)[0-9]+k?/\1$blocksize/")
 	else
 		MKFS_OPTIONS+=" -b size=$blocksize"
 	fi
Signature · 1 line
2.39.1