bcachefs: Improved debug checks

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2019-08-17 15:17:09 -04:00 committed by Kent Overstreet
parent 2cbe5cfe27
commit 63f1a59847
2 changed files with 42 additions and 22 deletions

View File

@ -21,6 +21,16 @@
static inline void __bch2_btree_node_iter_advance(struct btree_node_iter *,
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)
{
return bch2_bkey_to_bset_inlined(b, k);
@ -98,7 +108,8 @@ void bch2_dump_btree_node_iter(struct btree *b,
{
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) {
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,
char buf[100];
bch2_bkey_to_text(&PBUF(buf), &uk);
printk(KERN_ERR "set %zu key %zi/%u: %s\n", t - b->set,
k->_data - bset(b, t)->_data, bset(b, t)->u64s, buf);
printk(KERN_ERR "set %zu key %u: %s\n",
t - b->set, set->k, buf);
}
}
@ -170,8 +181,12 @@ void bch2_btree_node_iter_verify(struct btree_node_iter *iter,
struct btree *b)
{
struct btree_node_iter_set *set, *s2;
struct bkey_packed *k, *p;
struct bset_tree *t;
if (bch2_btree_node_iter_end(iter))
return;
/* Verify no duplicates: */
btree_node_iter_for_each(iter, set)
btree_node_iter_for_each(iter, s2)
@ -192,6 +207,18 @@ found:
btree_node_iter_for_each(iter, set)
BUG_ON(set != iter->data &&
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,
@ -1652,16 +1679,6 @@ void bch2_btree_node_iter_advance(struct btree_node_iter *iter,
__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:
*/

View File

@ -1477,6 +1477,8 @@ recheck:
EBUG_ON(bkey_cmp(k.k->p, iter->pos) < 0);
EBUG_ON(bkey_deleted(k.k));
iter->uptodate = BTREE_ITER_UPTODATE;
__bch2_btree_iter_verify(iter, l->b);
return k;
}
@ -1507,6 +1509,8 @@ recheck:
iter->k = n;
iter->uptodate = BTREE_ITER_UPTODATE;
__bch2_btree_iter_verify(iter, l->b);
return (struct bkey_s_c) { &iter->k, NULL };
}
@ -1539,19 +1543,18 @@ recheck:
goto recheck;
}
if (k.k &&
!bkey_deleted(k.k) &&
!bkey_cmp(iter->pos, k.k->p)) {
iter->uptodate = BTREE_ITER_UPTODATE;
return k;
} else {
if (!k.k ||
bkey_deleted(k.k) ||
bkey_cmp(iter->pos, k.k->p)) {
/* hole */
bkey_init(&iter->k);
iter->k.p = iter->pos;
iter->uptodate = BTREE_ITER_UPTODATE;
return (struct bkey_s_c) { &iter->k, NULL };
k = (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)