From: Zizhi Wo wozizhi@huawei.com
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 Signed-off-by: Baokun Li libaokun1@huawei.com --- fs/cachefiles/bind.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/bind.c b/fs/cachefiles/bind.c index c149d5037cc1..d076651b2931 100644 --- a/fs/cachefiles/bind.c +++ b/fs/cachefiles/bind.c @@ -59,6 +59,10 @@ 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 f7b01a4be183..16eaeee4a295 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -79,6 +79,7 @@ struct erofs_fs_context { struct erofs_dev_context *devs; char *fsid; char *domain_id; + bool ondemand_enabled; };
struct erofs_domain { diff --git a/fs/erofs/super.c b/fs/erofs/super.c index a6cb90c4fcce..7c9a29d2d9d4 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -401,6 +401,10 @@ static int erofs_fc_parse_param(struct fs_context *fc, break; case Opt_fsid: #ifdef CONFIG_EROFS_FS_ONDEMAND + if (!ctx->ondemand_enabled) { + errorfc(fc, "fsid option not supported"); + return -EINVAL; + } kfree(ctx->fsid); ctx->fsid = kstrdup(param->string, GFP_KERNEL); if (!ctx->fsid) @@ -412,6 +416,10 @@ static int erofs_fc_parse_param(struct fs_context *fc, break; case Opt_domain_id: #ifdef CONFIG_EROFS_FS_ONDEMAND + if (!ctx->ondemand_enabled) { + errorfc(fc, "domain_id option not supported"); + break; + } kfree(ctx->domain_id); ctx->domain_id = kstrdup(param->string, GFP_KERNEL); if (!ctx->domain_id) @@ -657,11 +665,16 @@ static const struct fs_context_operations erofs_anon_context_ops = { .get_tree = erofs_fc_anon_get_tree, };
+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_fs_context *ctx;
- if (!READ_ONCE(erofs_enabled)) + if (!erofs_can_init()) return -EOPNOTSUPP;
/* pseudo mount for anon inodes */ @@ -678,6 +691,7 @@ static int erofs_init_fs_context(struct fs_context *fc) kfree(ctx); return -ENOMEM; } + ctx->ondemand_enabled = cachefiles_ondemand_is_enabled(); fc->fs_private = ctx;
idr_init(&ctx->devs->tree); diff --git a/fs/fs_ctl.c b/fs/fs_ctl.c index ab6b532188d9..6464c9ba5e18 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 911c923c91bf..5e6d2b63626b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3702,4 +3702,17 @@ bool generic_atomic_write_valid(loff_t pos, size_t len, 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 */