bcachefs: Debug assertion improvements

Call bch2_btree_iter_verify from bch2_btree_node_iter_fix(); also verify
in btree_iter_peek_uptodate() that iter->k matches what's in the btree.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2019-09-19 16:07:41 -04:00 committed by Kent Overstreet
parent 554d219ebb
commit 059e4134d2
3 changed files with 26 additions and 35 deletions

View File

@ -542,14 +542,14 @@ static void __bch2_btree_node_iter_fix(struct btree_iter *iter,
goto fixup_done;
} else {
/* Iterator is after key that changed */
goto out_verify;
return;
}
found:
set->end = t->end_offset;
/* Iterator hasn't gotten to the key that changed yet: */
if (set->k < offset)
goto out_verify;
return;
if (new_u64s &&
btree_iter_pos_cmp(iter, b, where) > 0) {
@ -561,7 +561,7 @@ static void __bch2_btree_node_iter_fix(struct btree_iter *iter,
} else {
/* Iterator is after key that changed */
set->k = (int) set->k + shift;
goto out_verify;
return;
}
bch2_btree_node_iter_sort(node_iter, b);
@ -620,8 +620,6 @@ static void __bch2_btree_node_iter_fix(struct btree_iter *iter,
btree_iter_set_dirty(iter, BTREE_ITER_NEED_PEEK);
}
out_verify:
bch2_btree_node_iter_verify(node_iter, b);
}
void bch2_btree_node_iter_fix(struct btree_iter *iter,
@ -634,14 +632,18 @@ void bch2_btree_node_iter_fix(struct btree_iter *iter,
struct bset_tree *t = bch2_bkey_to_bset_inlined(b, where);
struct btree_iter *linked;
if (node_iter != &iter->l[b->c.level].iter)
if (node_iter != &iter->l[b->c.level].iter) {
__bch2_btree_node_iter_fix(iter, b, node_iter, t,
where, clobber_u64s, new_u64s);
where, clobber_u64s, new_u64s);
bch2_btree_node_iter_verify(node_iter, b);
}
trans_for_each_iter_with_node(iter->trans, b, linked)
trans_for_each_iter_with_node(iter->trans, b, linked) {
__bch2_btree_node_iter_fix(linked, b,
&linked->l[b->c.level].iter, t,
where, clobber_u64s, new_u64s);
&linked->l[b->c.level].iter, t,
where, clobber_u64s, new_u64s);
__bch2_btree_iter_verify(linked, b);
}
}
static inline struct bkey_s_c __btree_iter_unpack(struct btree_iter *iter,
@ -1341,14 +1343,20 @@ static inline struct bkey_s_c btree_iter_peek_uptodate(struct btree_iter *iter)
struct bkey_s_c ret = { .k = &iter->k };
if (!bkey_deleted(&iter->k)) {
EBUG_ON(bch2_btree_node_iter_end(&l->iter));
ret.v = bkeyp_val(&l->b->format,
__bch2_btree_node_iter_peek_all(&l->iter, l->b));
struct bkey_packed *_k =
__bch2_btree_node_iter_peek_all(&l->iter, l->b);
ret.v = bkeyp_val(&l->b->format, _k);
if (debug_check_iterators(iter->trans->c)) {
struct bkey k = bkey_unpack_key(l->b, _k);
BUG_ON(memcmp(&k, &iter->k, sizeof(k)));
}
if (debug_check_bkeys(iter->trans->c))
bch2_bkey_debugcheck(iter->trans->c, l->b, ret);
}
if (debug_check_bkeys(iter->trans->c) &&
!bkey_deleted(ret.k))
bch2_bkey_debugcheck(iter->trans->c, l->b, ret);
return ret;
}

View File

