Commit 2ef16441 authored by Jia Zhu's avatar Jia Zhu Committed by Gao Xiang

erofs: introduce 'domain_id' mount option

Introduce 'domain_id' mount option to enable shared domain sementics.
In which case, the related cookie is shared if two mountpoints in the
same domain have the same data blob. Users could specify the name of
domain by this mount option.
Signed-off-by: default avatarJia Zhu <zhujia.zj@bytedance.com>
Reviewed-by: default avatarJingbo Xu <jefflexu@linux.alibaba.com>
Link: https://lore.kernel.org/r/20220918043456.147-7-zhujia.zj@bytedance.comSigned-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent 7d419637
...@@ -440,6 +440,7 @@ enum { ...@@ -440,6 +440,7 @@ enum {
Opt_dax_enum, Opt_dax_enum,
Opt_device, Opt_device,
Opt_fsid, Opt_fsid,
Opt_domain_id,
Opt_err Opt_err
}; };
...@@ -465,6 +466,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = { ...@@ -465,6 +466,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {
fsparam_enum("dax", Opt_dax_enum, erofs_dax_param_enums), fsparam_enum("dax", Opt_dax_enum, erofs_dax_param_enums),
fsparam_string("device", Opt_device), fsparam_string("device", Opt_device),
fsparam_string("fsid", Opt_fsid), fsparam_string("fsid", Opt_fsid),
fsparam_string("domain_id", Opt_domain_id),
{} {}
}; };
...@@ -568,6 +570,16 @@ static int erofs_fc_parse_param(struct fs_context *fc, ...@@ -568,6 +570,16 @@ static int erofs_fc_parse_param(struct fs_context *fc,
return -ENOMEM; return -ENOMEM;
#else #else
errorfc(fc, "fsid option not supported"); errorfc(fc, "fsid option not supported");
#endif
break;
case Opt_domain_id:
#ifdef CONFIG_EROFS_FS_ONDEMAND
kfree(ctx->opt.domain_id);
ctx->opt.domain_id = kstrdup(param->string, GFP_KERNEL);
if (!ctx->opt.domain_id)
return -ENOMEM;
#else
errorfc(fc, "domain_id option not supported");
#endif #endif
break; break;
default: default:
...@@ -702,6 +714,7 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) ...@@ -702,6 +714,7 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
sb->s_fs_info = sbi; sb->s_fs_info = sbi;
sbi->opt = ctx->opt; sbi->opt = ctx->opt;
ctx->opt.fsid = NULL; ctx->opt.fsid = NULL;
ctx->opt.domain_id = NULL;
sbi->devs = ctx->devs; sbi->devs = ctx->devs;
ctx->devs = NULL; ctx->devs = NULL;
...@@ -846,6 +859,7 @@ static void erofs_fc_free(struct fs_context *fc) ...@@ -846,6 +859,7 @@ static void erofs_fc_free(struct fs_context *fc)
erofs_free_dev_context(ctx->devs); erofs_free_dev_context(ctx->devs);
kfree(ctx->opt.fsid); kfree(ctx->opt.fsid);
kfree(ctx->opt.domain_id);
kfree(ctx); kfree(ctx);
} }
...@@ -916,6 +930,7 @@ static void erofs_kill_sb(struct super_block *sb) ...@@ -916,6 +930,7 @@ static void erofs_kill_sb(struct super_block *sb)
fs_put_dax(sbi->dax_dev, NULL); fs_put_dax(sbi->dax_dev, NULL);
erofs_fscache_unregister_fs(sb); erofs_fscache_unregister_fs(sb);
kfree(sbi->opt.fsid); kfree(sbi->opt.fsid);
kfree(sbi->opt.domain_id);
kfree(sbi); kfree(sbi);
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
} }
...@@ -1068,6 +1083,8 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root) ...@@ -1068,6 +1083,8 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)
#ifdef CONFIG_EROFS_FS_ONDEMAND #ifdef CONFIG_EROFS_FS_ONDEMAND
if (opt->fsid) if (opt->fsid)
seq_printf(seq, ",fsid=%s", opt->fsid); seq_printf(seq, ",fsid=%s", opt->fsid);
if (opt->domain_id)
seq_printf(seq, ",domain_id=%s", opt->domain_id);
#endif #endif
return 0; return 0;
} }
......
...@@ -201,12 +201,27 @@ static struct kobject erofs_feat = { ...@@ -201,12 +201,27 @@ static struct kobject erofs_feat = {
int erofs_register_sysfs(struct super_block *sb) int erofs_register_sysfs(struct super_block *sb)
{ {
struct erofs_sb_info *sbi = EROFS_SB(sb); struct erofs_sb_info *sbi = EROFS_SB(sb);
char *name;
char *str = NULL;
int err; int err;
if (erofs_is_fscache_mode(sb)) {
if (sbi->opt.domain_id) {
str = kasprintf(GFP_KERNEL, "%s,%s", sbi->opt.domain_id,
sbi->opt.fsid);
if (!str)
return -ENOMEM;
name = str;
} else {
name = sbi->opt.fsid;
}
} else {
name = sb->s_id;
}
sbi->s_kobj.kset = &erofs_root; sbi->s_kobj.kset = &erofs_root;
init_completion(&sbi->s_kobj_unregister); init_completion(&sbi->s_kobj_unregister);
err = kobject_init_and_add(&sbi->s_kobj, &erofs_sb_ktype, NULL, "%s", err = kobject_init_and_add(&sbi->s_kobj, &erofs_sb_ktype, NULL, "%s", name);
erofs_is_fscache_mode(sb) ? sbi->opt.fsid : sb->s_id); kfree(str);
if (err) if (err)
goto put_sb_kobj; goto put_sb_kobj;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment