[PATCH 1/2] erofs: simplify instantiation of pseudo mount in fscache mode

Gao Xiang hsiangkao at linux.alibaba.com
Fri Feb 3 18:17:55 AEDT 2023



On 2023/2/3 15:14, Gao Xiang wrote:
> 
> 
> On 2023/2/3 11:47, Jingbo Xu wrote:
>> Introduce a pseudo fs type dedicated to the pseudo mount of fscache
>> mode, so that the logic of real mount won't be messed up with that of
>> pseudo mount, making the implementation of fscache mode more
>> self-contained.
>>
>> Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
>> ---
>>   fs/erofs/fscache.c  | 46 +++++++++++++++++++++++++++------------------
>>   fs/erofs/internal.h |  6 ++++++
>>   fs/erofs/super.c    | 35 +++++++---------------------------
>>   3 files changed, 41 insertions(+), 46 deletions(-)
>>
>> diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
>> index af6ba52bbe8b..2eb42bbc56a4 100644
>> --- a/fs/erofs/fscache.c
>> +++ b/fs/erofs/fscache.c
>> @@ -6,12 +6,13 @@
>>   #include <linux/fscache.h>
>>   #include <linux/file.h>
>>   #include <linux/anon_inodes.h>
>> +#include <linux/pseudo_fs.h>
>>   #include "internal.h"
>>   static DEFINE_MUTEX(erofs_domain_list_lock);
>>   static DEFINE_MUTEX(erofs_domain_cookies_lock);
>>   static LIST_HEAD(erofs_domain_list);
>> -static struct vfsmount *erofs_pseudo_mnt;
>> +static struct vfsmount *erofs_pseudo_mnt __read_mostly;
>>   struct erofs_fscache_request {
>>       struct erofs_fscache_request *primary;
>> @@ -471,10 +472,6 @@ static void erofs_fscache_domain_put(struct erofs_domain *domain)
>>       mutex_lock(&erofs_domain_list_lock);
>>       if (refcount_dec_and_test(&domain->ref)) {
>>           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);
>>           fscache_relinquish_volume(domain->volume, NULL, false);
>>           kfree(domain->domain_id);
>> @@ -526,15 +523,10 @@ static int erofs_fscache_init_domain(struct super_block *sb)
>>       }
>>       err = erofs_fscache_register_volume(sb);
>> -    if (err)
>> -        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;
>> -        }
>> +    if (err) {
>> +        kfree(domain->domain_id);
>> +        kfree(domain);
>> +        return err;
>>       }
>>       domain->volume = sbi->volume;
>> @@ -542,10 +534,6 @@ static int erofs_fscache_init_domain(struct super_block *sb)
>>       list_add(&domain->list, &erofs_domain_list);
>>       sbi->domain = domain;
>>       return 0;
>> -out:
>> -    kfree(domain->domain_id);
>> -    kfree(domain);
>> -    return err;
>>   }
>>   static int erofs_fscache_register_domain(struct super_block *sb)
>> @@ -780,3 +768,25 @@ void erofs_fscache_unregister_fs(struct super_block *sb)
>>       sbi->volume = NULL;
>>       sbi->domain = NULL;
>>   }
>> +
>> +static int erofs_fc_anon_get_tree(struct fs_context *fc)
>> +{
>> +    return PTR_ERR_OR_ZERO(init_pseudo(fc, EROFS_SUPER_MAGIC));
>> +}
>> +
>> +int __init erofs_fscache_init(void)
>> +{
>> +    static struct file_system_type erofs_anon_fs = {
>> +        .name        = "erofs_anonfs",
>> +        .init_fs_context = erofs_fc_anon_get_tree,
>> +        .kill_sb    = kill_anon_super,
>> +    };
> 
> 
> Please don't add another filesystem type, thanks.

I think it can be cleaned up nicely with Christoph's patchset, please help
follow if possible,
https://lore.kernel.org/linux-fsdevel/20210310083723.GC5217@lst.de/

Thanks,
Gao Xiang

> 
> Thanks,
> Gao Xiang


More information about the Linux-erofs mailing list