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 <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2022-04-02 17:24:25 -04:00 committed by Kent Overstreet
parent 64afbbc909
commit 80c80164a5

View File

@ -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;