[PATCH v2 06/34] nilfs2: don't set SB_RDONLY after filesystem errors

Ryusuke Konishi konishi.ryusuke at gmail.com
Wed Nov 11 05:56:21 PST 2026


On Wed, Nov 11, 2026 at 6:56 AM Christian Brauner wrote:
>
> 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.

Thanks for the detailed explanation and the concrete scenario with
fsfreeze; that
makes complete sense.

While the "s->s_flags |= SB_RDONLY" assignment in my example could simply be
dropped, your approach of treating it directly in the comparison looks better
as it is more conservative and natural.

I also agree with aligning this secondary mount behavior across get_tree_bdev()
and nilfs2 alike in a separate follow-up series on top.

So, I am completely fine with keeping the current v2 patch as-is for this part.

Thanks,
Ryusuke Konishi



More information about the linux-mtd mailing list