]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: Fix nochanges/read_only interaction
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 23 Dec 2023 22:50:29 +0000 (17:50 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 6 Jan 2024 04:24:19 +0000 (23:24 -0500)
nochanges means "we cannot issue writes at all"; it's possible to go
into a pseudo read-write mode where we pin dirty metadata in memory,
which is used for fsck in dry run mode and doing journal replay on a
read only mount, but we do not want to allow an actual read-write mount
in nochanges mode.

But we do always want to allow early read-write, during recovery - this
patch clarifies that.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs.c
fs/bcachefs/opts.h
fs/bcachefs/recovery.c
fs/bcachefs/super.c

index 12de97bc93b990428e20cd6b004fee0d0ff4592e..da11757682c0967950e9e9ea7d1e4d862937d0ce 100644 (file)
@@ -1630,12 +1630,12 @@ static int bch2_remount(struct super_block *sb, int *flags, char *data)
        struct bch_opts opts = bch2_opts_empty();
        int ret;
 
-       opt_set(opts, read_only, (*flags & SB_RDONLY) != 0);
-
        ret = bch2_parse_mount_opts(c, &opts, data);
        if (ret)
                goto err;
 
+       opt_set(opts, read_only, (*flags & SB_RDONLY) != 0);
+
        if (opts.read_only != c->opts.read_only) {
                down_write(&c->state_lock);
 
index cf69b92cbd03ebd5639e7f31872ba8d0d8044ffd..42cad83efb48337a2d4462ca6fd24d7946671b6c 100644 (file)
@@ -389,7 +389,7 @@ enum fsck_err_opts {
          BCH2_NO_SB_OPT,               BCH_SB_SECTOR,                  \
          "offset",     "Sector offset of superblock")                  \
        x(read_only,                    u8,                             \
-         OPT_FS,                                                       \
+         OPT_FS|OPT_MOUNT,                                             \
          OPT_BOOL(),                                                   \
          BCH2_NO_SB_OPT,               false,                          \
          NULL,         NULL)                                           \
index a792f42ab5ff0ea6d8627a1dcbc3a4af4fbbbaff..d2914e91146174124d17a8cd61f2d54b5a3041e1 100644 (file)
@@ -1076,7 +1076,9 @@ out:
                bch2_journal_keys_put_initial(c);
        kfree(clean);
 
-       if (!ret && test_bit(BCH_FS_need_delete_dead_snapshots, &c->flags)) {
+       if (!ret &&
+           test_bit(BCH_FS_need_delete_dead_snapshots, &c->flags) &&
+           !c->opts.nochanges) {
                bch2_fs_read_write_early(c);
                bch2_delete_dead_snapshots_async(c);
        }
index 592005b8e448adee8ed22ebdde93eb2d5a6ee792..492dfd4b5fde01d87ec2130d7b0df2e4f3e13667 100644 (file)
@@ -433,16 +433,6 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
        if (test_bit(BCH_FS_rw, &c->flags))
                return 0;
 
-       if (c->opts.norecovery)
-               return -BCH_ERR_erofs_norecovery;
-
-       /*
-        * nochanges is used for fsck -n mode - we have to allow going rw
-        * during recovery for that to work:
-        */
-       if (c->opts.nochanges && (!early || c->opts.read_only))
-               return -BCH_ERR_erofs_nochanges;
-
        bch_info(c, "going read-write");
 
        ret = bch2_sb_members_v2_init(c);
@@ -510,6 +500,12 @@ err:
 
 int bch2_fs_read_write(struct bch_fs *c)
 {
+       if (c->opts.norecovery)
+               return -BCH_ERR_erofs_norecovery;
+
+       if (c->opts.nochanges)
+               return -BCH_ERR_erofs_nochanges;
+
        return __bch2_fs_read_write(c, false);
 }
 
@@ -1033,7 +1029,7 @@ int bch2_fs_start(struct bch_fs *c)
 
        set_bit(BCH_FS_started, &c->flags);
 
-       if (c->opts.read_only || c->opts.nochanges) {
+       if (c->opts.read_only) {
                bch2_fs_read_only(c);
        } else {
                ret = !test_bit(BCH_FS_rw, &c->flags)
@@ -1946,6 +1942,11 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
                BUG_ON(darray_push(&sbs, sb));
        }
 
+       if (opts.nochanges && !opts.read_only) {
+               ret = -BCH_ERR_erofs_nochanges;
+               goto err_print;
+       }
+
        darray_for_each(sbs, sb)
                if (!best || le64_to_cpu(sb->sb->seq) > le64_to_cpu(best->sb->seq))
                        best = sb;