[PATCH v2 06/34] nilfs2: don't set SB_RDONLY after filesystem errors
Christian Brauner
brauner at kernel.org
Tue Nov 10 13:56:45 PST 2026
On Wed, Nov 04, 2026 at 02:32:10AM +0900, Ryusuke Konishi wrote:
> Sashiko's point here has a valid aspect.
>
> This inconsistency can be resolved by inserting the following handling
> logic if sb_emergency_ro(s) is true:
>
> } else if (!ctx->cno) {
> if (nilfs_tree_is_busy(s->s_root)) {
> if (sb_emergency_ro(s)) {
> if (!(fc->sb_flags & SB_RDONLY)) {
> err = -EROFS;
> goto failed_super;
> } else {
> s->s_flags |= SB_RDONLY;
> }
Meh, I'd not set SB_RDONLY there. Because it changes the read-only state
outside of reconfigure_super() which is precisely what this series gets
rid of.
The superblock can be frozen at that point, e.g., when the error hit
while it was frozen, and then thaw_super() leaves s_writers locked again:
mount /dev/sda /mnt
fsfreeze -f /mnt
<error> -> sb_set_emergency_ro()
mount -o ro /dev/sda /mnt2 -> SB_RDONLY on the frozen superblock
fsfreeze -u /mnt -> s_writers stay locked
It also turns the superblock read-only underneath the existing
read-write mount without sb_prepare_remount_readonly().
The busy-tree branch does what get_tree_bdev() does for every other
block device filesystem. A second read-only mount fails with EBUSY and a
second read-write mount gets the superblock and every write fails with
EROFS. That's what ext4 does since commit d3476f3dad4a ("ext4: don't set
SB_RDONLY after filesystem errors").
If we want the second read-only mount to work I think we should do it
for get_tree_bdev() and nilfs2 alike and treat the emergency state as
read-only in the comparison without touching s_flags:
if ((bool)(fc->sb_flags & SB_RDONLY) !=
(sb_rdonly(s) || sb_emergency_ro(s))) {
But I'd do that on top.
More information about the linux-mtd
mailing list