Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: chao@kernel.org (Chao Yu)
Subject: [PATCH] erofs: fix erofs_module_init & exit
Date: Fri, 6 Jul 2018 00:19:19 +0800	[thread overview]
Message-ID: <b66fb258-e9af-1ad9-7613-92ad07ca75b3@kernel.org> (raw)
In-Reply-To: <1530767030-86277-1-git-send-email-gaoxiang25@huawei.com>

Hi Xiang,

On 2018/7/5 13:03, Gao Xiang wrote:
> This patch adds missing parts and EROFS ondisk
> layout check as well.
> 
> Signed-off-by: Gao Xiang <gaoxiang25 at huawei.com>
> ---
>  fs/erofs/erofs_fs.h | 13 +++++++++++++
>  fs/erofs/super.c    | 28 +++++++++++++++++++++-------
>  2 files changed, 34 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h
> index ed943d4..0dbf08d 100644
> --- a/fs/erofs/erofs_fs.h
> +++ b/fs/erofs/erofs_fs.h
> @@ -253,5 +253,18 @@ enum {
>  
>  #define EROFS_NAME_LEN      255
>  
> +/* check the EROFS on-disk layout strictly at compile time */
> +static inline void erofs_check_ondisk_layout(void)
> +{
> +	BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
> +	BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
> +	BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
> +	BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
> +	BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
> +	BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
> +	BUILD_BUG_ON(sizeof(struct erofs_decompressed_index_vle) != 8);
> +	BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);

We'd better define some macros include above constants.

Other parts look good to me.

Thanks,

> +}
> +
>  #endif
>  
> diff --git a/fs/erofs/super.c b/fs/erofs/super.c
> index a1826b9..d104d88 100644
> --- a/fs/erofs/super.c
> +++ b/fs/erofs/super.c
> @@ -37,6 +37,12 @@ static int erofs_init_inode_cache(void)
>  	return erofs_inode_cachep != NULL ? 0 : -ENOMEM;
>  }
>  
> +static void erofs_exit_inode_cache(void)
> +{
> +	BUG_ON(erofs_inode_cachep == NULL);
> +	kmem_cache_destroy(erofs_inode_cachep);
> +}
> +
>  static struct inode *alloc_inode(struct super_block *sb)
>  {
>  	struct erofs_vnode *vi =
> @@ -398,22 +404,30 @@ int __init erofs_module_init(void)
>  {
>  	int err;
>  
> +	erofs_check_ondisk_layout();
>  	infoln("Initializing erofs " EROFS_VERSION);
>  
>  	err = erofs_init_inode_cache();
> -	if (!err) {
> -		err = register_filesystem(&erofs_fs_type);
> -		if (!err) {
> -			infoln("Successfully to initialize erofs");
> -			return 0;
> -		}
> -	}
> +	if (err)
> +		goto icache_err;
> +
> +	err = register_filesystem(&erofs_fs_type);
> +	if (err)
> +		goto fs_err;
> +
> +	infoln("Successfully to initialize erofs");
> +	return 0;
> +
> +fs_err:
> +	erofs_exit_inode_cache();
> +icache_err:
>  	return err;
>  }
>  
>  void __exit erofs_module_exit(void)
>  {
>  	unregister_filesystem(&erofs_fs_type);
> +	erofs_exit_inode_cache();
>  	infoln("Successfully finalize erofs");
>  }
>  
> 

  reply	other threads:[~2018-07-05 16:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-05  5:03 [PATCH] erofs: fix erofs_module_init & exit Gao Xiang
2018-07-05 16:19 ` Chao Yu [this message]
2018-07-05 16:39   ` Gao Xiang
2018-07-06  1:30     ` Chao Yu
2018-07-06  2:09       ` Gao Xiang
2018-07-06 11:34         ` Gao Xiang
2018-07-06 11:56           ` Chao Yu
2018-07-06 11:30 ` [PATCH v2] " Gao Xiang

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=b66fb258-e9af-1ad9-7613-92ad07ca75b3@kernel.org \
    --to=chao@kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox