bcachefs: Fix failure to read btree roots
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 13 Feb 2023 00:24:34 +0000 (19:24 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:52 +0000 (17:09 -0400)
If failed to read a btree root - or if we're not using a btree root,
because of the reconstruct_alloc option - make sure we update the
corresponding info for the key/level for the root on disk.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/recovery.c

index 8a78377bf9c5991846c7e4202107cac7d1b00656..178f064244601ec302521213f8bac5d80b4a83a8 100644 (file)
@@ -974,9 +974,15 @@ static int read_btree_roots(struct bch_fs *c)
                }
        }
 
-       for (i = 0; i < BTREE_ID_NR; i++)
-               if (!c->btree_roots[i].b)
+       for (i = 0; i < BTREE_ID_NR; i++) {
+               struct btree_root *r = &c->btree_roots[i];
+
+               if (!r->b) {
+                       r->alive = false;
+                       r->level = 0;
                        bch2_btree_root_alloc(c, i);
+               }
+       }
 fsck_err:
        return ret;
 }