LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Chao Yu <yuchao0@huawei.com>
To: Gao Xiang <gaoxiang25@huawei.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	<devel@driverdev.osuosl.org>
Cc: <linux-erofs@lists.ozlabs.org>,
	LKML <linux-kernel@vger.kernel.org>, <weidu.du@huawei.com>,
	Miao Xie <miaoxie@huawei.com>
Subject: Re: [PATCH 11/22] staging: erofs: kill all failure handling in fill_super()
Date: Wed, 31 Jul 2019 16:15:36 +0800
Message-ID: <56bdc87a-635f-e596-584e-fca0acb4a69e@huawei.com> (raw)
In-Reply-To: <20190729065159.62378-12-gaoxiang25@huawei.com>

On 2019/7/29 14:51, Gao Xiang wrote:
> .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>
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> ---
>  drivers/staging/erofs/super.c | 121 +++++++++++++++-------------------
>  1 file changed, 53 insertions(+), 68 deletions(-)
> 
> diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
> index bfb6e1e09781..af5d87793e4d 100644
> --- a/drivers/staging/erofs/super.c
> +++ b/drivers/staging/erofs/super.c
> @@ -343,51 +343,52 @@ static const struct address_space_operations managed_cache_aops = {
>  	.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))
> -		return ERR_PTR(-ENOMEM);
> +		return -ENOMEM;
>  
>  	set_nlink(inode, 1);
>  	inode->i_size = OFFSET_MAX;
>  
>  	inode->i_mapping->a_ops = &managed_cache_aops;
>  	mapping_set_gfp_mask(inode->i_mapping,
> -			     GFP_NOFS | __GFP_HIGHMEM |
> -			     __GFP_MOVABLE |  __GFP_NOFAIL);
> -	return inode;
> +			     GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE);

It looks above change is not belong to this patch?

Otherwise, it looks good to me.

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,

