[PATCH v2 5/7] ext4: correct behavior under errors=remount-ro mode

libaokun@huaweicloud.com posted 7 patches 11 months ago
[PATCH v2 5/7] ext4: correct behavior under errors=remount-ro mode
Posted by libaokun@huaweicloud.com 11 months ago
From: Baokun Li <libaokun1@huawei.com>

And after commit 95257987a638 ("ext4: drop EXT4_MF_FS_ABORTED flag") in
v6.6-rc1, the EXT4_FLAGS_SHUTDOWN bit is set in ext4_handle_error() under
errors=remount-ro mode. This causes the read to fail even when the error
is triggered in errors=remount-ro mode.

To correct the behavior under errors=remount-ro, EXT4_FLAGS_SHUTDOWN is
replaced by the newly introduced EXT4_FLAGS_EMERGENCY_RO. This new flag
only prevents writes, matching the previous behavior with SB_RDONLY.

Fixes: 95257987a638 ("ext4: drop EXT4_MF_FS_ABORTED flag")
Closes: https://lore.kernel.org/all/22d652f6-cb3c-43f5-b2fe-0a4bb6516a04@huawei.com/
Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
---
 fs/ext4/super.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index d8116c9c2bd0..098e62727aec 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -708,11 +708,8 @@ static void ext4_handle_error(struct super_block *sb, bool force_ro, int error,
 	if (test_opt(sb, WARN_ON_ERROR))
 		WARN_ON_ONCE(1);
 
-	if (!continue_fs && !sb_rdonly(sb)) {
-		set_bit(EXT4_FLAGS_SHUTDOWN, &EXT4_SB(sb)->s_ext4_flags);
-		if (journal)
-			jbd2_journal_abort(journal, -EIO);
-	}
+	if (!continue_fs && !ext4_emergency_ro(sb) && journal)
+		jbd2_journal_abort(journal, -EIO);
 
 	if (!bdev_read_only(sb->s_bdev)) {
 		save_error_info(sb, error, ino, block, func, line);
@@ -738,17 +735,17 @@ static void ext4_handle_error(struct super_block *sb, bool force_ro, int error,
 			sb->s_id);
 	}
 
-	if (sb_rdonly(sb) || continue_fs)
+	if (ext4_emergency_ro(sb) || continue_fs)
 		return;
 
 	ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
 	/*
-	 * EXT4_FLAGS_SHUTDOWN was set which stops all filesystem
-	 * modifications. We don't set SB_RDONLY because that requires
-	 * sb->s_umount semaphore and setting it without proper remount
-	 * procedure is confusing code such as freeze_super() leading to
-	 * deadlocks and other problems.
+	 * We don't set SB_RDONLY because that requires sb->s_umount
+	 * semaphore and setting it without proper remount procedure is
+	 * confusing code such as freeze_super() leading to deadlocks
+	 * and other problems.
 	 */
+	set_bit(EXT4_FLAGS_EMERGENCY_RO, &EXT4_SB(sb)->s_ext4_flags);
 }
 
 static void update_super_work(struct work_struct *work)
-- 
2.39.2
Re: [PATCH v2 5/7] ext4: correct behavior under errors=remount-ro mode
Posted by Jan Kara 10 months, 1 week ago
On Wed 22-01-25 19:41:28, libaokun@huaweicloud.com wrote:
> From: Baokun Li <libaokun1@huawei.com>
> 
> And after commit 95257987a638 ("ext4: drop EXT4_MF_FS_ABORTED flag") in
> v6.6-rc1, the EXT4_FLAGS_SHUTDOWN bit is set in ext4_handle_error() under
> errors=remount-ro mode. This causes the read to fail even when the error
> is triggered in errors=remount-ro mode.
> 
> To correct the behavior under errors=remount-ro, EXT4_FLAGS_SHUTDOWN is
> replaced by the newly introduced EXT4_FLAGS_EMERGENCY_RO. This new flag
> only prevents writes, matching the previous behavior with SB_RDONLY.
> 
> Fixes: 95257987a638 ("ext4: drop EXT4_MF_FS_ABORTED flag")
> Closes: https://lore.kernel.org/all/22d652f6-cb3c-43f5-b2fe-0a4bb6516a04@huawei.com/
> Suggested-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Baokun Li <libaokun1@huawei.com>
> Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

Looks good. Feel free to add:

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

								Honza

> ---
>  fs/ext4/super.c | 19 ++++++++-----------
>  1 file changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index d8116c9c2bd0..098e62727aec 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -708,11 +708,8 @@ static void ext4_handle_error(struct super_block *sb, bool force_ro, int error,
>  	if (test_opt(sb, WARN_ON_ERROR))
>  		WARN_ON_ONCE(1);
>  
> -	if (!continue_fs && !sb_rdonly(sb)) {
> -		set_bit(EXT4_FLAGS_SHUTDOWN, &EXT4_SB(sb)->s_ext4_flags);
> -		if (journal)
> -			jbd2_journal_abort(journal, -EIO);
> -	}
> +	if (!continue_fs && !ext4_emergency_ro(sb) && journal)
> +		jbd2_journal_abort(journal, -EIO);
>  
>  	if (!bdev_read_only(sb->s_bdev)) {
>  		save_error_info(sb, error, ino, block, func, line);
> @@ -738,17 +735,17 @@ static void ext4_handle_error(struct super_block *sb, bool force_ro, int error,
>  			sb->s_id);
>  	}
>  
> -	if (sb_rdonly(sb) || continue_fs)
> +	if (ext4_emergency_ro(sb) || continue_fs)
>  		return;
>  
>  	ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
>  	/*
> -	 * EXT4_FLAGS_SHUTDOWN was set which stops all filesystem
> -	 * modifications. We don't set SB_RDONLY because that requires
> -	 * sb->s_umount semaphore and setting it without proper remount
> -	 * procedure is confusing code such as freeze_super() leading to
> -	 * deadlocks and other problems.
> +	 * We don't set SB_RDONLY because that requires sb->s_umount
> +	 * semaphore and setting it without proper remount procedure is
> +	 * confusing code such as freeze_super() leading to deadlocks
> +	 * and other problems.
>  	 */
> +	set_bit(EXT4_FLAGS_EMERGENCY_RO, &EXT4_SB(sb)->s_ext4_flags);
>  }
>  
>  static void update_super_work(struct work_struct *work)
> -- 
> 2.39.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR