summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/super.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-12-23 17:50:29 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-01-05 23:24:19 -0500
commit62719cf33c3ad62986130a19496cd864a0ed06c3 (patch)
treef82ecd9d2029d76f9a862302d6abd0a650aa482c /fs/bcachefs/super.c
parent5e329145148d7e9fe5a07ecfc08682ef7334a4d1 (diff)
downloadlinux-62719cf33c3ad62986130a19496cd864a0ed06c3.tar.gz
linux-62719cf33c3ad62986130a19496cd864a0ed06c3.tar.bz2
linux-62719cf33c3ad62986130a19496cd864a0ed06c3.zip
bcachefs: Fix nochanges/read_only interaction
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>
Diffstat (limited to 'fs/bcachefs/super.c')
-rw-r--r--fs/bcachefs/super.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c
index 592005b8e448..492dfd4b5fde 100644
--- a/fs/bcachefs/super.c
+++ b/fs/bcachefs/super.c
@@ -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;