[PATCH] ext4: clear i_state_flags when alloc inode

Haibo Chen posted 1 patch 1 month, 2 weeks ago
fs/ext4/ialloc.c | 1 -
fs/ext4/inode.c  | 1 -
fs/ext4/super.c  | 1 +
3 files changed, 1 insertion(+), 2 deletions(-)
[PATCH] ext4: clear i_state_flags when alloc inode
Posted by Haibo Chen 1 month, 2 weeks ago
i_state_flags used on 32-bit archs, need to clear this flag when
alloc inode.
Find this issue when umount ext4, sometimes track the inode as orphan
accidently, cause ext4 mesg dump.

Fixes: acf943e9768e ("ext4: fix checks for orphan inodes")
Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
---
 fs/ext4/ialloc.c | 1 -
 fs/ext4/inode.c  | 1 -
 fs/ext4/super.c  | 1 +
 3 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index ba4fd9aba1c14de56b89ebbeb4597f7becf947ff..b20a1bf866abedf3a768ee8a147f108ea09ecb01 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -1293,7 +1293,6 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,
 		ei->i_csum_seed = ext4_chksum(csum, (__u8 *)&gen, sizeof(gen));
 	}
 
-	ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
 	ext4_set_inode_state(inode, EXT4_STATE_NEW);
 
 	ei->i_extra_isize = sbi->s_want_extra_isize;
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index a163c087137314c541ec10c011488c5392fb7011..bf6786d373ff57c32d5a84cfd73ea8a33cb68b16 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5285,7 +5285,6 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
 	ei->i_projid = make_kprojid(&init_user_ns, i_projid);
 	set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
 
-	ext4_clear_state_flags(ei);	/* Only relevant on 32-bit archs */
 	ei->i_inline_off = 0;
 	ei->i_dir_start_lookup = 0;
 	ei->i_dtime = le32_to_cpu(raw_inode->i_dtime);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 33e7c08c9529c357d291f40269863398753dc650..3dcc9410c09a55d5dce2dbff388a97bf4f133818 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1396,6 +1396,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
 
 	inode_set_iversion(&ei->vfs_inode, 1);
 	ei->i_flags = 0;
+	ext4_clear_state_flags(ei);	/* Only relevant on 32-bit archs */
 	spin_lock_init(&ei->i_raw_lock);
 	ei->i_prealloc_node = RB_ROOT;
 	atomic_set(&ei->i_prealloc_active, 0);

---
base-commit: 9823120909776bbca58a3c55ef1f27d49283c1f3
change-id: 20251104-ext4-3f9647dcedd0

Best regards,
-- 
Haibo Chen <haibo.chen@nxp.com>
Re: [PATCH] ext4: clear i_state_flags when alloc inode
Posted by Theodore Ts'o 1 month ago
On Tue, 04 Nov 2025 16:12:24 +0800, Haibo Chen wrote:
> i_state_flags used on 32-bit archs, need to clear this flag when
> alloc inode.
> Find this issue when umount ext4, sometimes track the inode as orphan
> accidently, cause ext4 mesg dump.
> 
> 

Applied, thanks!

[1/1] ext4: clear i_state_flags when alloc inode
      commit: 322a9e3c77253842617257af246cb5a0ac77851c

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>
Re: [PATCH] ext4: clear i_state_flags when alloc inode
Posted by Baokun Li 1 month, 1 week ago
On 2025-11-04 16:12, Haibo Chen wrote:
> i_state_flags used on 32-bit archs, need to clear this flag when
> alloc inode.
> Find this issue when umount ext4, sometimes track the inode as orphan
> accidently, cause ext4 mesg dump.
>
> Fixes: acf943e9768e ("ext4: fix checks for orphan inodes")
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>

Looks good. Feel free to add:

Reviewed-by: Baokun Li <libaokun1@huawei.com>

> ---
>  fs/ext4/ialloc.c | 1 -
>  fs/ext4/inode.c  | 1 -
>  fs/ext4/super.c  | 1 +
>  3 files changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
> index ba4fd9aba1c14de56b89ebbeb4597f7becf947ff..b20a1bf866abedf3a768ee8a147f108ea09ecb01 100644
> --- a/fs/ext4/ialloc.c
> +++ b/fs/ext4/ialloc.c
> @@ -1293,7 +1293,6 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,
>  		ei->i_csum_seed = ext4_chksum(csum, (__u8 *)&gen, sizeof(gen));
>  	}
>  
> -	ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
>  	ext4_set_inode_state(inode, EXT4_STATE_NEW);
>  
>  	ei->i_extra_isize = sbi->s_want_extra_isize;
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index a163c087137314c541ec10c011488c5392fb7011..bf6786d373ff57c32d5a84cfd73ea8a33cb68b16 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5285,7 +5285,6 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
>  	ei->i_projid = make_kprojid(&init_user_ns, i_projid);
>  	set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
>  
> -	ext4_clear_state_flags(ei);	/* Only relevant on 32-bit archs */
>  	ei->i_inline_off = 0;
>  	ei->i_dir_start_lookup = 0;
>  	ei->i_dtime = le32_to_cpu(raw_inode->i_dtime);
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 33e7c08c9529c357d291f40269863398753dc650..3dcc9410c09a55d5dce2dbff388a97bf4f133818 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1396,6 +1396,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
>  
>  	inode_set_iversion(&ei->vfs_inode, 1);
>  	ei->i_flags = 0;
> +	ext4_clear_state_flags(ei);	/* Only relevant on 32-bit archs */
>  	spin_lock_init(&ei->i_raw_lock);
>  	ei->i_prealloc_node = RB_ROOT;
>  	atomic_set(&ei->i_prealloc_active, 0);
>
> ---
> base-commit: 9823120909776bbca58a3c55ef1f27d49283c1f3
> change-id: 20251104-ext4-3f9647dcedd0
>
> Best regards,
Re: [PATCH] ext4: clear i_state_flags when alloc inode
Posted by Zhang Yi 1 month, 2 weeks ago
On 11/4/2025 4:12 PM, Haibo Chen wrote:
> i_state_flags used on 32-bit archs, need to clear this flag when
> alloc inode.
> Find this issue when umount ext4, sometimes track the inode as orphan
> accidently, cause ext4 mesg dump.
> 
> Fixes: acf943e9768e ("ext4: fix checks for orphan inodes")
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>

