Skip to content

Commit 5ab4beb

Browse files
author
Kent Overstreet
committed
bcachefs: Don't scan for btree nodes when we can reconstruct
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 359571c commit 5ab4beb

4 files changed

Lines changed: 29 additions & 18 deletions

File tree

fs/bcachefs/bcachefs_format.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,20 @@ enum btree_id {
15351535
BTREE_ID_NR
15361536
};
15371537

1538+
static inline bool btree_id_is_alloc(enum btree_id id)
1539+
{
1540+
switch (id) {
1541+
case BTREE_ID_alloc:
1542+
case BTREE_ID_backpointers:
1543+
case BTREE_ID_need_discard:
1544+
case BTREE_ID_freespace:
1545+
case BTREE_ID_bucket_gens:
1546+
return true;
1547+
default:
1548+
return false;
1549+
}
1550+
}
1551+
15381552
#define BTREE_MAX_DEPTH 4U
15391553

15401554
/* Btree nodes */

fs/bcachefs/btree_gc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,16 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
368368
buf.buf)) {
369369
bch2_btree_node_evict(trans, cur_k.k);
370370
cur = NULL;
371-
ret = bch2_run_explicit_recovery_pass(c, BCH_RECOVERY_PASS_scan_for_btree_nodes) ?:
372-
bch2_journal_key_delete(c, b->c.btree_id,
373-
b->c.level, cur_k.k->k.p);
371+
ret = bch2_journal_key_delete(c, b->c.btree_id,
372+
b->c.level, cur_k.k->k.p);
374373
if (ret)
375374
break;
375+
376+
if (!btree_id_is_alloc(b->c.btree_id)) {
377+
ret = bch2_run_explicit_recovery_pass(c, BCH_RECOVERY_PASS_scan_for_btree_nodes);
378+
if (ret)
379+
break;
380+
}
376381
continue;
377382
}
378383

fs/bcachefs/btree_node_scan.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ static void try_read_btree_node(struct find_btree_nodes *f, struct bch_dev *ca,
133133
if (le64_to_cpu(bn->magic) != bset_magic(c))
134134
return;
135135

136+
if (btree_id_is_alloc(BTREE_NODE_ID(bn)))
137+
return;
138+
136139
rcu_read_lock();
137140
struct found_btree_node n = {
138141
.btree_id = BTREE_NODE_ID(bn),
@@ -290,7 +293,7 @@ static int handle_overwrites(struct bch_fs *c,
290293
found_btree_node_to_text(&buf, c, n);
291294
bch_err(c, "%s", buf.buf);
292295
printbuf_exit(&buf);
293-
return -1;
296+
return -BCH_ERR_fsck_repair_unimplemented;
294297
}
295298
}
296299

@@ -436,6 +439,9 @@ bool bch2_btree_has_scanned_nodes(struct bch_fs *c, enum btree_id btree)
436439
int bch2_get_scanned_nodes(struct bch_fs *c, enum btree_id btree,
437440
unsigned level, struct bpos node_min, struct bpos node_max)
438441
{
442+
if (btree_id_is_alloc(btree))
443+
return 0;
444+
439445
struct find_btree_nodes *f = &c->found_btree_nodes;
440446

441447
int ret = bch2_run_explicit_recovery_pass(c, BCH_RECOVERY_PASS_scan_for_btree_nodes);

fs/bcachefs/recovery.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,6 @@ void bch2_btree_lost_data(struct bch_fs *c, enum btree_id btree)
4747
}
4848
}
4949

50-
static bool btree_id_is_alloc(enum btree_id id)
51-
{
52-
switch (id) {
53-
case BTREE_ID_alloc:
54-
case BTREE_ID_backpointers:
55-
case BTREE_ID_need_discard:
56-
case BTREE_ID_freespace:
57-
case BTREE_ID_bucket_gens:
58-
return true;
59-
default:
60-
return false;
61-
}
62-
}
63-
6450
/* for -o reconstruct_alloc: */
6551
static void bch2_reconstruct_alloc(struct bch_fs *c)
6652
{

0 commit comments

Comments
 (0)