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 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 --- fs/Makefile | 1 + fs/erofs/super.c | 3 +++ fs/fs_ctl.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 ++++ 4 files changed, 44 insertions(+) create mode 100644 fs/fs_ctl.c
diff --git a/fs/Makefile b/fs/Makefile index f1b15345e6a1..45e54c34c309 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -16,6 +16,7 @@ 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 mnt_idmapping.o remap_range.o +obj-y += fs_ctl.o
obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o obj-$(CONFIG_PROC_FS) += proc_namespace.o diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 113414e6f35b..43fc432337c5 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -766,6 +766,9 @@ static int erofs_init_fs_context(struct fs_context *fc) { struct erofs_sb_info *sbi;
+ if (!READ_ONCE(erofs_enabled)) + return -EOPNOTSUPP; + sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); if (!sbi) return -ENOMEM; diff --git a/fs/fs_ctl.c b/fs/fs_ctl.c new file mode 100644 index 000000000000..14ddf0b5607f --- /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 = true; +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 db0ad52d3b48..8e84757981d3 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3582,4 +3582,8 @@ static inline void fs_file_read_update_args_by_trace(struct kiocb *iocb) {} static inline void fs_file_read_do_trace(struct kiocb *iocb) {} #endif
+#if IS_ENABLED(CONFIG_EROFS_FS) +extern bool erofs_enabled; +#endif + #endif /* _LINUX_FS_H */