> +	sbi->managed_cache = inode;
> +	return 0;
>  }
> -
> +#else
> +static int erofs_init_managed_cache(struct super_block *sb) { return 0; }
>  #endif
>  
>  static int erofs_fill_super(struct super_block *sb, void *data, int silent)
>  {
>  	struct inode *inode;
>  	struct erofs_sb_info *sbi;
> -	int err = -EINVAL;
> +	int err;
>  
>  	infoln("fill_super, device -> %s", sb->s_id);
>  	infoln("options -> %s", (char *)data);
>  
> +	sb->s_magic = EROFS_SUPER_MAGIC;
> +
>  	if (unlikely(!sb_set_blocksize(sb, EROFS_BLKSIZ))) {
>  		errln("failed to set erofs blksize");
> -		goto err;
> +		return -EINVAL;
>  	}
>  
>  	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
> -	if (unlikely(!sbi)) {
> -		err = -ENOMEM;
> -		goto err;
> -	}
> -	sb->s_fs_info = sbi;
> +	if (unlikely(!sbi))
> +		return -ENOMEM;
>  
> +	sb->s_fs_info = sbi;
>  	err = superblock_read(sb);
>  	if (err)
> -		goto err_sbread;
> +		return err;
>  
> -	sb->s_magic = EROFS_SUPER_MAGIC;
>  	sb->s_flags |= SB_RDONLY | SB_NOATIME;
>  	sb->s_maxbytes = MAX_LFS_FILESIZE;
>  	sb->s_time_gran = 1;
> @@ -397,13 +398,12 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent)
>  #ifdef CONFIG_EROFS_FS_XATTR
>  	sb->s_xattr = erofs_xattr_handlers;
>  #endif
> -
>  	/* set erofs default mount options */
>  	default_options(sbi);
>  
>  	err = parse_options(sb, data);
> -	if (err)
> -		goto err_parseopt;
> +	if (unlikely(err))
> +		return err;
>  
>  	if (!silent)
>  		infoln("root inode @ nid %llu", ROOT_NID(sbi));
> @@ -417,93 +417,78 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent)
>  	INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC);
>  #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 */
>  	inode = erofs_iget(sb, ROOT_NID(sbi), true);
> -	if (IS_ERR(inode)) {
> -		err = PTR_ERR(inode);
> -		goto err_iget;
> -	}
> +	if (IS_ERR(inode))
> +		return PTR_ERR(inode);
>  
> -	if (!S_ISDIR(inode->i_mode)) {
> +	if (unlikely(!S_ISDIR(inode->i_mode))) {
>  		errln("rootino(nid %llu) is not a directory(i_mode %o)",
>  		      ROOT_NID(sbi), inode->i_mode);
> -		err = -EINVAL;
>  		iput(inode);
> -		goto err_iget;
> +		return -EINVAL;
>  	}
>  
>  	sb->s_root = d_make_root(inode);
> -	if (!sb->s_root) {
> -		err = -ENOMEM;
> -		goto err_iget;
> -	}
> +	if (unlikely(!sb->s_root))
> +		return -ENOMEM;
>  
>  	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)
>  		infoln("mounted on %s with opts: %s.", sb->s_id, (char *)data);
>  	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;
> +}
> +
> +static struct dentry *erofs_mount(struct file_system_type *fs_type, int flags,
> +				  const char *dev_name, void *data)
> +{
> +	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_put_super(struct super_block *sb)
> +static void erofs_kill_sb(struct super_block *sb)
>  {
> -	struct erofs_sb_info *sbi = EROFS_SB(sb);
> +	struct erofs_sb_info *sbi;
> +
> +	WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
> +	infoln("unmounting for %s", sb->s_id);
>  
> -	/* for cases which are failed in "read_super" */
> +	kill_block_super(sb);
> +
> +	sbi = EROFS_SB(sb);
>  	if (!sbi)
>  		return;
> +	kfree(sbi);
> +	sb->s_fs_info = NULL;
> +}
>  
> -	WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
> +/* 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);
>  
> -	infoln("unmounted for %s", sb->s_id);
> +	DBG_BUGON(!sbi);
>  
>  	erofs_shrinker_unregister(sb);
>  #ifdef EROFS_FS_HAS_MANAGED_CACHE
>  	iput(sbi->managed_cache);
> +	sbi->managed_cache = NULL;
>  #endif
> -	kfree(sbi);
> -	sb->s_fs_info = NULL;
> -}
> -
> -static struct dentry *erofs_mount(struct file_system_type *fs_type, int flags,
> -				  const char *dev_name, void *data)
> -{
> -	return mount_bdev(fs_type, flags, dev_name, data, erofs_fill_super);
>  }
>  
>  static struct file_system_type erofs_fs_type = {
>  	.owner          = THIS_MODULE,
>  	.name           = "erofs",
>  	.mount          = erofs_mount,
> -	.kill_sb        = kill_block_super,
> +	.kill_sb        = erofs_kill_sb,
>  	.fs_flags       = FS_REQUIRES_DEV,
>  };
>  MODULE_ALIAS_FS("erofs");
> 

  reply index

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-29  6:51 [PATCH 00/22] staging: erofs: updates according to erofs-outofstaging v4 Gao Xiang
2019-07-29  6:51 ` [PATCH 01/22] staging: erofs: update source file headers Gao Xiang
2019-07-30  7:20   ` Greg Kroah-Hartman
2019-07-30  7:26     ` Gao Xiang
2019-07-31  6:36   ` Chao Yu
2019-07-29  6:51 ` [PATCH 02/22] staging: erofs: rename source files for better understanding Gao Xiang
2019-07-31  6:43   ` Chao Yu
2019-07-29  6:51 ` [PATCH 03/22] staging: erofs: fix dummy functions erofs_{get,list}xattr Gao Xiang
2019-07-31  6:44   ` [PATCH 03/22] staging: erofs: fix dummy functions erofs_{get, list}xattr Chao Yu
2019-07-29  6:51 ` [PATCH 04/22] staging: erofs: keep up erofs_fs.h with erofs-outofstaging patchset Gao Xiang
2019-07-31  6:46   ` Chao Yu
2019-07-29  6:51 ` [PATCH 05/22] staging: erofs: sunset erofs_workstn_{lock,unlock} Gao Xiang
2019-07-31  6:49   ` Chao Yu
2019-07-29  6:51 ` [PATCH 06/22] staging: erofs: clean up internal.h Gao Xiang
2019-07-31  6:53   ` Chao Yu
2019-07-29  6:51 ` [PATCH 07/22] staging: erofs: remove redundant #include "internal.h" Gao Xiang
2019-07-31  7:03   ` Chao Yu
2019-07-31  7:08     ` Gao Xiang
2019-07-31 12:07       ` Chao Yu
2019-07-31 12:54         ` Gao Xiang
2019-08-01  1:31           ` Chao Yu
2019-07-29  6:51 ` [PATCH 08/22] staging: erofs: kill CONFIG_EROFS_FS_IO_MAX_RETRIES Gao Xiang
2019-07-31  7:05   ` Chao Yu
2019-07-31  7:11     ` Gao Xiang
2019-07-31 12:10       ` Chao Yu
2019-07-31 12:55         ` Gao Xiang
2019-07-29  6:51 ` [PATCH 09/22] staging: erofs: clean up shrinker stuffs Gao Xiang
2019-07-31  7:41   ` Chao Yu
2019-07-29  6:51 ` [PATCH 10/22] staging: erofs: kill sbi->dev_name Gao Xiang
2019-07-31  7:46   ` Chao Yu
2019-07-29  6:51 ` [PATCH 11/22] staging: erofs: kill all failure handling in fill_super() Gao Xiang
2019-07-31  8:15   ` Chao Yu [this message]
2019-07-31 12:52     ` Gao Xiang
2019-07-29  6:51 ` [PATCH 12/22] staging: erofs: refine erofs_allocpage() Gao Xiang
2019-07-31  8:20   ` Chao Yu
2019-07-29  6:51 ` [PATCH 13/22] staging: erofs: kill CONFIG_EROFS_FS_USE_VM_MAP_RAM Gao Xiang
2019-07-31  8:27   ` Chao Yu
2019-07-29  6:51 ` [PATCH 14/22] staging: erofs: tidy up zpvec.h Gao Xiang
2019-07-31  8:28   ` Chao Yu
2019-07-29  6:51 ` [PATCH 15/22] staging: erofs: remove redundant braces in inode.c Gao Xiang
2019-07-31  8:29   ` Chao Yu
2019-07-29  6:51 ` [PATCH 16/22] staging: erofs: tidy up decompression frontend Gao Xiang
2019-07-31  9:07   ` Chao Yu
2019-07-29  6:51 ` [PATCH 17/22] staging: erofs: remove clusterbits in sbi Gao Xiang
2019-07-31  9:12   ` Chao Yu
2019-07-29  6:51 ` [PATCH 18/22] staging: erofs: turn cache strategies into mount options Gao Xiang
2019-07-31  9:23   ` Chao Yu
2019-07-29  6:51 ` [PATCH 19/22] staging: erofs: tidy up utils.c Gao Xiang
2019-07-31  9:24   ` Chao Yu
2019-07-29  6:51 ` [PATCH 20/22] staging: erofs: tidy up internal.h Gao Xiang
2019-07-31  9:25   ` Chao Yu
2019-07-29  6:51 ` [PATCH 21/22] staging: erofs: update super.c Gao Xiang
2019-07-31  9:40   ` Chao Yu
2019-07-29  6:51 ` [PATCH 22/22] staging: erofs: update Kconfig Gao Xiang
2019-07-31  9:44   ` Chao Yu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56bdc87a-635f-e596-584e-fca0acb4a69e@huawei.com \
    --to=yuchao0@huawei.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gaoxiang25@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miaoxie@huawei.com \
    --cc=weidu.du@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git
	git clone --mirror https://lore.kernel.org/lkml/10 lkml/git/10.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git