public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] common/rc: add _parse_size_from_string
@ 2022-06-14  5:08 An Long
  2022-06-14  5:08 ` [PATCH 2/2] common/rc: fix input value to _scratch_mkfs_sized An Long
  2022-06-15  6:05 ` [PATCH 1/2] common/rc: add _parse_size_from_string Zorro Lang
  0 siblings, 2 replies; 7+ messages in thread
From: An Long @ 2022-06-14  5:08 UTC (permalink / raw)
  To: fstests; +Cc: An Long

Add a helper to convert size value to bytes. This is used to handle
value as bytes, such as 4k to 4096.

Signed-off-by: An Long <lan@suse.com>
---
 common/rc | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/common/rc b/common/rc
index 3c072c16..22050bc2 100644
--- a/common/rc
+++ b/common/rc
@@ -1028,6 +1028,54 @@ _check_minimal_fs_size()
 	fi
 }
 
+# Convert size value to bytes
+# _parse_size_from_string <size>
+_parse_size_from_string()
+{
+        local str=$1
+        local mult=1
+        local size
+        local endchar
+
+        if [[ $str =~ ^[0-9]+[a-zA-Z]$ ]] ; then
+                size=${str:: -1}
+                endchar=${str: -1}
+                case $endchar in
+                e|E)
+                                mult=$(($mult * 1024))
+                                ;&
+                p|P)
+                                mult=$(($mult * 1024))
+                                ;&
+                t|T)
+                                mult=$(($mult * 1024))
+                                ;&
+                g|G)
+                                mult=$(($mult * 1024))
+                                ;&
+                m|M)
+                                mult=$(($mult * 1024))
+                                ;&
+                k|K)
+                                mult=$(($mult * 1024))
+                                ;&
+                b|B)
+                                ;;
+                *)
+                                echo "unknown size descriptor $endchar"
+                                exit 1
+                esac
+        elif [[ $str =~ ^[0-9]+$ ]] ; then
+                size=$str
+        else
+                echo "size value $str is invalid"
+                exit 1
+        fi
+
+        size=$(($size * $mult))
+        echo $size
+}
+
 # Create fs of certain size on scratch device
 # _scratch_mkfs_sized <size in bytes> [optional blocksize]
 _scratch_mkfs_sized()
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH 0/2] Fix input value to _scratch_mkfs_sized
@ 2022-06-27 14:08 An Long
  2022-06-27 14:08 ` [PATCH 2/2] common/rc: fix " An Long
  0 siblings, 1 reply; 7+ messages in thread
From: An Long @ 2022-06-27 14:08 UTC (permalink / raw)
  To: fstests; +Cc: An Long

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%2F9qV62dtVyCvn@mit.edu/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
-- 
2.35.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-27 14:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-14  5:08 [PATCH 1/2] common/rc: add _parse_size_from_string An Long
2022-06-14  5:08 ` [PATCH 2/2] common/rc: fix input value to _scratch_mkfs_sized An Long
2022-06-15  4:15   ` Zorro Lang
2022-06-16  4:30     ` Long An
2022-06-15  6:05 ` [PATCH 1/2] common/rc: add _parse_size_from_string Zorro Lang
2022-06-16  4:37   ` Long An
  -- strict thread matches above, loose matches on Subject: below --
2022-06-27 14:08 [PATCH 0/2] Fix input value to _scratch_mkfs_sized An Long
2022-06-27 14:08 ` [PATCH 2/2] common/rc: fix " An Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox