[2/7] erofs: initialize packed inode after root inode is assigned

Message ID 20230407141710.113882-3-jefflexu@linux.alibaba.com
State New
Headers
Series erofs: introduce long xattr name prefixes feature |

Commit Message

Jingbo Xu April 7, 2023, 2:17 p.m. UTC
  As commit 8f7acdae2cd4 ("staging: erofs: kill all failure handling in
fill_super()"), move the initialization of packed inode after root
inode is assigned, so that the iput() in .put_super() is adequate as
the failure handling.

Otherwise, iput() is also needed in .kill_sb(), in case of the mounting
fails halfway.

Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
 fs/erofs/internal.h |  1 +
 fs/erofs/super.c    | 22 +++++++++++-----------
 2 files changed, 12 insertions(+), 11 deletions(-)
  

Comments

Gao Xiang April 9, 2023, 10:52 a.m. UTC | #1
On 2023/4/7 22:17, Jingbo Xu wrote:
> As commit 8f7acdae2cd4 ("staging: erofs: kill all failure handling in
> fill_super()"), move the initialization of packed inode after root
> inode is assigned, so that the iput() in .put_super() is adequate as
> the failure handling.
> 
> Otherwise, iput() is also needed in .kill_sb(), in case of the mounting
> fails halfway.
> 

Fixes: b15b2e307c3a ("erofs: support on-disk compressed fragments data")

> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>

Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Thanks,
Gao Xiang
  
Yue Hu April 10, 2023, 2:44 a.m. UTC | #2
On Fri,  7 Apr 2023 22:17:05 +0800
Jingbo Xu <jefflexu@linux.alibaba.com> wrote:

> As commit 8f7acdae2cd4 ("staging: erofs: kill all failure handling in
> fill_super()"), move the initialization of packed inode after root
> inode is assigned, so that the iput() in .put_super() is adequate as
> the failure handling.
> 
> Otherwise, iput() is also needed in .kill_sb(), in case of the mounting
> fails halfway.
> 
> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>

Reviewed-by: Yue Hu <huyue2@coolpad.com>

> ---
>  fs/erofs/internal.h |  1 +
>  fs/erofs/super.c    | 22 +++++++++++-----------
>  2 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
> index 2bcff3194e4a..caea9dc1cd82 100644
> --- a/fs/erofs/internal.h
> +++ b/fs/erofs/internal.h
> @@ -157,6 +157,7 @@ struct erofs_sb_info {
>  
>  	/* what we really care is nid, rather than ino.. */
>  	erofs_nid_t root_nid;
> +	erofs_nid_t packed_nid;
>  	/* used for statfs, f_files - f_favail */
>  	u64 inos;
>  
> diff --git a/fs/erofs/super.c b/fs/erofs/super.c
> index 58ffbf410bfb..325602820dc8 100644
> --- a/fs/erofs/super.c
> +++ b/fs/erofs/super.c
> @@ -388,17 +388,7 @@ static int erofs_read_superblock(struct super_block *sb)
>  #endif
>  	sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
>  	sbi->root_nid = le16_to_cpu(dsb->root_nid);
> -#ifdef CONFIG_EROFS_FS_ZIP
> -	sbi->packed_inode = NULL;
> -	if (erofs_sb_has_fragments(sbi) && dsb->packed_nid) {
> -		sbi->packed_inode =
> -			erofs_iget(sb, le64_to_cpu(dsb->packed_nid));
> -		if (IS_ERR(sbi->packed_inode)) {
> -			ret = PTR_ERR(sbi->packed_inode);
> -			goto out;
> -		}
> -	}
> -#endif
> +	sbi->packed_nid = le64_to_cpu(dsb->packed_nid);
>  	sbi->inos = le64_to_cpu(dsb->inos);
>  
>  	sbi->build_time = le64_to_cpu(dsb->build_time);
> @@ -820,6 +810,16 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
>  
>  	erofs_shrinker_register(sb);
>  	/* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */
> +#ifdef CONFIG_EROFS_FS_ZIP
> +	if (erofs_sb_has_fragments(sbi) && sbi->packed_nid) {
> +		sbi->packed_inode = erofs_iget(sb, sbi->packed_nid);
> +		if (IS_ERR(sbi->packed_inode)) {
> +			err = PTR_ERR(sbi->packed_inode);
> +			sbi->packed_inode = NULL;
> +			return err;
> +		}
> +	}
> +#endif
>  	err = erofs_init_managed_cache(sb);
>  	if (err)
>  		return err;
  

Patch

diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 2bcff3194e4a..caea9dc1cd82 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -157,6 +157,7 @@  struct erofs_sb_info {
 
 	/* what we really care is nid, rather than ino.. */
 	erofs_nid_t root_nid;
+	erofs_nid_t packed_nid;
 	/* used for statfs, f_files - f_favail */
 	u64 inos;
 
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 58ffbf410bfb..325602820dc8 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -388,17 +388,7 @@  static int erofs_read_superblock(struct super_block *sb)
 #endif
 	sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
 	sbi->root_nid = le16_to_cpu(dsb->root_nid);
-#ifdef CONFIG_EROFS_FS_ZIP
-	sbi->packed_inode = NULL;
-	if (erofs_sb_has_fragments(sbi) && dsb->packed_nid) {
-		sbi->packed_inode =
-			erofs_iget(sb, le64_to_cpu(dsb->packed_nid));
-		if (IS_ERR(sbi->packed_inode)) {
-			ret = PTR_ERR(sbi->packed_inode);
-			goto out;
-		}
-	}
-#endif
+	sbi->packed_nid = le64_to_cpu(dsb->packed_nid);
 	sbi->inos = le64_to_cpu(dsb->inos);
 
 	sbi->build_time = le64_to_cpu(dsb->build_time);
@@ -820,6 +810,16 @@  static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
 
 	erofs_shrinker_register(sb);
 	/* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */
+#ifdef CONFIG_EROFS_FS_ZIP
+	if (erofs_sb_has_fragments(sbi) && sbi->packed_nid) {
+		sbi->packed_inode = erofs_iget(sb, sbi->packed_nid);
+		if (IS_ERR(sbi->packed_inode)) {
+			err = PTR_ERR(sbi->packed_inode);
+			sbi->packed_inode = NULL;
+			return err;
+		}
+	}
+#endif
 	err = erofs_init_managed_cache(sb);
 	if (err)
 		return err;