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

From: libaokun
Date: Wed Jan 22 2025 - 06:48:59 EST


From: Baokun Li <libaokun1@xxxxxxxxxx>

Changes since v1:
* Patch 1,2: Add comma after the last enum member.
* Patch 3: Rename ext4_is_emergency() to ext4_emergency_state().
* Patch 4: Instead of adding an ext4_sb_rdonly() helper, add additional
ext4_emergency_state() checks.
* Patch 5: Replace sb_rdonly() with ext4_emergency_ro() in
ext4_handle_error() and keep the SB_RDONLY comments.
* Collect RVB from Jan Kara and Zhang Yi.(Thanks for your review!)
* Rebased on link[2] to avoid context conflicts with Patch 3.
(ext4_forced_shutdown() -> ext4_emergency_state() in ext4_end_io_end()).

[v1]: https://lore.kernel.org/r/20250117082315.2869996-1-libaokun@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/r/20250122110533.4116662-1-libaokun@xxxxxxxxxxxxxxx [2]

After commit d3476f3dad4a ("ext4: don't set SB_RDONLY after filesystem
errors") in v6.12-rc1, the 'errors=remount-ro' mode no longer sets
SB_RDONLY on errors, which results in us seeing the filesystem is still
in rw state after errors.

What's worse is that after commit
95257987a638 ("ext4: drop EXT4_MF_FS_ABORTED flag")
was merged in v6.6-rc1, the EXT4_FLAGS_SHUTDOWN bit is set in
ext4_handle_error(). This causes the file system to not be read-only
when an error is triggered in "errors=remount-ro" mode, because
EXT4_FLAGS_SHUTDOWN prevents both writing and reading.

This patch set fixes the above behavior change. See the link[1] for the
previous discussion:

Link: https://lore.kernel.org/r/22d652f6-cb3c-43f5-b2fe-0a4bb6516a04@xxxxxxxxxx [1]

Comments and questions are, as always, welcome.

Thanks,
Baokun

Baokun Li (7):
ext4: convert EXT4_FLAGS_* defines to enum
ext4: add EXT4_FLAGS_EMERGENCY_RO bit
ext4: add ext4_emergency_state() helper function
ext4: add more ext4_emergency_state() checks around sb_rdonly()
ext4: correct behavior under errors=remount-ro mode
ext4: show 'emergency_ro' when EXT4_FLAGS_EMERGENCY_RO is set
ext4: show 'shutdown' hint when ext4 is forced to shutdown

fs/ext4/ext4.h | 23 +++++++++++++--
fs/ext4/ext4_jbd2.c | 6 ++--
fs/ext4/file.c | 27 +++++++++++------
fs/ext4/fsync.c | 12 +++-----
fs/ext4/ialloc.c | 5 ++--
fs/ext4/inline.c | 2 +-
fs/ext4/inode.c | 47 +++++++++++++++++-------------
fs/ext4/ioctl.c | 2 +-
fs/ext4/mballoc.c | 4 +--
fs/ext4/mmp.c | 2 +-
fs/ext4/namei.c | 20 +++++++------
fs/ext4/page-io.c | 2 +-
fs/ext4/super.c | 70 +++++++++++++++++++++++++--------------------
13 files changed, 134 insertions(+), 88 deletions(-)

--
2.39.2