Commit a9d1f910 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Debug code improvements

.key_debugcheck no longer needs to take a pointer to the btree node

Also, try to make sure wherever we're inserting or modifying keys in the
btree.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 4cac0bf2
...@@ -145,7 +145,7 @@ void bch2_bkey_debugcheck(struct bch_fs *c, struct btree *b, struct bkey_s_c k) ...@@ -145,7 +145,7 @@ void bch2_bkey_debugcheck(struct bch_fs *c, struct btree *b, struct bkey_s_c k)
} }
if (ops->key_debugcheck) if (ops->key_debugcheck)
ops->key_debugcheck(c, b, k); ops->key_debugcheck(c, k);
} }
void bch2_bpos_to_text(struct printbuf *out, struct bpos pos) void bch2_bpos_to_text(struct printbuf *out, struct bpos pos)
......
...@@ -26,8 +26,7 @@ struct bkey_ops { ...@@ -26,8 +26,7 @@ struct bkey_ops {
/* Returns reason for being invalid if invalid, else NULL: */ /* Returns reason for being invalid if invalid, else NULL: */
const char * (*key_invalid)(const struct bch_fs *, const char * (*key_invalid)(const struct bch_fs *,
struct bkey_s_c); struct bkey_s_c);
void (*key_debugcheck)(struct bch_fs *, struct btree *, void (*key_debugcheck)(struct bch_fs *, struct bkey_s_c);
struct bkey_s_c);
void (*val_to_text)(struct printbuf *, struct bch_fs *, void (*val_to_text)(struct printbuf *, struct bch_fs *,
struct bkey_s_c); struct bkey_s_c);
void (*swab)(const struct bkey_format *, struct bkey_packed *); void (*swab)(const struct bkey_format *, struct bkey_packed *);
......
...@@ -671,8 +671,7 @@ const char *bch2_btree_ptr_invalid(const struct bch_fs *c, struct bkey_s_c k) ...@@ -671,8 +671,7 @@ const char *bch2_btree_ptr_invalid(const struct bch_fs *c, struct bkey_s_c k)
return bch2_bkey_ptrs_invalid(c, k); return bch2_bkey_ptrs_invalid(c, k);
} }
void bch2_btree_ptr_debugcheck(struct bch_fs *c, struct btree *b, void bch2_btree_ptr_debugcheck(struct bch_fs *c, struct bkey_s_c k)
struct bkey_s_c k)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr; const struct bch_extent_ptr *ptr;
...@@ -895,6 +894,9 @@ static void extent_bset_insert(struct bch_fs *c, struct btree_iter *iter, ...@@ -895,6 +894,9 @@ static void extent_bset_insert(struct bch_fs *c, struct btree_iter *iter,
EBUG_ON(bkey_deleted(&insert->k) || !insert->k.size); EBUG_ON(bkey_deleted(&insert->k) || !insert->k.size);
verify_extent_nonoverlapping(c, l->b, &l->iter, insert); verify_extent_nonoverlapping(c, l->b, &l->iter, insert);
if (debug_check_bkeys(c))
bch2_bkey_debugcheck(c, l->b, bkey_i_to_s_c(insert));
node_iter = l->iter; node_iter = l->iter;
k = bch2_btree_node_iter_prev_filter(&node_iter, l->b, KEY_TYPE_discard); k = bch2_btree_node_iter_prev_filter(&node_iter, l->b, KEY_TYPE_discard);
if (k && !bkey_written(l->b, k) && if (k && !bkey_written(l->b, k) &&
...@@ -1362,10 +1364,6 @@ void bch2_insert_fixup_extent(struct btree_trans *trans, ...@@ -1362,10 +1364,6 @@ void bch2_insert_fixup_extent(struct btree_trans *trans,
if (s.deleting) if (s.deleting)
tmp.k.k.type = KEY_TYPE_discard; tmp.k.k.type = KEY_TYPE_discard;
if (debug_check_bkeys(c))
bch2_bkey_debugcheck(c, iter->l[0].b,
bkey_i_to_s_c(&tmp.k));
EBUG_ON(bkey_deleted(&tmp.k.k) || !tmp.k.k.size); EBUG_ON(bkey_deleted(&tmp.k.k) || !tmp.k.k.size);
extent_bset_insert(c, iter, &tmp.k); extent_bset_insert(c, iter, &tmp.k);
...@@ -1390,8 +1388,7 @@ const char *bch2_extent_invalid(const struct bch_fs *c, struct bkey_s_c k) ...@@ -1390,8 +1388,7 @@ const char *bch2_extent_invalid(const struct bch_fs *c, struct bkey_s_c k)
return bch2_bkey_ptrs_invalid(c, k); return bch2_bkey_ptrs_invalid(c, k);
} }
void bch2_extent_debugcheck(struct bch_fs *c, struct btree *b, void bch2_extent_debugcheck(struct bch_fs *c, struct bkey_s_c k)
struct bkey_s_c k)
{ {
struct bkey_s_c_extent e = bkey_s_c_to_extent(k); struct bkey_s_c_extent e = bkey_s_c_to_extent(k);
const union bch_extent_entry *entry; const union bch_extent_entry *entry;
...@@ -1765,6 +1762,12 @@ static bool bch2_extent_merge_inline(struct bch_fs *c, ...@@ -1765,6 +1762,12 @@ static bool bch2_extent_merge_inline(struct bch_fs *c,
if (ret == BCH_MERGE_NOMERGE) if (ret == BCH_MERGE_NOMERGE)
return false; return false;
if (debug_check_bkeys(c))
bch2_bkey_debugcheck(c, b, bkey_i_to_s_c(&li.k));
if (debug_check_bkeys(c) &&
ret == BCH_MERGE_PARTIAL)
bch2_bkey_debugcheck(c, b, bkey_i_to_s_c(&ri.k));
/* /*
* check if we overlap with deleted extents - would break the sort * check if we overlap with deleted extents - would break the sort
* order: * order:
......
...@@ -389,8 +389,7 @@ const char *bch2_bkey_ptrs_invalid(const struct bch_fs *, struct bkey_s_c); ...@@ -389,8 +389,7 @@ const char *bch2_bkey_ptrs_invalid(const struct bch_fs *, struct bkey_s_c);
/* bch_btree_ptr: */ /* bch_btree_ptr: */
const char *bch2_btree_ptr_invalid(const struct bch_fs *, struct bkey_s_c); const char *bch2_btree_ptr_invalid(const struct bch_fs *, struct bkey_s_c);
void bch2_btree_ptr_debugcheck(struct bch_fs *, struct btree *, void bch2_btree_ptr_debugcheck(struct bch_fs *, struct bkey_s_c);
struct bkey_s_c);
void bch2_btree_ptr_to_text(struct printbuf *, struct bch_fs *, void bch2_btree_ptr_to_text(struct printbuf *, struct bch_fs *,
struct bkey_s_c); struct bkey_s_c);
void bch2_ptr_swab(const struct bkey_format *, struct bkey_packed *); void bch2_ptr_swab(const struct bkey_format *, struct bkey_packed *);
...@@ -405,7 +404,7 @@ void bch2_ptr_swab(const struct bkey_format *, struct bkey_packed *); ...@@ -405,7 +404,7 @@ void bch2_ptr_swab(const struct bkey_format *, struct bkey_packed *);
/* bch_extent: */ /* bch_extent: */
const char *bch2_extent_invalid(const struct bch_fs *, struct bkey_s_c); const char *bch2_extent_invalid(const struct bch_fs *, struct bkey_s_c);
void bch2_extent_debugcheck(struct bch_fs *, struct btree *, struct bkey_s_c); void bch2_extent_debugcheck(struct bch_fs *, struct bkey_s_c);
void bch2_extent_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c); void bch2_extent_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
bool bch2_extent_normalize(struct bch_fs *, struct bkey_s); bool bch2_extent_normalize(struct bch_fs *, struct bkey_s);
enum merge_result bch2_extent_merge(struct bch_fs *, enum merge_result bch2_extent_merge(struct bch_fs *,
......
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