Skip to content

Commit a984956

Browse files
Jia Zhuhsiangkao
authored andcommitted
erofs: introduce a pseudo mnt to manage shared cookies
Use a pseudo mnt to manage shared cookies. Signed-off-by: Jia Zhu <[email protected]> Reviewed-by: Jingbo Xu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 8b7adf1 commit a984956

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

fs/erofs/fscache.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
static DEFINE_MUTEX(erofs_domain_list_lock);
1010
static LIST_HEAD(erofs_domain_list);
11+
static struct vfsmount *erofs_pseudo_mnt;
1112

1213
static struct netfs_io_request *erofs_fscache_alloc_request(struct address_space *mapping,
1314
loff_t start, size_t len)
@@ -432,6 +433,10 @@ static void erofs_fscache_domain_put(struct erofs_domain *domain)
432433
mutex_lock(&erofs_domain_list_lock);
433434
if (refcount_dec_and_test(&domain->ref)) {
434435
list_del(&domain->list);
436+
if (list_empty(&erofs_domain_list)) {
437+
kern_unmount(erofs_pseudo_mnt);
438+
erofs_pseudo_mnt = NULL;
439+
}
435440
mutex_unlock(&erofs_domain_list_lock);
436441
fscache_relinquish_volume(domain->volume, NULL, false);
437442
kfree(domain->domain_id);
@@ -486,6 +491,14 @@ static int erofs_fscache_init_domain(struct super_block *sb)
486491
if (err)
487492
goto out;
488493

494+
if (!erofs_pseudo_mnt) {
495+
erofs_pseudo_mnt = kern_mount(&erofs_fs_type);
496+
if (IS_ERR(erofs_pseudo_mnt)) {
497+
err = PTR_ERR(erofs_pseudo_mnt);
498+
goto out;
499+
}
500+
}
501+
489502
domain->volume = sbi->volume;
490503
refcount_set(&domain->ref, 1);
491504
list_add(&domain->list, &erofs_domain_list);

fs/erofs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ struct page *erofs_grab_cache_page_nowait(struct address_space *mapping,
373373
}
374374

375375
extern const struct super_operations erofs_sops;
376+
extern struct file_system_type erofs_fs_type;
376377

377378
extern const struct address_space_operations erofs_raw_access_aops;
378379
extern const struct address_space_operations z_erofs_aops;

fs/erofs/super.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,13 @@ static const struct export_operations erofs_export_ops = {
676676
.get_parent = erofs_get_parent,
677677
};
678678

679+
static int erofs_fc_fill_pseudo_super(struct super_block *sb, struct fs_context *fc)
680+
{
681+
static const struct tree_descr empty_descr = {""};
682+
683+
return simple_fill_super(sb, EROFS_SUPER_MAGIC, &empty_descr);
684+
}
685+
679686
static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
680687
{
681688
struct inode *inode;
@@ -776,6 +783,11 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
776783
return 0;
777784
}
778785

786+
static int erofs_fc_anon_get_tree(struct fs_context *fc)
787+
{
788+
return get_tree_nodev(fc, erofs_fc_fill_pseudo_super);
789+
}
790+
779791
static int erofs_fc_get_tree(struct fs_context *fc)
780792
{
781793
struct erofs_fs_context *ctx = fc->fs_private;
@@ -844,10 +856,21 @@ static const struct fs_context_operations erofs_context_ops = {
844856
.free = erofs_fc_free,
845857
};
846858

859+
static const struct fs_context_operations erofs_anon_context_ops = {
860+
.get_tree = erofs_fc_anon_get_tree,
861+
};
862+
847863
static int erofs_init_fs_context(struct fs_context *fc)
848864
{
849-
struct erofs_fs_context *ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
865+
struct erofs_fs_context *ctx;
866+
867+
/* pseudo mount for anon inodes */
868+
if (fc->sb_flags & SB_KERNMOUNT) {
869+
fc->ops = &erofs_anon_context_ops;
870+
return 0;
871+
}
850872

873+
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
851874
if (!ctx)
852875
return -ENOMEM;
853876
ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL);
@@ -874,6 +897,12 @@ static void erofs_kill_sb(struct super_block *sb)
874897

875898
WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
876899

900+
/* pseudo mount for anon inodes */
901+
if (sb->s_flags & SB_KERNMOUNT) {
902+
kill_anon_super(sb);
903+
return;
904+
}
905+
877906
if (erofs_is_fscache_mode(sb))
878907
kill_anon_super(sb);
879908
else
@@ -907,7 +936,7 @@ static void erofs_put_super(struct super_block *sb)
907936
erofs_fscache_unregister_fs(sb);
908937
}
909938

910-
static struct file_system_type erofs_fs_type = {
939+
struct file_system_type erofs_fs_type = {
911940
.owner = THIS_MODULE,
912941
.name = "erofs",
913942
.init_fs_context = erofs_init_fs_context,

0 commit comments

Comments
 (0)