Looks good to me.

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

> ---
>  fs/ext4/ialloc.c | 1 -
>  fs/ext4/inode.c  | 1 -
>  fs/ext4/super.c  | 1 +
>  3 files changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
> index ba4fd9aba1c14de56b89ebbeb4597f7becf947ff..b20a1bf866abedf3a768ee8a147f108ea09ecb01 100644
> --- a/fs/ext4/ialloc.c
> +++ b/fs/ext4/ialloc.c
> @@ -1293,7 +1293,6 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,
>  		ei->i_csum_seed = ext4_chksum(csum, (__u8 *)&gen, sizeof(gen));
>  	}
>  
> -	ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
>  	ext4_set_inode_state(inode, EXT4_STATE_NEW);
>  
>  	ei->i_extra_isize = sbi->s_want_extra_isize;
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index a163c087137314c541ec10c011488c5392fb7011..bf6786d373ff57c32d5a84cfd73ea8a33cb68b16 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5285,7 +5285,6 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
>  	ei->i_projid = make_kprojid(&init_user_ns, i_projid);
>  	set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
>  
> -	ext4_clear_state_flags(ei);	/* Only relevant on 32-bit archs */
>  	ei->i_inline_off = 0;
>  	ei->i_dir_start_lookup = 0;
>  	ei->i_dtime = le32_to_cpu(raw_inode->i_dtime);
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 33e7c08c9529c357d291f40269863398753dc650..3dcc9410c09a55d5dce2dbff388a97bf4f133818 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1396,6 +1396,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
>  
>  	inode_set_iversion(&ei->vfs_inode, 1);
>  	ei->i_flags = 0;
> +	ext4_clear_state_flags(ei);	/* Only relevant on 32-bit archs */
>  	spin_lock_init(&ei->i_raw_lock);
>  	ei->i_prealloc_node = RB_ROOT;
>  	atomic_set(&ei->i_prealloc_active, 0);
> 
> ---
> base-commit: 9823120909776bbca58a3c55ef1f27d49283c1f3
> change-id: 20251104-ext4-3f9647dcedd0
> 
> Best regards,
Re: [PATCH] ext4: clear i_state_flags when alloc inode
Posted by Jan Kara 1 month, 2 weeks ago
On Tue 04-11-25 16:12:24, Haibo Chen wrote:
> i_state_flags used on 32-bit archs, need to clear this flag when
> alloc inode.
> Find this issue when umount ext4, sometimes track the inode as orphan
> accidently, cause ext4 mesg dump.
> 
> Fixes: acf943e9768e ("ext4: fix checks for orphan inodes")
> Signed-off-by: Haibo Chen <haibo.chen@nxp.com>

Looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/ialloc.c | 1 -
>  fs/ext4/inode.c  | 1 -
>  fs/ext4/super.c  | 1 +
>  3 files changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
> index ba4fd9aba1c14de56b89ebbeb4597f7becf947ff..b20a1bf866abedf3a768ee8a147f108ea09ecb01 100644
> --- a/fs/ext4/ialloc.c
> +++ b/fs/ext4/ialloc.c
> @@ -1293,7 +1293,6 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,
>  		ei->i_csum_seed = ext4_chksum(csum, (__u8 *)&gen, sizeof(gen));
>  	}
>  
> -	ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
>  	ext4_set_inode_state(inode, EXT4_STATE_NEW);
>  
>  	ei->i_extra_isize = sbi->s_want_extra_isize;
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index a163c087137314c541ec10c011488c5392fb7011..bf6786d373ff57c32d5a84cfd73ea8a33cb68b16 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5285,7 +5285,6 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
>  	ei->i_projid = make_kprojid(&init_user_ns, i_projid);
>  	set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
>  
> -	ext4_clear_state_flags(ei);	/* Only relevant on 32-bit archs */
>  	ei->i_inline_off = 0;
>  	ei->i_dir_start_lookup = 0;
>  	ei->i_dtime = le32_to_cpu(raw_inode->i_dtime);
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 33e7c08c9529c357d291f40269863398753dc650..3dcc9410c09a55d5dce2dbff388a97bf4f133818 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1396,6 +1396,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
>  
>  	inode_set_iversion(&ei->vfs_inode, 1);
>  	ei->i_flags = 0;
> +	ext4_clear_state_flags(ei);	/* Only relevant on 32-bit archs */
>  	spin_lock_init(&ei->i_raw_lock);
>  	ei->i_prealloc_node = RB_ROOT;
>  	atomic_set(&ei->i_prealloc_active, 0);
> 
> ---
> base-commit: 9823120909776bbca58a3c55ef1f27d49283c1f3
> change-id: 20251104-ext4-3f9647dcedd0
> 
> Best regards,
> -- 
> Haibo Chen <haibo.chen@nxp.com>
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR