erofs: register fscache context for primary data blob

Registers fscache context for primary data blob. Also move the
initialization of s_op and related fields forward, since anonymous
inode will be allocated under the super block when registering the
fscache context.

Something worth mentioning about the cleanup routine.

1. The fscache context will instantiate anonymous inodes under the super
block. Release these anonymous inodes when .put_super() is called, or
we'll get "VFS: Busy inodes after unmount." warning.

2. The fscache context is initialized prior to the root inode. If
.kill_sb() is called when mount failed, .put_super() won't be called
when root inode has not been initialized yet. Thus .kill_sb() shall
also contain the cleanup routine.

Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20220425122143.56815-16-jefflexu@linux.alibaba.com
Acked-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
This commit is contained in:
Jeffle Xu 2022-04-25 20:21:37 +08:00 committed by Gao Xiang
parent ec00b5e29c
commit 37c90c5fae
2 changed files with 12 additions and 4 deletions

View File

@ -155,6 +155,7 @@ struct erofs_sb_info {
/* fscache support */ /* fscache support */
struct fscache_volume *volume; struct fscache_volume *volume;
struct erofs_fscache *s_fscache;
}; };
#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)

View File

@ -628,6 +628,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
int err; int err;
sb->s_magic = EROFS_SUPER_MAGIC; sb->s_magic = EROFS_SUPER_MAGIC;
sb->s_flags |= SB_RDONLY | SB_NOATIME;
sb->s_maxbytes = MAX_LFS_FILESIZE;
sb->s_op = &erofs_sops;
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
if (!sbi) if (!sbi)
@ -645,6 +648,11 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
err = erofs_fscache_register_fs(sb); err = erofs_fscache_register_fs(sb);
if (err) if (err)
return err; return err;
err = erofs_fscache_register_cookie(sb, &sbi->s_fscache,
sbi->opt.fsid, true);
if (err)
return err;
} else { } else {
if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
erofs_err(sb, "failed to set erofs blksize"); erofs_err(sb, "failed to set erofs blksize");
@ -667,11 +675,8 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
clear_opt(&sbi->opt, DAX_ALWAYS); clear_opt(&sbi->opt, DAX_ALWAYS);
} }
} }
sb->s_flags |= SB_RDONLY | SB_NOATIME;
sb->s_maxbytes = MAX_LFS_FILESIZE;
sb->s_time_gran = 1;
sb->s_op = &erofs_sops; sb->s_time_gran = 1;
sb->s_xattr = erofs_xattr_handlers; sb->s_xattr = erofs_xattr_handlers;
sb->s_export_op = &erofs_export_ops; sb->s_export_op = &erofs_export_ops;
@ -812,6 +817,7 @@ static void erofs_kill_sb(struct super_block *sb)
erofs_free_dev_context(sbi->devs); erofs_free_dev_context(sbi->devs);
fs_put_dax(sbi->dax_dev); fs_put_dax(sbi->dax_dev);
erofs_fscache_unregister_cookie(&sbi->s_fscache);
erofs_fscache_unregister_fs(sb); erofs_fscache_unregister_fs(sb);
kfree(sbi); kfree(sbi);
sb->s_fs_info = NULL; sb->s_fs_info = NULL;
@ -830,6 +836,7 @@ static void erofs_put_super(struct super_block *sb)
iput(sbi->managed_cache); iput(sbi->managed_cache);
sbi->managed_cache = NULL; sbi->managed_cache = NULL;
#endif #endif
erofs_fscache_unregister_cookie(&sbi->s_fscache);
} }
static struct file_system_type erofs_fs_type = { static struct file_system_type erofs_fs_type = {