From: Zizhi Wo wozizhi@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT
--------------------------------
In order to make the user state control the characteristics of the erofs, a dynamic switch about erofs is added.
The switch named erofs_enabled is closed by default, and is isolated by CONFIG_EROFS_FS. Users can open it by echo 1/on/ON/y/Y to /sys/module/fs_ctl/parameters/erofs_enabled.
Signed-off-by: Zizhi Wo wozizhi@huawei.com Signed-off-by: Baokun Li libaokun1@huawei.com --- fs/Makefile | 2 ++ fs/erofs/super.c | 3 +++ fs/fs_ctl.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 ++++ 4 files changed, 45 insertions(+) create mode 100644 fs/fs_ctl.c
diff --git a/fs/Makefile b/fs/Makefile index 29cc13ba2c08..06f000e22e06 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -15,6 +15,8 @@ obj-y := open.o read_write.o file_table.o super.o \ stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ fs_types.o fs_context.o fs_parser.o fsopen.o init.o \ kernel_read_file.o remap_range.o +obj-y += fs_ctl.o + ifdef CONFIG_CC_IS_CLANG CFLAGS_namei.o := $(call cc-disable-warning, bitwise-instead-of-logical) endif diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 606d4637a795..a6cb90c4fcce 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -661,6 +661,9 @@ static int erofs_init_fs_context(struct fs_context *fc) { struct erofs_fs_context *ctx;
+ if (!READ_ONCE(erofs_enabled)) + return -EOPNOTSUPP; + /* pseudo mount for anon inodes */ if (fc->sb_flags & SB_KERNMOUNT) { fc->ops = &erofs_anon_context_ops; diff --git a/fs/fs_ctl.c b/fs/fs_ctl.c new file mode 100644 index 000000000000..ab6b532188d9 --- /dev/null +++ b/fs/fs_ctl.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2024. Huawei Technologies Co., Ltd */ + +#include <linux/moduleparam.h> +#include <linux/kernel.h> +#include <linux/fs.h> + +#if IS_ENABLED(CONFIG_EROFS_FS) +static int param_set_bool_on_only_once(const char *s, const struct kernel_param *kp) +{ + int ret; + bool value, *res = kp->arg; + + if (!s) + s = "1"; + + ret = strtobool(s, &value); + if (ret) + return ret; + + if (!value && *res) + return -EBUSY; + + if (value && !*res) + WRITE_ONCE(*res, true); + + return 0; +} +#endif + +#if IS_ENABLED(CONFIG_EROFS_FS) +bool erofs_enabled; +EXPORT_SYMBOL(erofs_enabled); +module_param_call(erofs_enabled, param_set_bool_on_only_once, param_get_bool, + &erofs_enabled, 0644); +#endif diff --git a/include/linux/fs.h b/include/linux/fs.h index 7e8684e3f05d..911c923c91bf 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3698,4 +3698,8 @@ bool generic_atomic_write_valid(loff_t pos, size_t len, return true; }
+#if IS_ENABLED(CONFIG_EROFS_FS) +extern bool erofs_enabled; +#endif + #endif /* _LINUX_FS_H */