100 lines
3.0 KiB
Diff
100 lines
3.0 KiB
Diff
From 88c2aa59c3f62a04f89a62985f9f0ece694fe066 Mon Sep 17 00:00:00 2001
|
|
From: Integral <integral@murena.io>
|
|
Date: Wed, 23 Oct 2024 18:00:33 +0800
|
|
Subject: [PATCH 067/233] bcachefs: add support for true/false & yes/no in
|
|
bool-type options
|
|
Content-Type: text/plain; charset="utf-8"
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
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 <integral@murena.io>
|
|
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
|
|
Acked-by: David Howells <dhowells@redhat.com>
|
|
Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
|
|
---
|
|
fs/bcachefs/opts.c | 16 +++++++++-------
|
|
fs/fs_parser.c | 3 ++-
|
|
include/linux/fs_parser.h | 2 ++
|
|
3 files changed, 13 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
|
|
index 49c59aec6954..0ba58d74c21f 100644
|
|
--- a/fs/bcachefs/opts.c
|
|
+++ b/fs/bcachefs/opts.c
|
|
@@ -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"
|
|
@@ -334,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) {
|
|
diff --git a/fs/fs_parser.c b/fs/fs_parser.c
|
|
index 24727ec34e5a..6521e9a9d6ef 100644
|
|
--- a/fs/fs_parser.c
|
|
+++ b/fs/fs_parser.c
|
|
@@ -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)
|
|
diff --git a/include/linux/fs_parser.h b/include/linux/fs_parser.h
|
|
index 6cf713a7e6c6..0974cd33bcba 100644
|
|
--- a/include/linux/fs_parser.h
|
|
+++ b/include/linux/fs_parser.h
|
|
@@ -83,6 +83,8 @@ extern int fs_lookup_param(struct fs_context *fc,
|
|
|
|
extern int lookup_constant(const struct constant_table tbl[], const char *name, int not_found);
|
|
|
|
+extern const struct constant_table bool_names[];
|
|
+
|
|
#ifdef CONFIG_VALIDATE_FS_PARSER
|
|
extern bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size,
|
|
int low, int high, int special);
|
|
--
|
|
2.45.2
|
|
|