]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Don't write partially-initialized superblocks
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 2 Apr 2022 21:24:25 +0000 (17:24 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:30 +0000 (17:09 -0400)
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>
fs/bcachefs/super-io.c

index c7962266f495e3ec822982b561adb126f802d3ba..4fb2bede39f65b10ab1d838e04af11452e38ed6c 100644 (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;