aboutsummaryrefslogtreecommitdiff
path: root/fs/bcachefs/super-io.c
diff options
context:
space:
mode:
authorGravatar Kent Overstreet <kent.overstreet@gmail.com> 2022-04-02 17:24:25 -0400
committerGravatar Kent Overstreet <kent.overstreet@linux.dev> 2023-10-22 17:09:30 -0400
commit80c80164a5f131307b9b870f7a366ed45b901b88 (patch)
tree40d87e5d0dd4d1be9271842f7632d824c753e7e0 /fs/bcachefs/super-io.c
parentbcachefs: Improve read_from_stale_dirty_pointer() message (diff)
downloadlinux-80c80164a5f131307b9b870f7a366ed45b901b88.tar.gz
linux-80c80164a5f131307b9b870f7a366ed45b901b88.tar.bz2
linux-80c80164a5f131307b9b870f7a366ed45b901b88.zip
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>
Diffstat (limited to 'fs/bcachefs/super-io.c')
-rw-r--r--fs/bcachefs/super-io.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c
index c7962266f495..4fb2bede39f6 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;