bcachefs: Make sure opts.read_only gets propagated back to VFS
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 8 Jun 2025 00:18:16 +0000 (20:18 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 12 Jun 2025 03:21:30 +0000 (23:21 -0400)
If we think we're read-only but the VFS doesn't, fun will ensue.

And now that we know we have to be able to do this safely, just make
nochanges imply ro.

Reported-by: syzbot+a7d6ceaba099cc21dee4@syzkaller.appspotmail.com
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs.c
fs/bcachefs/recovery.c

index 85d13f800165cd3863283d6a401d361e17aeae4e..3063a8ddc2dfae1852c9bfdea999beeece1a6510 100644 (file)
@@ -2490,6 +2490,14 @@ static int bch2_fs_get_tree(struct fs_context *fc)
        if (ret)
                goto err_stop_fs;
 
+       /*
+        * We might be doing a RO mount because other options required it, or we
+        * have no alloc info and it's a small image with no room to regenerate
+        * it
+        */
+       if (c->opts.read_only)
+               fc->sb_flags |= SB_RDONLY;
+
        sb = sget(fc->fs_type, NULL, bch2_set_super, fc->sb_flags|SB_NOSEC, c);
        ret = PTR_ERR_OR_ZERO(sb);
        if (ret)
index 06d0ba0fbffb42c794512f5e645b4921d8f4cc98..520eb72c49712c77cab56f71e4f9e31834d4164d 100644 (file)
@@ -752,9 +752,11 @@ int bch2_fs_recovery(struct bch_fs *c)
                        ? min(c->opts.recovery_pass_last, BCH_RECOVERY_PASS_snapshots_read)
                        : BCH_RECOVERY_PASS_snapshots_read;
                c->opts.nochanges = true;
-               c->opts.read_only = true;
        }
 
+       if (c->opts.nochanges)
+               c->opts.read_only = true;
+
        mutex_lock(&c->sb_lock);
        struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
        bool write_sb = false;