@ -151,7 +151,6 @@ bool bch2_btree_bset_insert_key(struct btree_iter *iter,
bch2_bset_delete(b, k, clobber_u64s);
bch2_btree_node_iter_fix(iter, b, node_iter,
k, clobber_u64s, 0);
bch2_btree_iter_verify(iter, b);
return true;
}
@ -161,7 +160,6 @@ bool bch2_btree_bset_insert_key(struct btree_iter *iter,
k->type = KEY_TYPE_deleted;
bch2_btree_node_iter_fix(iter, b, node_iter, k,
k->u64s, k->u64s);
bch2_btree_iter_verify(iter, b);
if (bkey_whiteout(&insert->k)) {
reserve_whiteout(b, k);
@ -185,7 +183,6 @@ bool bch2_btree_bset_insert_key(struct btree_iter *iter,
bch2_bset_insert(b, node_iter, k, insert, clobber_u64s);
bch2_btree_node_iter_fix(iter, b, node_iter, k,
clobber_u64s, k->u64s);
bch2_btree_iter_verify(iter, b);
return true;
}

View File

@ -875,13 +875,6 @@ static void verify_extent_nonoverlapping(struct bch_fs *c,
#endif
}
static void verify_modified_extent(struct btree_iter *iter,
struct bkey_packed *k)
{
bch2_btree_iter_verify(iter, iter->l[0].b);
bch2_verify_insert_pos(iter->l[0].b, k, k, k->u64s);
}
static void extent_bset_insert(struct bch_fs *c, struct btree_iter *iter,
struct bkey_i *insert)
{
@ -923,7 +916,6 @@ static void extent_bset_insert(struct bch_fs *c, struct btree_iter *iter,
bch2_bset_insert(l->b, &l->iter, k, insert, 0);
bch2_btree_node_iter_fix(iter, l->b, &l->iter, k, 0, k->u64s);
bch2_btree_iter_verify(iter, l->b);
}
static unsigned bch2_bkey_nr_alloc_ptrs(struct bkey_s_c k)
@ -1138,17 +1130,16 @@ extent_squash(struct bch_fs *c, struct btree_iter *iter,
case BCH_EXTENT_OVERLAP_FRONT:
/* insert overlaps with start of k: */
__bch2_cut_front(insert->k.p, k);
BUG_ON(bkey_deleted(k.k));
EBUG_ON(bkey_deleted(k.k));
extent_save(l->b, _k, k.k);
bch2_btree_node_iter_fix(iter, l->b, &l->iter,
_k, _k->u64s, _k->u64s);
verify_modified_extent(iter, _k);
break;
case BCH_EXTENT_OVERLAP_BACK:
/* insert overlaps with end of k: */
bch2_cut_back(bkey_start_pos(&insert->k), k.k);
BUG_ON(bkey_deleted(k.k));
EBUG_ON(bkey_deleted(k.k));
extent_save(l->b, _k, k.k);
/*
@ -1159,7 +1150,6 @@ extent_squash(struct bch_fs *c, struct btree_iter *iter,
bch2_bset_fix_invalidated_key(l->b, _k);
bch2_btree_node_iter_fix(iter, l->b, &l->iter,
_k, _k->u64s, _k->u64s);
verify_modified_extent(iter, _k);
break;
case BCH_EXTENT_OVERLAP_ALL: {
@ -1176,12 +1166,10 @@ extent_squash(struct bch_fs *c, struct btree_iter *iter,
bch2_bset_delete(l->b, _k, _k->u64s);
bch2_btree_node_iter_fix(iter, l->b, &l->iter,
_k, u64s, 0);
bch2_btree_iter_verify(iter, l->b);
} else {
extent_save(l->b, _k, k.k);
bch2_btree_node_iter_fix(iter, l->b, &l->iter,
_k, _k->u64s, _k->u64s);
verify_modified_extent(iter, _k);
}
break;
@ -1213,7 +1201,6 @@ extent_squash(struct bch_fs *c, struct btree_iter *iter,
extent_save(l->b, _k, k.k);
bch2_btree_node_iter_fix(iter, l->b, &l->iter,
_k, _k->u64s, _k->u64s);
verify_modified_extent(iter, _k);
extent_bset_insert(c, iter, &split.k);
break;
@ -1806,7 +1793,6 @@ static bool bch2_extent_merge_inline(struct bch_fs *c,
bch2_bset_fix_invalidated_key(b, m);
bch2_btree_node_iter_fix(iter, b, node_iter,
m, m->u64s, m->u64s);
verify_modified_extent(iter, m);
return ret == BCH_MERGE_MERGE;
}