Commit 62719cf3 authored by Kent Overstreet's avatar Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 5e329145
...@@ -1630,12 +1630,12 @@ static int bch2_remount(struct super_block *sb, int *flags, char *data) ...@@ -1630,12 +1630,12 @@ static int bch2_remount(struct super_block *sb, int *flags, char *data)
struct bch_opts opts = bch2_opts_empty(); struct bch_opts opts = bch2_opts_empty();
int ret; int ret;
opt_set(opts, read_only, (*flags & SB_RDONLY) != 0);
ret = bch2_parse_mount_opts(c, &opts, data); ret = bch2_parse_mount_opts(c, &opts, data);
if (ret) if (ret)
goto err; goto err;
opt_set(opts, read_only, (*flags & SB_RDONLY) != 0);
if (opts.read_only != c->opts.read_only) { if (opts.read_only != c->opts.read_only) {
down_write(&c->state_lock); down_write(&c->state_lock);
......
...@@ -389,7 +389,7 @@ enum fsck_err_opts { ...@@ -389,7 +389,7 @@ enum fsck_err_opts {
BCH2_NO_SB_OPT, BCH_SB_SECTOR, \ BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
"offset", "Sector offset of superblock") \ "offset", "Sector offset of superblock") \
x(read_only, u8, \ x(read_only, u8, \
OPT_FS, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
BCH2_NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, NULL) \ NULL, NULL) \
......
...@@ -1076,7 +1076,9 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1076,7 +1076,9 @@ int bch2_fs_recovery(struct bch_fs *c)
bch2_journal_keys_put_initial(c); bch2_journal_keys_put_initial(c);
kfree(clean); 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_fs_read_write_early(c);
bch2_delete_dead_snapshots_async(c); bch2_delete_dead_snapshots_async(c);
} }
......
...@@ -433,16 +433,6 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early) ...@@ -433,16 +433,6 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
if (test_bit(BCH_FS_rw, &c->flags)) if (test_bit(BCH_FS_rw, &c->flags))
return 0; 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"); bch_info(c, "going read-write");
ret = bch2_sb_members_v2_init(c); ret = bch2_sb_members_v2_init(c);
...@@ -510,6 +500,12 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early) ...@@ -510,6 +500,12 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
int bch2_fs_read_write(struct bch_fs *c) 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); return __bch2_fs_read_write(c, false);
} }
...@@ -1033,7 +1029,7 @@ int bch2_fs_start(struct bch_fs *c) ...@@ -1033,7 +1029,7 @@ int bch2_fs_start(struct bch_fs *c)
set_bit(BCH_FS_started, &c->flags); 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); bch2_fs_read_only(c);
} else { } else {
ret = !test_bit(BCH_FS_rw, &c->flags) ret = !test_bit(BCH_FS_rw, &c->flags)
...@@ -1946,6 +1942,11 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices, ...@@ -1946,6 +1942,11 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
BUG_ON(darray_push(&sbs, sb)); 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) darray_for_each(sbs, sb)
if (!best || le64_to_cpu(sb->sb->seq) > le64_to_cpu(best->sb->seq)) if (!best || le64_to_cpu(sb->sb->seq) > le64_to_cpu(best->sb->seq))
best = sb; best = sb;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment