[v5,1/2] ext4: commit super block if fs record error when journal record without error

Message ID 20230307061703.245965-2-yebin@huaweicloud.com
State New
Headers
Series fix error flag covered by journal recovery |

Commit Message

Ye Bin March 7, 2023, 6:17 a.m. UTC
  From: Ye Bin <yebin10@huawei.com>

Now, 'es->s_state' maybe covered by recover journal. And journal errno
maybe not recorded in journal sb as IO error. ext4_update_super() only
update error information when 'sbi->s_add_error_count' large than zero.
Then 'EXT4_ERROR_FS' flag maybe lost.
To solve above issue just recover 'es->s_state' error flag after journal
replay like error info.

Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 fs/ext4/super.c | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Comments

Jan Kara March 7, 2023, 9:02 a.m. UTC | #1
On Tue 07-03-23 14:17:02, Ye Bin wrote:
> From: Ye Bin <yebin10@huawei.com>
> 
> Now, 'es->s_state' maybe covered by recover journal. And journal errno
> maybe not recorded in journal sb as IO error. ext4_update_super() only
> update error information when 'sbi->s_add_error_count' large than zero.
> Then 'EXT4_ERROR_FS' flag maybe lost.
> To solve above issue just recover 'es->s_state' error flag after journal
> replay like error info.
> 
> Signed-off-by: Ye Bin <yebin10@huawei.com>

Looks good to me. Feel free to add:

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

								Honza

> ---
>  fs/ext4/super.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 88f7b8a88c76..dfa31eea1346 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -5920,6 +5920,7 @@ static int ext4_load_journal(struct super_block *sb,
>  		err = jbd2_journal_wipe(journal, !really_read_only);
>  	if (!err) {
>  		char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
> +
>  		if (save)
>  			memcpy(save, ((char *) es) +
>  			       EXT4_S_ERR_START, EXT4_S_ERR_LEN);
> @@ -5928,6 +5929,14 @@ static int ext4_load_journal(struct super_block *sb,
>  			memcpy(((char *) es) + EXT4_S_ERR_START,
>  			       save, EXT4_S_ERR_LEN);
>  		kfree(save);
> +		es->s_state |= cpu_to_le16(EXT4_SB(sb)->s_mount_state &
> +					   EXT4_ERROR_FS);
> +		/* Write out restored error information to the superblock */
> +		if (!bdev_read_only(sb->s_bdev)) {
> +			int err2;
> +			err2 = ext4_commit_super(sb);
> +			err = err ? : err2;
> +		}
>  	}
>  
>  	if (err) {
> -- 
> 2.31.1
>
  
Baokun Li March 8, 2023, 1:04 a.m. UTC | #2
On 2023/3/7 14:17, Ye Bin wrote:
> From: Ye Bin <yebin10@huawei.com>
>
> Now, 'es->s_state' maybe covered by recover journal. And journal errno
> maybe not recorded in journal sb as IO error. ext4_update_super() only
> update error information when 'sbi->s_add_error_count' large than zero.
> Then 'EXT4_ERROR_FS' flag maybe lost.
> To solve above issue just recover 'es->s_state' error flag after journal
> replay like error info.
>
> Signed-off-by: Ye Bin <yebin10@huawei.com>



Looks good to me.

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


> ---
>   fs/ext4/super.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
>
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 88f7b8a88c76..dfa31eea1346 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -5920,6 +5920,7 @@ static int ext4_load_journal(struct super_block *sb,
>   		err = jbd2_journal_wipe(journal, !really_read_only);
>   	if (!err) {
>   		char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
> +
>   		if (save)
>   			memcpy(save, ((char *) es) +
>   			       EXT4_S_ERR_START, EXT4_S_ERR_LEN);
> @@ -5928,6 +5929,14 @@ static int ext4_load_journal(struct super_block *sb,
>   			memcpy(((char *) es) + EXT4_S_ERR_START,
>   			       save, EXT4_S_ERR_LEN);
>   		kfree(save);
> +		es->s_state |= cpu_to_le16(EXT4_SB(sb)->s_mount_state &
> +					   EXT4_ERROR_FS);
> +		/* Write out restored error information to the superblock */
> +		if (!bdev_read_only(sb->s_bdev)) {
> +			int err2;
> +			err2 = ext4_commit_super(sb);
> +			err = err ? : err2;
> +		}
>   	}
>   
>   	if (err) {
  

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 88f7b8a88c76..dfa31eea1346 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5920,6 +5920,7 @@  static int ext4_load_journal(struct super_block *sb,
 		err = jbd2_journal_wipe(journal, !really_read_only);
 	if (!err) {
 		char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
+
 		if (save)
 			memcpy(save, ((char *) es) +
 			       EXT4_S_ERR_START, EXT4_S_ERR_LEN);
@@ -5928,6 +5929,14 @@  static int ext4_load_journal(struct super_block *sb,
 			memcpy(((char *) es) + EXT4_S_ERR_START,
 			       save, EXT4_S_ERR_LEN);
 		kfree(save);
+		es->s_state |= cpu_to_le16(EXT4_SB(sb)->s_mount_state &
+					   EXT4_ERROR_FS);
+		/* Write out restored error information to the superblock */
+		if (!bdev_read_only(sb->s_bdev)) {
+			int err2;
+			err2 = ext4_commit_super(sb);
+			err = err ? : err2;
+		}
 	}
 
 	if (err) {