Commit 78c054ed authored by Zizhi Wo's avatar Zizhi Wo
Browse files

erofs: add erofs_ondemand switch

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT



--------------------------------

In order to make the user state better control the characteristics of the
on demand load mode, a dynamic switch about the on-demand mode is added.

The switch named cachefiles_ondemand_enabled is closed by default, and is
isolated by CONFIG_CACHEFILES_ONDEMAND. Users can open it by echo
1/on/ON/y/Y to /sys/module/fs_ctl/parameters/cachefiles_ondemand_enabled.

Signed-off-by: default avatarZizhi Wo <wozizhi@huawei.com>
parent 3af8d2e6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -780,6 +780,10 @@ static int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)

	if (IS_ENABLED(CONFIG_CACHEFILES_ONDEMAND)) {
		if (!strcmp(args, "ondemand")) {
			if (!cachefiles_ondemand_is_enabled()) {
				pr_err("ondemand mode is disabled\n");
				return -EINVAL;
			}
			set_bit(CACHEFILES_ONDEMAND_MODE, &cache->flags);
		} else if (*args) {
			pr_err("Invalid argument to the 'bind' command\n");
+1 −0
Original line number Diff line number Diff line
@@ -176,6 +176,7 @@ struct erofs_sb_info {
	struct erofs_domain *domain;
	char *fsid;
	char *domain_id;
	bool  ondemand_enabled;
};

#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
+15 −1
Original line number Diff line number Diff line
@@ -514,12 +514,20 @@ static int erofs_fc_parse_param(struct fs_context *fc,
		break;
#ifdef CONFIG_EROFS_FS_ONDEMAND
	case Opt_fsid:
		if (!sbi->ondemand_enabled) {
			errorfc(fc, "fsid option not supported");
			break;
		}
		kfree(sbi->fsid);
		sbi->fsid = kstrdup(param->string, GFP_KERNEL);
		if (!sbi->fsid)
			return -ENOMEM;
		break;
	case Opt_domain_id:
		if (!sbi->ondemand_enabled) {
			errorfc(fc, "domain_id option not supported");
			break;
		}
		kfree(sbi->domain_id);
		sbi->domain_id = kstrdup(param->string, GFP_KERNEL);
		if (!sbi->domain_id)
@@ -762,11 +770,16 @@ static const struct fs_context_operations erofs_context_ops = {
	.free		= erofs_fc_free,
};

static inline bool erofs_can_init(void)
{
	return READ_ONCE(erofs_enabled) || cachefiles_ondemand_is_enabled();
}

static int erofs_init_fs_context(struct fs_context *fc)
{
	struct erofs_sb_info *sbi;

	if (!READ_ONCE(erofs_enabled))
	if (!erofs_can_init())
		return -EOPNOTSUPP;

	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
@@ -778,6 +791,7 @@ static int erofs_init_fs_context(struct fs_context *fc)
		kfree(sbi);
		return -ENOMEM;
	}
	sbi->ondemand_enabled = cachefiles_ondemand_is_enabled();
	fc->s_fs_info = sbi;

	idr_init(&sbi->devs->tree);
+8 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
#include <linux/kernel.h>
#include <linux/fs.h>

#if IS_ENABLED(CONFIG_EROFS_FS)
#if IS_ENABLED(CONFIG_EROFS_FS) || IS_ENABLED(CONFIG_CACHEFILES_ONDEMAND)
static int param_set_bool_on_only_once(const char *s, const struct kernel_param *kp)
{
	int ret;
@@ -34,3 +34,10 @@ EXPORT_SYMBOL(erofs_enabled);
module_param_call(erofs_enabled, param_set_bool_on_only_once, param_get_bool,
		  &erofs_enabled, 0644);
#endif

#if IS_ENABLED(CONFIG_CACHEFILES_ONDEMAND)
bool cachefiles_ondemand_enabled;
EXPORT_SYMBOL(cachefiles_ondemand_enabled);
module_param_call(cachefiles_ondemand_enabled, param_set_bool_on_only_once, param_get_bool,
		  &cachefiles_ondemand_enabled, 0644);
#endif
+13 −0
Original line number Diff line number Diff line
@@ -3586,4 +3586,17 @@ static inline void fs_file_read_do_trace(struct kiocb *iocb) {}
extern bool erofs_enabled;
#endif

#if IS_ENABLED(CONFIG_CACHEFILES_ONDEMAND)
extern bool cachefiles_ondemand_enabled;
static inline bool cachefiles_ondemand_is_enabled(void)
{
	return READ_ONCE(cachefiles_ondemand_enabled);
}
#else
static inline bool cachefiles_ondemand_is_enabled(void)
{
	return false;
}
#endif

#endif /* _LINUX_FS_H */