Commit 3af8d2e6 authored by Zizhi Wo's avatar Zizhi Wo
Browse files

erofs: add erofs switch to better control it

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: default avatarZizhi Wo <wozizhi@huawei.com>
parent 4248e3f0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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
+3 −0
Original line number Diff line number Diff line
@@ -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;

fs/fs_ctl.c

0 → 100644
+36 −0
Original line number Diff line number Diff line
// 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
+4 −0
Original line number Diff line number Diff line
@@ -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 */