Therefore, if my original patch is okay, could you merge it?
Thanks,
Integral
On 7/22/24 12:03 PM, Hongbo Li wrote:
On 2024/7/19 6:50, Kent Overstreet wrote:
On Thu, Jul 18, 2024 at 08:29:28PM GMT, Integral wrote:
Here is the new patch:
Currently, when using bcachefs-tools to set options, bool-type
options can
only accept 1 or 0. Add support for accepting true/false, yes/no &
on/off for these options.
Signed-off-by: Integral <[email protected]>
---
fs/bcachefs/opts.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
index 0770aebef6d8..0e4cd6984eda 100644
--- a/fs/bcachefs/opts.c
+++ b/fs/bcachefs/opts.c
@@ -332,17 +332,21 @@ int bch2_opt_parse(struct bch_fs *c,
switch (opt->type) {
case BCH_OPT_BOOL:
if (val) {
- ret = kstrtou64(val, 10, res);
+ if (!strcasecmp(val, "1") || !strcasecmp(val, "true") ||
+ !strcasecmp(val, "yes") || !strcasecmp(val, "on")) {
+ *res = 1;
+ } else if (!strcasecmp(val, "0") || !strcasecmp(val,
"false") ||
+ !strcasecmp(val, "no") || !strcasecmp(val, "off")) {
Sorry, may be I was wrong.
+ *res = 0;
+ } else {
+ if (err)
+ prt_printf(err, "%s: must be bool",
opt->attr.name);
+ return -BCH_ERR_option_not_bool;
+ }
There _should_ be something more standard in the kernel for parsing bool
options (commandline options, module options) - please hunt around for
that and see if it works; report back on what you find.
I find in Documentation/filesystems/mount_api.rst, it give an
explanation.
```
Note that if the value is of fs_param_is_bool type, fs_parse() will try
to match any string value against "0", "1", "no", "yes", "false", "true".
```
But this has been handled in fs_param_is_bool with macro fsparam_bool.
Many file systems do this in fs_parse. I think the original patch
seems ok.
Thanks,
Hongbo
We want to be consistent on how we parse bools throughout the kernel.