Commit a9849560 authored by Jia Zhu's avatar Jia Zhu Committed by Gao Xiang

erofs: introduce a pseudo mnt to manage shared cookies

Use a pseudo mnt to manage shared cookies.
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-5-zhujia.zj@bytedance.comSigned-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent 8b7adf1d
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
static DEFINE_MUTEX(erofs_domain_list_lock); static DEFINE_MUTEX(erofs_domain_list_lock);
static LIST_HEAD(erofs_domain_list); static LIST_HEAD(erofs_domain_list);
static struct vfsmount *erofs_pseudo_mnt;
static struct netfs_io_request *erofs_fscache_alloc_request(struct address_space *mapping, static struct netfs_io_request *erofs_fscache_alloc_request(struct address_space *mapping,
loff_t start, size_t len) loff_t start, size_t len)
...@@ -432,6 +433,10 @@ static void erofs_fscache_domain_put(struct erofs_domain *domain) ...@@ -432,6 +433,10 @@ static void erofs_fscache_domain_put(struct erofs_domain *domain)
mutex_lock(&erofs_domain_list_lock); mutex_lock(&erofs_domain_list_lock);
if (refcount_dec_and_test(&domain->ref)) { if (refcount_dec_and_test(&domain->ref)) {
list_del(&domain->list); list_del(&domain->list);
if (list_empty(&erofs_domain_list)) {
kern_unmount(erofs_pseudo_mnt);
erofs_pseudo_mnt = NULL;
}
mutex_unlock(&erofs_domain_list_lock); mutex_unlock(&erofs_domain_list_lock);
fscache_relinquish_volume(domain->volume, NULL, false); fscache_relinquish_volume(domain->volume, NULL, false);
kfree(domain->domain_id); kfree(domain->domain_id);
...@@ -486,6 +491,14 @@ static int erofs_fscache_init_domain(struct super_block *sb) ...@@ -486,6 +491,14 @@ static int erofs_fscache_init_domain(struct super_block *sb)
if (err) if (err)
goto out; goto out;
if (!erofs_pseudo_mnt) {
erofs_pseudo_mnt = kern_mount(&erofs_fs_type);
if (IS_ERR(erofs_pseudo_mnt)) {
err = PTR_ERR(erofs_pseudo_mnt);
goto out;
}
}
domain->volume = sbi->volume; domain->volume = sbi->volume;
refcount_set(&domain->ref, 1); refcount_set(&domain->ref, 1);
list_add(&domain->list, &erofs_domain_list); list_add(&domain->list, &erofs_domain_list);
......
...@@ -373,6 +373,7 @@ struct page *erofs_grab_cache_page_nowait(struct address_space *mapping, ...@@ -373,6 +373,7 @@ struct page *erofs_grab_cache_page_nowait(struct address_space *mapping,
} }
extern const struct super_operations erofs_sops; extern const struct super_operations erofs_sops;
extern struct file_system_type erofs_fs_type;
extern const struct address_space_operations erofs_raw_access_aops; extern const struct address_space_operations erofs_raw_access_aops;
extern const struct address_space_operations z_erofs_aops; extern const struct address_space_operations z_erofs_aops;
......
...@@ -676,6 +676,13 @@ static const struct export_operations erofs_export_ops = { ...@@ -676,6 +676,13 @@ static const struct export_operations erofs_export_ops = {
.get_parent = erofs_get_parent, .get_parent = erofs_get_parent,
}; };
static int erofs_fc_fill_pseudo_super(struct super_block *sb, struct fs_context *fc)
{
static const struct tree_descr empty_descr = {""};
return simple_fill_super(sb, EROFS_SUPER_MAGIC, &empty_descr);
}
static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
{ {
struct inode *inode; struct inode *inode;
...@@ -776,6 +783,11 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) ...@@ -776,6 +783,11 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
return 0; return 0;
} }
static int erofs_fc_anon_get_tree(struct fs_context *fc)
{
return get_tree_nodev(fc, erofs_fc_fill_pseudo_super);
}
static int erofs_fc_get_tree(struct fs_context *fc) static int erofs_fc_get_tree(struct fs_context *fc)
{ {
struct erofs_fs_context *ctx = fc->fs_private; struct erofs_fs_context *ctx = fc->fs_private;
...@@ -844,10 +856,21 @@ static const struct fs_context_operations erofs_context_ops = { ...@@ -844,10 +856,21 @@ static const struct fs_context_operations erofs_context_ops = {
.free = erofs_fc_free, .free = erofs_fc_free,
}; };
static const struct fs_context_operations erofs_anon_context_ops = {
.get_tree = erofs_fc_anon_get_tree,
};
static int erofs_init_fs_context(struct fs_context *fc) static int erofs_init_fs_context(struct fs_context *fc)
{ {
struct erofs_fs_context *ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); struct erofs_fs_context *ctx;
/* pseudo mount for anon inodes */
if (fc->sb_flags & SB_KERNMOUNT) {
fc->ops = &erofs_anon_context_ops;
return 0;
}
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL); ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL);
...@@ -874,6 +897,12 @@ static void erofs_kill_sb(struct super_block *sb) ...@@ -874,6 +897,12 @@ static void erofs_kill_sb(struct super_block *sb)
WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC); WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
/* pseudo mount for anon inodes */
if (sb->s_flags & SB_KERNMOUNT) {
kill_anon_super(sb);
return;
}
if (erofs_is_fscache_mode(sb)) if (erofs_is_fscache_mode(sb))
kill_anon_super(sb); kill_anon_super(sb);
else else
...@@ -907,7 +936,7 @@ static void erofs_put_super(struct super_block *sb) ...@@ -907,7 +936,7 @@ static void erofs_put_super(struct super_block *sb)
erofs_fscache_unregister_fs(sb); erofs_fscache_unregister_fs(sb);
} }
static struct file_system_type erofs_fs_type = { struct file_system_type erofs_fs_type = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "erofs", .name = "erofs",
.init_fs_context = erofs_init_fs_context, .init_fs_context = erofs_init_fs_context,
......
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