Commit 3ab25c1b authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: We can handle missing btree roots for all alloc btrees

We can rebuild alloc info if these btree roots are missing - no need to
bail out and say the filesystem is unrecoverable
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent b962552e
...@@ -924,6 +924,18 @@ static struct bch_sb_field_clean *read_superblock_clean(struct bch_fs *c) ...@@ -924,6 +924,18 @@ static struct bch_sb_field_clean *read_superblock_clean(struct bch_fs *c)
return ERR_PTR(ret); return ERR_PTR(ret);
} }
static bool btree_id_is_alloc(enum btree_id id)
{
switch (id) {
case BTREE_ID_alloc:
case BTREE_ID_need_discard:
case BTREE_ID_freespace:
return true;
default:
return false;
}
}
static int read_btree_roots(struct bch_fs *c) static int read_btree_roots(struct bch_fs *c)
{ {
unsigned i; unsigned i;
...@@ -935,14 +947,14 @@ static int read_btree_roots(struct bch_fs *c) ...@@ -935,14 +947,14 @@ static int read_btree_roots(struct bch_fs *c)
if (!r->alive) if (!r->alive)
continue; continue;
if (i == BTREE_ID_alloc && if (btree_id_is_alloc(i) &&
c->opts.reconstruct_alloc) { c->opts.reconstruct_alloc) {
c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info); c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
continue; continue;
} }
if (r->error) { if (r->error) {
__fsck_err(c, i == BTREE_ID_alloc __fsck_err(c, btree_id_is_alloc(i)
? FSCK_CAN_IGNORE : 0, ? FSCK_CAN_IGNORE : 0,
"invalid btree root %s", "invalid btree root %s",
bch2_btree_ids[i]); bch2_btree_ids[i]);
...@@ -952,11 +964,12 @@ static int read_btree_roots(struct bch_fs *c) ...@@ -952,11 +964,12 @@ static int read_btree_roots(struct bch_fs *c)
ret = bch2_btree_root_read(c, i, &r->key, r->level); ret = bch2_btree_root_read(c, i, &r->key, r->level);
if (ret) { if (ret) {
__fsck_err(c, i == BTREE_ID_alloc __fsck_err(c,
btree_id_is_alloc(i)
? FSCK_CAN_IGNORE : 0, ? FSCK_CAN_IGNORE : 0,
"error reading btree root %s", "error reading btree root %s",
bch2_btree_ids[i]); bch2_btree_ids[i]);
if (i == BTREE_ID_alloc) if (btree_id_is_alloc(i))
c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info); c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
} }
} }
...@@ -1192,6 +1205,9 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1192,6 +1205,9 @@ int bch2_fs_recovery(struct bch_fs *c)
if (ret) if (ret)
goto err; goto err;
if (c->opts.reconstruct_alloc)
bch2_journal_log_msg(&c->journal, "dropping alloc info");
/* /*
* Skip past versions that might have possibly been used (as nonces), * Skip past versions that might have possibly been used (as nonces),
* but hadn't had their pointers written: * but hadn't had their pointers written:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment