libbcachefs: add support for true/false & yes/no in bool-type options
PATCH 1/1 libbcachefs: add support for true/false & yes/no in bool-type options
This is a resend of my previous patch with code style optimized as I forgot to add Kent Overstreet in "To". The previous patch is
(https://lore.kernel.org/linux-bcachefs/[email protected]/T/#u).
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
--- libbcachefs/opts.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
libbcachefs/opts.c +9 -7
@@ -332,17 +332,19 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); +if (!strcmp (val,"1" ) || !strcmp (val,"true" ) || !strcmp (val,"yes" )) { + *res =1 ; + }else if (!strcmp (val,"0" ) || !strcmp (val,"false" ) || !strcmp (val,"no" )) { + *res =0 ; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return -BCH_ERR_option_not_bool; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
Signature · 1 line
2.45.2
Quoted 10 lines · Integral
This is a resend of my previous patch with code style optimized as I forgot to add Kent Overstreet in "To". The previous patch is
(https://lore.kernel.org/linux-bcachefs/[email protected]/T/#u).Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
--- libbcachefs/opts.c | 16 +++++++++-------
Generating diff on bcachefs tree (not bcachefs-tools)?
libbcachefs/opts.c int bch2_opt_parse(struct bch_fs *c, · line 335
Quoted 12 lines
1 file changed, 9 insertions(+), 7 deletions(-)libbcachefs/opts.c +1
-1@@ -332,17 +332,19 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); +if (!strcmp (val,"1" ) || !strcmp (val,"true" ) || !strcmp (val,"yes" )) {
Should we use the strcasecmp replace the strcmp?
Thanks,
Hongbo
Quoted 21 lines
libbcachefs/opts.c +8
-6+ *res =1 ; + }else if (!strcmp (val,"0" ) || !strcmp (val,"false" ) || !strcmp (val,"no" )) { + *res =0 ; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return -BCH_ERR_option_not_bool; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
Quoted 2 lines · Hongbo Li
+ } else if (!strcmp(val, "0") || !strcmp(val, "false") || !strcmp(val, "no")) {
How about also parse on/off into bool type.
Thanks,
Hongbo
PATCH 1/1 Add support for true/false, yes/no & on/off in bool-type options
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.
--- fs/bcachefs/opts.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
fs/bcachefs/opts.c +11 -7
@@ -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" )) { + *res =0 ; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return -BCH_ERR_option_not_bool; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
Signature · 1 line
2.45.2
Re: [PATCH] Add support for true/false, yes/no & on/off in bool-type options
Quoted 21 lines · Integral
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(-)fs/bcachefs/opts.c +1
-1@@ -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") ||
fs/bcachefs/opts.c int bch2_opt_parse(struct bch_fs *c, · line 345
Quoted 10 lines
fs/bcachefs/opts.c +10
-0+ !strcasecmp(val, "yes") || !strcasecmp(val, "on")) { + *res =1 ; + } else if (!strcasecmp(val, "0") || !strcasecmp(val, "false") || + !strcasecmp(val, "no") || !strcasecmp(val, "off")) { + *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.
We want to be consistent on how we parse bools throughout the kernel.
Re: [PATCH] Add support for true/false, yes/no & on/off in bool-type options
Quoted 12 lines · Kent Overstreet
Quoted 11 lines · Integral
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(-)
Quoted 14 lines
Quoted 5 lines
fs/bcachefs/opts.c +0
-0fs/bcachefs/opts.c int bch2_opt_parse(struct bch_fs *c, · line 339
Quoted 9 lines
fs/bcachefs/opts.c +5
-1@@ -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.
Quoted 10 lines
fs/bcachefs/opts.c int bch2_opt_parse(struct bch_fs *c, · line 345
Quoted 6 lines
fs/bcachefs/opts.c +6
-0+ *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
Quoted 2 lines
We want to be consistent on how we parse bools throughout the kernel.
Re: [PATCH] Add support for true/false, yes/no & on/off in bool-type options
Therefore, if my original patch is okay, could you merge it?
Thanks,
Integral
Re: [PATCH] Add support for true/false, yes/no & on/off in bool-type options
In reply to Hongbo LiTherefore, if my original patch is okay, could you merge it?
Thanks,
Integral
Quoted 57 lines · Hongbo Li
Quoted 12 lines · Kent Overstreet
Quoted 11 lines · Integral
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(-)Quoted 15 lines
Quoted 7 lines
fs/bcachefs/opts.c +0
-0@@ -332,17 +332,21 @@ int bch2_opt_parse(struct bch_fs *c, switch (opt->type) {case
BCH_OPT_BOOL:Quoted 8 lines
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.
Quoted 11 lines
Quoted 7 lines
+ *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_boolwith macrofsparam_bool. Many file systems do this infs_parse. I think the original patch seems ok.Thanks,
HongboQuoted 2 lines
We want to be consistent on how we parse bools throughout the kernel.
Re: [PATCH] Add support for true/false, yes/no & on/off in bool-type options
Quoted 3 lines · Integral
Therefore, if my original patch is okay, could you merge it?
I took a look just now, I think you can use lookup_constant.
Quoted 64 lines
Thanks,
Integral
Quoted 55 lines · Hongbo Li
Quoted 12 lines · Kent Overstreet
Quoted 11 lines · Integral
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(-)Quoted 14 lines
Quoted 5 lines
fs/bcachefs/opts.c +0
-0fs/bcachefs/opts.c int bch2_opt_parse(struct bch_fs *c, · line 339
Quoted 9 lines
fs/bcachefs/opts.c +5
-1@@ -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.
Quoted 10 lines
fs/bcachefs/opts.c int bch2_opt_parse(struct bch_fs *c, · line 345
Quoted 6 lines
fs/bcachefs/opts.c +6
-0+ *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_boolwith macrofsparam_bool. Many file systems do this infs_parse. I think the original patch seems ok.Thanks,
HongboQuoted 2 lines
We want to be consistent on how we parse bools throughout the kernel.
PATCH v2 1/1 bcachefs: add support for true/false & yes/no in bool-type options
Here is my 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 and yes/no for these options.
--- fs/bcachefs/opts.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
fs/bcachefs/opts.c +21 -7
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h"
@@ -322,6 +323,18 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; } +static const struct constant_table bch2_opt_bool_names[] = { + {"0" , false }, + {"false" , false }, + {"no" , false }, + {"off" , false }, + {"1" , true }, + {"true" , true }, + {"yes" , true }, + {"on" , true }, + { }, +}; + int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,
@@ -332,17 +345,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); + ret =lookup_constant (bch2_opt_bool_names, val, BCH_ERR_option_not_bool); +if (ret != BCH_ERR_option_not_bool) { + *res = ret; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return ret; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
Signature · 1 line
2.46.2
Re: [PATCH v2] bcachefs: add support for true/false & yes/no in bool-type options
Any progress on this?
Re: [PATCH v2] bcachefs: add support for true/false & yes/no in bool-type options
In reply to IntegralQuoted 43 lines · Integral
Here is my 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 and yes/no for these options.
Signed-off-by Integral <[email protected]>--- fs/bcachefs/opts.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)fs/bcachefs/opts.c +13
-0@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h" @@ -322,6 +323,18 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; } +static const struct constant_table bch2_opt_bool_names[] = { + {"0" , false }, + {"false" , false }, + {"no" , false }, + {"off" , false }, + {"1" , true }, + {"true" , true }, + {"yes" , true }, + {"on" , true }, + { }, +}; + int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,
fs/bcachefs/opts.c int bch2_opt_parse(struct bch_fs *c, · line 349
Quoted 6 lines
fs/bcachefs/opts.c +2
-1@@ -332,17 +345,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); + ret =lookup_constant (bch2_opt_bool_names, val, BCH_ERR_option_not_bool); +if (ret != BCH_ERR_option_not_bool) {
I apologize for looking at your patch so late. But this seems something wrong. The third parameter should be -BCH_ERR_option_not_bool. And also as noted in [1]. The only accepted bool value are: "0", "1", "no", "yes", "false", "true". This just like what has been done in fs_param_is_bool helper.
[1] Documentation/filesystems/mount_api.rst
Thanks,
Hongbo
Quoted 19 lines
fs/bcachefs/opts.c +6
-6+ *res = ret; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return ret; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
PATCH v3 1/1 bcachefs: add support for true/false & yes/no in bool-type options
Here is my modified patch:
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
--- fs/bcachefs/opts.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
fs/bcachefs/opts.c +19 -7
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h"
@@ -322,6 +323,16 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; } +static const struct constant_table bch2_opt_bool_names[] = { + {"0" , false }, + {"false" , false }, + {"no" , false }, + {"1" , true }, + {"true" , true }, + {"yes" , true }, + { }, +}; + int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,
@@ -332,17 +343,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); + ret =lookup_constant (bch2_opt_bool_names, val, -BCH_ERR_option_not_bool); +if (ret != BCH_ERR_option_not_bool) { + *res = ret; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return ret; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
Signature · 1 line
2.47.0
Re: [PATCH v3] bcachefs: add support for true/false & yes/no in bool-type options
Is my new patch acceptable?
Re: [PATCH v3] bcachefs: add support for true/false & yes/no in bool-type options
In reply to IntegralQuoted 41 lines · Integral
Here is my modified patch:
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
Signed-off-by Integral <[email protected]>--- fs/bcachefs/opts.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)fs/bcachefs/opts.c +11
-0@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h" @@ -322,6 +323,16 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; } +static const struct constant_table bch2_opt_bool_names[] = { + {"0" , false }, + {"false" , false }, + {"no" , false }, + {"1" , true }, + {"true" , true }, + {"yes" , true }, + { }, +}; + int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,
fs/bcachefs/opts.c int bch2_opt_parse(struct bch_fs *c, · line 347
Quoted 6 lines
fs/bcachefs/opts.c +2
-1@@ -332,17 +343,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); + ret =lookup_constant (bch2_opt_bool_names, val, -BCH_ERR_option_not_bool); +if (ret != BCH_ERR_option_not_bool) {
Should it also be modified? Other seems good for me. :)
Thanks,
Hongbo
Quoted 19 lines
fs/bcachefs/opts.c +6
-6+ *res = ret; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return ret; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
PATCH v4 1/1 libbcachefs: add support for true/false & yes/no in bool-type options
Here is my latest patch:
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
--- fs/bcachefs/opts.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
fs/bcachefs/opts.c +19 -7
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h"
@@ -322,6 +323,16 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; } +static const struct constant_table bch2_opt_bool_names[] = { + {"0" , false }, + {"false" , false }, + {"no" , false }, + {"1" , true }, + {"true" , true }, + {"yes" , true }, + { }, +}; + int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,
@@ -332,17 +343,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); + ret =lookup_constant (bch2_opt_bool_names, val, -BCH_ERR_option_not_bool); +if (ret != -BCH_ERR_option_not_bool) { + *res = ret; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return ret; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
Signature · 1 line
2.47.0
Quoted 6 lines · Integral
Here is my latest patch:
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
Looks good to me! :)
Thanks
Hongbo
Quoted 60 lines
Signed-off-by Integral <[email protected]>--- fs/bcachefs/opts.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)fs/bcachefs/opts.c +19
-7@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h" @@ -322,6 +323,16 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; } +static const struct constant_table bch2_opt_bool_names[] = { + {"0" , false }, + {"false" , false }, + {"no" , false }, + {"1" , true }, + {"true" , true }, + {"yes" , true }, + { }, +}; + int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,@@ -332,17 +343,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); + ret =lookup_constant (bch2_opt_bool_names, val, -BCH_ERR_option_not_bool); +if (ret != -BCH_ERR_option_not_bool) { + *res = ret; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return ret; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
Quoted 28 lines · Integral
Here is my latest patch:
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
Signed-off-by Integral <[email protected]>---
fs/bcachefs/opts.c| 26 +++++++++++++++++++-------1 file changed, 19 insertions(+), 7 deletions(-)fs/bcachefs/opts.c +1
-0@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h" @@ -322,6 +323,16 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; }
fs/bcachefs/opts.c int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err) · line 335
Quoted 10 lines
fs/bcachefs/opts.c +10
-0+static const struct constant_table bch2_opt_bool_names[] = { + {"0" , false }, + {"false" , false }, + {"no" , false }, + {"1" , true }, + {"true" , true }, + {"yes" , true }, + { }, +}; +
Can you use the existing constant table?
Quoted 32 lines
fs/bcachefs/opts.c +0
-0int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,@@ -332,17 +343,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case
BCH_OPT_BOOL:
if (val) {
- ret =kstrtou64(val, 10, res);
+ ret =lookup_constant(bch2_opt_bool_names, val, -BCH_ERR_option_not_bool);
+ if (ret != -BCH_ERR_option_not_bool) {
+ *res = ret;
+ } else {
+ if (err)
+prt_printf(err, "%s: must be bool", opt->attr.name);
+ return ret;
+ }
} else {
- ret = 0;
*res = 1;
}- if (ret < 0 || (*res != 0 && *res != 1)) {
- if (err)
-prt_printf(err, "%s: must be bool", opt->attr.name);
- return ret < 0 ? ret : -BCH_ERR_option_not_bool;
- }
break;
caseBCH_OPT_UINT:
if (!val) {Signature · 1 line
2.47.0
PATCH v5 1/1 bcachefs: add support for true/false & yes/no in bool-type options
Here is the patch which uses existing constant table:
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
--- fs/bcachefs/opts.c | 18 +++++++++++------- fs/fs_parser.c | 3 ++- 2 files changed, 13 insertions(+), 8 deletions(-)
fs/bcachefs/opts.c +11 -7
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h"
@@ -322,6 +323,8 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; } +extern const struct constant_table bool_names[]; + int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,
@@ -332,17 +335,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case BCH_OPT_BOOL :if (val) { - ret =kstrtou64 (val,10 , res); + ret =lookup_constant (bool_names, val, -BCH_ERR_option_not_bool); +if (ret != -BCH_ERR_option_not_bool) { + *res = ret; + }else { +if (err) +prt_printf (err,"%s: must be bool" , opt->attr.name); +return ret; + } }else { - ret =0 ; *res =1 ; } -if (ret <0 || (*res !=0 && *res !=1 )) { -if (err) -prt_printf (err,"%s: must be bool" , opt->attr.name); -return ret <0 ? ret : -BCH_ERR_option_not_bool; - }break ;case BCH_OPT_UINT :if (!val) {
fs/fs_parser.c +2 -1
@@ -13,7 +13,7 @@#include <linux/namei.h> #include "internal.h" -static const struct constant_table bool_names[] = { +const struct constant_table bool_names[] = { {"0" , false }, {"1" , true }, {"false" , false },
@@ -22,6 +22,7 @@ static const struct constant_table bool_names[] = { { "yes", true }, { }, }; +EXPORT_SYMBOL (bool_names);static const struct constant_table *__lookup_constant (const struct constant_table *tbl,const char *name)
Signature · 1 line
2.47.0
Re: [PATCH v5] bcachefs: add support for true/false & yes/no in bool-type options
Is my v5 patch more acceptable?
Re: [PATCH v5] bcachefs: add support for true/false & yes/no in bool-type options
In reply to IntegralQuoted 8 lines · Integral
Here is the patch which uses existing constant table:
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
Signed-off-by Integral <[email protected]>
The code changes part looks good.
Quoted 76 lines
---
fs/bcachefs/opts.c| 18 +++++++++++-------fs/fs_parser.c| 3 ++-2 files changed, 13 insertions(+), 8 deletions(-)fs/bcachefs/opts.c +3
-0@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/kernel.h> +#include <linux/fs_parser.h> #include "bcachefs.h" #include "compress.h" @@ -322,6 +323,8 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)return 0 ; } +extern const struct constant_table bool_names[]; + int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, const char *val, u64 *res,@@ -332,17 +335,18 @@ int bch2_opt_parse(struct bch_fs *c,switch (opt->type) {case
BCH_OPT_BOOL:
if (val) {
- ret =kstrtou64(val, 10, res);
+ ret =lookup_constant(bool_names, val, -BCH_ERR_option_not_bool);
+ if (ret != -BCH_ERR_option_not_bool) {
+ *res = ret;
+ } else {
+ if (err)
+prt_printf(err, "%s: must be bool", opt->attr.name);
+ return ret;
+ }
} else {
- ret = 0;
*res = 1;
}- if (ret < 0 || (*res != 0 && *res != 1)) {
- if (err)
-prt_printf(err, "%s: must be bool", opt->attr.name);
- return ret < 0 ? ret : -BCH_ERR_option_not_bool;
- }
break;
caseBCH_OPT_UINT:
if (!val) {fs/fs_parser.c +2
-1@@ -13,7 +13,7 @@#include <linux/namei.h> #include "internal.h" -static const struct constant_table bool_names[] = { +const struct constant_table bool_names[] = { {"0" , false }, {"1" , true }, {"false" , false },@@ -22,6 +22,7 @@ static const struct constant_table bool_names[] = { { "yes", true }, { }, }; +EXPORT_SYMBOL (bool_names);static const struct
constant_table*__lookup_constant(const struct constant_table *tbl, const char *name)Signature · 1 line
2.47.0
Re: [PATCH v5] bcachefs: add support for true/false & yes/no in bool-type options
If my latest patch is acceptable, could you please apply my patch? :)
Re: [PATCH v5] bcachefs: add support for true/false & yes/no in bool-type options
Hi, Alan Huang
Give you a friendly ping :)
Quoted 1 line · Integral
If my latest patch is acceptable, could you please apply my patch? :)
Quoted 7 lines · Integral
This is a resend of my previous patch with code style optimized as I forgot to add Kent Overstreet in "To". The previous patch is
(https://lore.kernel.org/linux-bcachefs/[email protected]/T/#u).Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
Sorry I missed this before - you just need a signed-off-by line and I can apply
Quoted 6 lines · Kent Overstreet
Quoted 4 lines · Integral
This is a resend of my previous patch with code style optimized as I forgot to add Kent Overstreet in "To". The previous patch is
(https://lore.kernel.org/linux-bcachefs/[email protected]/T/#u).
Quoted 7 lines
Quoted 3 lines
Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
Sorry I missed this before - you just need a signed-off-by line and I can apply
There is a v5 now:
https://lore.kernel.org/all/[email protected]/T/#mea54884e20fa63d4ee32132a1980749e9f6283b9
Quoted 11 lines · Alan Huang
Quoted 10 lines · Kent Overstreet
Quoted 7 lines · Integral
This is a resend of my previous patch with code style optimized as I forgot to add Kent Overstreet in "To". The previous patch is
(https://lore.kernel.org/linux-bcachefs/[email protected]/T/#u).Currently, when using bcachefs-tools to set options, bool-type options can only accept 1 or 0. Add support for accepting true/false and yes/no for these options.
Quoted 7 lines
Quoted 3 lines
Sorry I missed this before - you just need a signed-off-by line and I can apply
There is a v5 now:
https://lore.kernel.org/all/[email protected]/T/#mea54884e20fa63d4ee32132a1980749e9f6283b9
Thanks, I've applied v5