Commit 63f1a598 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Improved debug checks

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 2cbe5cfe
...@@ -21,6 +21,16 @@ ...@@ -21,6 +21,16 @@
static inline void __bch2_btree_node_iter_advance(struct btree_node_iter *, static inline void __bch2_btree_node_iter_advance(struct btree_node_iter *,
struct btree *); struct btree *);
static inline unsigned __btree_node_iter_used(struct btree_node_iter *iter)
{
unsigned n = ARRAY_SIZE(iter->data);
while (n && __btree_node_iter_set_end(iter, n - 1))
--n;
return n;
}
struct bset_tree *bch2_bkey_to_bset(struct btree *b, struct bkey_packed *k) struct bset_tree *bch2_bkey_to_bset(struct btree *b, struct bkey_packed *k)
{ {
return bch2_bkey_to_bset_inlined(b, k); return bch2_bkey_to_bset_inlined(b, k);
...@@ -98,7 +108,8 @@ void bch2_dump_btree_node_iter(struct btree *b, ...@@ -98,7 +108,8 @@ void bch2_dump_btree_node_iter(struct btree *b,
{ {
struct btree_node_iter_set *set; struct btree_node_iter_set *set;
printk(KERN_ERR "btree node iter with %u sets:\n", b->nsets); printk(KERN_ERR "btree node iter with %u/%u sets:\n",
__btree_node_iter_used(iter), b->nsets);
btree_node_iter_for_each(iter, set) { btree_node_iter_for_each(iter, set) {
struct bkey_packed *k = __btree_node_offset_to_key(b, set->k); struct bkey_packed *k = __btree_node_offset_to_key(b, set->k);
...@@ -107,8 +118,8 @@ void bch2_dump_btree_node_iter(struct btree *b, ...@@ -107,8 +118,8 @@ void bch2_dump_btree_node_iter(struct btree *b,
char buf[100]; char buf[100];
bch2_bkey_to_text(&PBUF(buf), &uk); bch2_bkey_to_text(&PBUF(buf), &uk);
printk(KERN_ERR "set %zu key %zi/%u: %s\n", t - b->set, printk(KERN_ERR "set %zu key %u: %s\n",
k->_data - bset(b, t)->_data, bset(b, t)->u64s, buf); t - b->set, set->k, buf);
} }
} }
...@@ -170,8 +181,12 @@ void bch2_btree_node_iter_verify(struct btree_node_iter *iter, ...@@ -170,8 +181,12 @@ void bch2_btree_node_iter_verify(struct btree_node_iter *iter,
struct btree *b) struct btree *b)
{ {
struct btree_node_iter_set *set, *s2; struct btree_node_iter_set *set, *s2;
struct bkey_packed *k, *p;
struct bset_tree *t; struct bset_tree *t;
if (bch2_btree_node_iter_end(iter))
return;
/* Verify no duplicates: */ /* Verify no duplicates: */
btree_node_iter_for_each(iter, set) btree_node_iter_for_each(iter, set)
btree_node_iter_for_each(iter, s2) btree_node_iter_for_each(iter, s2)
...@@ -192,6 +207,18 @@ void bch2_btree_node_iter_verify(struct btree_node_iter *iter, ...@@ -192,6 +207,18 @@ void bch2_btree_node_iter_verify(struct btree_node_iter *iter,
btree_node_iter_for_each(iter, set) btree_node_iter_for_each(iter, set)
BUG_ON(set != iter->data && BUG_ON(set != iter->data &&
btree_node_iter_cmp(b, set[-1], set[0]) > 0); btree_node_iter_cmp(b, set[-1], set[0]) > 0);
k = bch2_btree_node_iter_peek_all(iter, b);
for_each_bset(b, t) {
if (iter->data[0].end == t->end_offset)
continue;
p = bch2_bkey_prev_all(b, t,
bch2_btree_node_iter_bset_pos(iter, b, t));
BUG_ON(p && bkey_iter_cmp(b, k, p) < 0);
}
} }
void bch2_verify_insert_pos(struct btree *b, struct bkey_packed *where, void bch2_verify_insert_pos(struct btree *b, struct bkey_packed *where,
...@@ -1652,16 +1679,6 @@ void bch2_btree_node_iter_advance(struct btree_node_iter *iter, ...@@ -1652,16 +1679,6 @@ void bch2_btree_node_iter_advance(struct btree_node_iter *iter,
__bch2_btree_node_iter_advance(iter, b); __bch2_btree_node_iter_advance(iter, b);
} }
static inline unsigned __btree_node_iter_used(struct btree_node_iter *iter)
{
unsigned n = ARRAY_SIZE(iter->data);
while (n && __btree_node_iter_set_end(iter, n - 1))
--n;
return n;
}
/* /*
* Expensive: * Expensive:
*/ */
......
...@@ -1477,6 +1477,8 @@ __bch2_btree_iter_peek_slot_extents(struct btree_iter *iter) ...@@ -1477,6 +1477,8 @@ __bch2_btree_iter_peek_slot_extents(struct btree_iter *iter)
EBUG_ON(bkey_cmp(k.k->p, iter->pos) < 0); EBUG_ON(bkey_cmp(k.k->p, iter->pos) < 0);
EBUG_ON(bkey_deleted(k.k)); EBUG_ON(bkey_deleted(k.k));
iter->uptodate = BTREE_ITER_UPTODATE; iter->uptodate = BTREE_ITER_UPTODATE;
__bch2_btree_iter_verify(iter, l->b);
return k; return k;
} }
...@@ -1507,6 +1509,8 @@ __bch2_btree_iter_peek_slot_extents(struct btree_iter *iter) ...@@ -1507,6 +1509,8 @@ __bch2_btree_iter_peek_slot_extents(struct btree_iter *iter)
iter->k = n; iter->k = n;
iter->uptodate = BTREE_ITER_UPTODATE; iter->uptodate = BTREE_ITER_UPTODATE;
__bch2_btree_iter_verify(iter, l->b);
return (struct bkey_s_c) { &iter->k, NULL }; return (struct bkey_s_c) { &iter->k, NULL };
} }
...@@ -1539,19 +1543,18 @@ __bch2_btree_iter_peek_slot(struct btree_iter *iter) ...@@ -1539,19 +1543,18 @@ __bch2_btree_iter_peek_slot(struct btree_iter *iter)
goto recheck; goto recheck;
} }
if (k.k && if (!k.k ||
!bkey_deleted(k.k) && bkey_deleted(k.k) ||
!bkey_cmp(iter->pos, k.k->p)) { bkey_cmp(iter->pos, k.k->p)) {
iter->uptodate = BTREE_ITER_UPTODATE;
return k;
} else {
/* hole */ /* hole */
bkey_init(&iter->k); bkey_init(&iter->k);
iter->k.p = iter->pos; iter->k.p = iter->pos;
k = (struct bkey_s_c) { &iter->k, NULL };
iter->uptodate = BTREE_ITER_UPTODATE;
return (struct bkey_s_c) { &iter->k, NULL };
} }
iter->uptodate = BTREE_ITER_UPTODATE;
__bch2_btree_iter_verify(iter, l->b);
return k;
} }
struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
......
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