From 80c80164a5f131307b9b870f7a366ed45b901b88 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sat, 2 Apr 2022 17:24:25 -0400 Subject: [PATCH] bcachefs: Don't write partially-initialized superblocks This neatly avoids bugs where we fail partway through initializing a new filesystem, if we just don't write out partly-initialized state. Signed-off-by: Kent Overstreet --- fs/bcachefs/super-io.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index c7962266f495e..4fb2bede39f65 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -833,6 +833,13 @@ int bch2_write_super(struct bch_fs *c) if (c->opts.nochanges) goto out; + /* + * Defer writing the superblock until filesystem initialization is + * complete - don't write out a partly initialized superblock: + */ + if (!BCH_SB_INITIALIZED(c->disk_sb.sb)) + goto out; + for_each_online_member(ca, c, i) { __set_bit(ca->dev_idx, sb_written.d); ca->sb_write_error = 0; -- 2.39.5