Offering: HULK 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: Zizhi Wo wozizhi@huawei.com --- fs/cachefiles/daemon.c | 4 ++++ fs/erofs/internal.h | 1 + fs/erofs/super.c | 16 +++++++++++++++- fs/fs_ctl.c | 9 ++++++++- include/linux/fs.h | 13 +++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index 59e576951c68..afec4032878c 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c @@ -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"); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 787cc9ff9029..a53152693ae2 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -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) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 43fc432337c5..db9f4bcb8c78 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -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); diff --git a/fs/fs_ctl.c b/fs/fs_ctl.c index 14ddf0b5607f..37f8a7567b96 100644 --- a/fs/fs_ctl.c +++ b/fs/fs_ctl.c @@ -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 diff --git a/include/linux/fs.h b/include/linux/fs.h index 8e84757981d3..0efc8bea182d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -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 */