staging: erofs: kill all failure handling in fill_super()
.kill_sb() will do that instead in order to remove duplicated code. Note that the initialzation of managed_cache is now moved after s_root is assigned since it's more preferred to iput() in .put_super() and all inodes should be evicted before the end of generic_shutdown_super(sb). Suggested-by: Al Viro <viro@zeniv.linux.org.uk> Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com> Link: https://lore.kernel.org/r/20190731155752.210602-12-gaoxiang25@huawei.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
9e794de573
commit
8f7acdae2c
|
@ -343,12 +343,13 @@ static const struct address_space_operations managed_cache_aops = {
|
||||||
.invalidatepage = managed_cache_invalidatepage,
|
.invalidatepage = managed_cache_invalidatepage,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct inode *erofs_init_managed_cache(struct super_block *sb)
|
static int erofs_init_managed_cache(struct super_block *sb)
|
||||||
{
|
{
|
||||||
struct inode *inode = new_inode(sb);
|
struct erofs_sb_info *const sbi = EROFS_SB(sb);
|
||||||
|
struct inode *const inode = new_inode(sb);
|
||||||
|
|
||||||
if (unlikely(!inode))
|
if (unlikely(!inode))
|
||||||
return ERR_PTR(-ENOMEM);
|
return -ENOMEM;
|
||||||
|
|
||||||
set_nlink(inode, 1);
|
set_nlink(inode, 1);
|
||||||
inode->i_size = OFFSET_MAX;
|
inode->i_size = OFFSET_MAX;
|
||||||
|
@ -357,37 +358,38 @@ static struct inode *erofs_init_managed_cache(struct super_block *sb)
|
||||||
mapping_set_gfp_mask(inode->i_mapping,
|
mapping_set_gfp_mask(inode->i_mapping,
|
||||||
GFP_NOFS | __GFP_HIGHMEM |
|
GFP_NOFS | __GFP_HIGHMEM |
|
||||||
__GFP_MOVABLE | __GFP_NOFAIL);
|
__GFP_MOVABLE | __GFP_NOFAIL);
|
||||||
return inode;
|
sbi->managed_cache = inode;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static int erofs_init_managed_cache(struct super_block *sb) { return 0; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int erofs_fill_super(struct super_block *sb, void *data, int silent)
|
static int erofs_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
{
|
{
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
struct erofs_sb_info *sbi;
|
struct erofs_sb_info *sbi;
|
||||||
int err = -EINVAL;
|
int err;
|
||||||
|
|
||||||
infoln("fill_super, device -> %s", sb->s_id);
|
infoln("fill_super, device -> %s", sb->s_id);
|
||||||
infoln("options -> %s", (char *)data);
|
infoln("options -> %s", (char *)data);
|
||||||
|
|
||||||
|
sb->s_magic = EROFS_SUPER_MAGIC;
|
||||||
|
|
||||||
if (unlikely(!sb_set_blocksize(sb, EROFS_BLKSIZ))) {
|
if (unlikely(!sb_set_blocksize(sb, EROFS_BLKSIZ))) {
|
||||||
errln("failed to set erofs blksize");
|
errln("failed to set erofs blksize");
|
||||||
goto err;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
|
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
|
||||||
if (unlikely(!sbi)) {
|
if (unlikely(!sbi))
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
sb->s_fs_info = sbi;
|
|
||||||
|
|
||||||
|
sb->s_fs_info = sbi;
|
||||||
err = superblock_read(sb);
|
err = superblock_read(sb);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_sbread;
|
return err;
|
||||||
|
|
||||||
sb->s_magic = EROFS_SUPER_MAGIC;
|
|
||||||
sb->s_flags |= SB_RDONLY | SB_NOATIME;
|
sb->s_flags |= SB_RDONLY | SB_NOATIME;
|
||||||
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
||||||
sb->s_time_gran = 1;
|
sb->s_time_gran = 1;
|
||||||
|
@ -397,13 +399,12 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
#ifdef CONFIG_EROFS_FS_XATTR
|
#ifdef CONFIG_EROFS_FS_XATTR
|
||||||
sb->s_xattr = erofs_xattr_handlers;
|
sb->s_xattr = erofs_xattr_handlers;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* set erofs default mount options */
|
/* set erofs default mount options */
|
||||||
default_options(sbi);
|
default_options(sbi);
|
||||||
|
|
||||||
err = parse_options(sb, data);
|
err = parse_options(sb, data);
|
||||||
if (err)
|
if (unlikely(err))
|
||||||
goto err_parseopt;
|
return err;
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
infoln("root inode @ nid %llu", ROOT_NID(sbi));
|
infoln("root inode @ nid %llu", ROOT_NID(sbi));
|
||||||
|
@ -417,80 +418,31 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC);
|
INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EROFS_FS_HAS_MANAGED_CACHE
|
|
||||||
sbi->managed_cache = erofs_init_managed_cache(sb);
|
|
||||||
if (IS_ERR(sbi->managed_cache)) {
|
|
||||||
err = PTR_ERR(sbi->managed_cache);
|
|
||||||
goto err_init_managed_cache;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* get the root inode */
|
/* get the root inode */
|
||||||
inode = erofs_iget(sb, ROOT_NID(sbi), true);
|
inode = erofs_iget(sb, ROOT_NID(sbi), true);
|
||||||
if (IS_ERR(inode)) {
|
if (IS_ERR(inode))
|
||||||
err = PTR_ERR(inode);
|
return PTR_ERR(inode);
|
||||||
goto err_iget;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!S_ISDIR(inode->i_mode)) {
|
if (unlikely(!S_ISDIR(inode->i_mode))) {
|
||||||
errln("rootino(nid %llu) is not a directory(i_mode %o)",
|
errln("rootino(nid %llu) is not a directory(i_mode %o)",
|
||||||
ROOT_NID(sbi), inode->i_mode);
|
ROOT_NID(sbi), inode->i_mode);
|
||||||
err = -EINVAL;
|
|
||||||
iput(inode);
|
iput(inode);
|
||||||
goto err_iget;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sb->s_root = d_make_root(inode);
|
sb->s_root = d_make_root(inode);
|
||||||
if (!sb->s_root) {
|
if (unlikely(!sb->s_root))
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_iget;
|
|
||||||
}
|
|
||||||
|
|
||||||
erofs_shrinker_register(sb);
|
erofs_shrinker_register(sb);
|
||||||
|
/* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */
|
||||||
|
err = erofs_init_managed_cache(sb);
|
||||||
|
if (unlikely(err))
|
||||||
|
return err;
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
infoln("mounted on %s with opts: %s.", sb->s_id, (char *)data);
|
infoln("mounted on %s with opts: %s.", sb->s_id, (char *)data);
|
||||||
return 0;
|
return 0;
|
||||||
/*
|
|
||||||
* please add a label for each exit point and use
|
|
||||||
* the following name convention, thus new features
|
|
||||||
* can be integrated easily without renaming labels.
|
|
||||||
*/
|
|
||||||
err_iget:
|
|
||||||
#ifdef EROFS_FS_HAS_MANAGED_CACHE
|
|
||||||
iput(sbi->managed_cache);
|
|
||||||
err_init_managed_cache:
|
|
||||||
#endif
|
|
||||||
err_parseopt:
|
|
||||||
err_sbread:
|
|
||||||
sb->s_fs_info = NULL;
|
|
||||||
kfree(sbi);
|
|
||||||
err:
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* could be triggered after deactivate_locked_super()
|
|
||||||
* is called, thus including umount and failed to initialize.
|
|
||||||
*/
|
|
||||||
static void erofs_put_super(struct super_block *sb)
|
|
||||||
{
|
|
||||||
struct erofs_sb_info *sbi = EROFS_SB(sb);
|
|
||||||
|
|
||||||
/* for cases which are failed in "read_super" */
|
|
||||||
if (!sbi)
|
|
||||||
return;
|
|
||||||
|
|
||||||
WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
|
|
||||||
|
|
||||||
infoln("unmounted for %s", sb->s_id);
|
|
||||||
|
|
||||||
erofs_shrinker_unregister(sb);
|
|
||||||
#ifdef EROFS_FS_HAS_MANAGED_CACHE
|
|
||||||
iput(sbi->managed_cache);
|
|
||||||
#endif
|
|
||||||
kfree(sbi);
|
|
||||||
sb->s_fs_info = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct dentry *erofs_mount(struct file_system_type *fs_type, int flags,
|
static struct dentry *erofs_mount(struct file_system_type *fs_type, int flags,
|
||||||
|
@ -499,11 +451,45 @@ static struct dentry *erofs_mount(struct file_system_type *fs_type, int flags,
|
||||||
return mount_bdev(fs_type, flags, dev_name, data, erofs_fill_super);
|
return mount_bdev(fs_type, flags, dev_name, data, erofs_fill_super);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* could be triggered after deactivate_locked_super()
|
||||||
|
* is called, thus including umount and failed to initialize.
|
||||||
|
*/
|
||||||
|
static void erofs_kill_sb(struct super_block *sb)
|
||||||
|
{
|
||||||
|
struct erofs_sb_info *sbi;
|
||||||
|
|
||||||
|
WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
|
||||||
|
infoln("unmounting for %s", sb->s_id);
|
||||||
|
|
||||||
|
kill_block_super(sb);
|
||||||
|
|
||||||
|
sbi = EROFS_SB(sb);
|
||||||
|
if (!sbi)
|
||||||
|
return;
|
||||||
|
kfree(sbi);
|
||||||
|
sb->s_fs_info = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* called when ->s_root is non-NULL */
|
||||||
|
static void erofs_put_super(struct super_block *sb)
|
||||||
|
{
|
||||||
|
struct erofs_sb_info *const sbi = EROFS_SB(sb);
|
||||||
|
|
||||||
|
DBG_BUGON(!sbi);
|
||||||
|
|
||||||
|
erofs_shrinker_unregister(sb);
|
||||||
|
#ifdef EROFS_FS_HAS_MANAGED_CACHE
|
||||||
|
iput(sbi->managed_cache);
|
||||||
|
sbi->managed_cache = NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static struct file_system_type erofs_fs_type = {
|
static struct file_system_type erofs_fs_type = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.name = "erofs",
|
.name = "erofs",
|
||||||
.mount = erofs_mount,
|
.mount = erofs_mount,
|
||||||
.kill_sb = kill_block_super,
|
.kill_sb = erofs_kill_sb,
|
||||||
.fs_flags = FS_REQUIRES_DEV,
|
.fs_flags = FS_REQUIRES_DEV,
|
||||||
};
|
};
|
||||||
MODULE_ALIAS_FS("erofs");
|
MODULE_ALIAS_FS("erofs");
|
||||||
|
|
Loading…
Reference in New Issue