From: Gao Xiang hsiangkao@linux.alibaba.com
anolis inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT
Reference: https://gitee.com/anolis/cloud-kernel/commit/0960115ba31d
--------------------------------
ANBZ: #1666
commit 37c90c5fae701983e21cc80396649e3aca7f4fa1 upstream.
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.
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 Signed-off-by: Huang Jianan jnhuang@linux.alibaba.com Reviewed-by: Jeffle Xu jefflexu@linux.alibaba.com Signed-off-by: Baokun Li libaokun1@huawei.com --- fs/erofs/internal.h | 1 + fs/erofs/super.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 22844d047566..06aa8dc55cfc 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -127,6 +127,7 @@ struct erofs_sb_info {
/* fscache support */ struct fscache_cookie *volume; + struct erofs_fscache *s_fscache; };
#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 2b21c5efaff3..7af2afd62c40 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -427,6 +427,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) int err;
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); if (!sbi) @@ -444,6 +447,10 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) err = erofs_fscache_register_fs(sb); if (err) return err; + err = erofs_fscache_register_cookie(sb, &sbi->s_fscache, + sbi->opt.fsid, true); + if (err) + return err; } else { if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { erofs_err(sb, "failed to set erofs blksize"); @@ -455,11 +462,7 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) if (err) return err;
- 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_xattr = erofs_xattr_handlers;
if (test_opt(&sbi->opt, POSIX_ACL)) @@ -592,6 +595,7 @@ static void erofs_kill_sb(struct super_block *sb) if (!sbi) return; erofs_free_dev_context(sbi->devs); + erofs_fscache_unregister_cookie(&sbi->s_fscache); erofs_fscache_unregister_fs(sb); kfree(sbi); sb->s_fs_info = NULL; @@ -609,6 +613,7 @@ static void erofs_put_super(struct super_block *sb) iput(sbi->managed_cache); sbi->managed_cache = NULL; #endif + erofs_fscache_unregister_cookie(&sbi->s_fscache); }
static struct file_system_type erofs_fs_type = {