Commit 812a9297 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix btree node keys accounting in topology repair path

When dropping keys now outside a now because we're changing the node
min/max, we need to redo the node's accounting as well.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 805b535a
...@@ -134,18 +134,24 @@ void bch2_dump_btree_node_iter(struct btree *b, ...@@ -134,18 +134,24 @@ void bch2_dump_btree_node_iter(struct btree *b,
printbuf_exit(&buf); printbuf_exit(&buf);
} }
#ifdef CONFIG_BCACHEFS_DEBUG struct btree_nr_keys bch2_btree_node_count_keys(struct btree *b)
void __bch2_verify_btree_nr_keys(struct btree *b)
{ {
struct bset_tree *t; struct bset_tree *t;
struct bkey_packed *k; struct bkey_packed *k;
struct btree_nr_keys nr = { 0 }; struct btree_nr_keys nr = {};
for_each_bset(b, t) for_each_bset(b, t)
bset_tree_for_each_key(b, t, k) bset_tree_for_each_key(b, t, k)
if (!bkey_deleted(k)) if (!bkey_deleted(k))
btree_keys_account_key_add(&nr, t - b->set, k); btree_keys_account_key_add(&nr, t - b->set, k);
return nr;
}
#ifdef CONFIG_BCACHEFS_DEBUG
void __bch2_verify_btree_nr_keys(struct btree *b)
{
struct btree_nr_keys nr = bch2_btree_node_count_keys(b);
BUG_ON(memcmp(&nr, &b->nr, sizeof(nr))); BUG_ON(memcmp(&nr, &b->nr, sizeof(nr)));
} }
......
...@@ -458,6 +458,8 @@ struct bkey_s_c bch2_btree_node_iter_peek_unpack(struct btree_node_iter *, ...@@ -458,6 +458,8 @@ struct bkey_s_c bch2_btree_node_iter_peek_unpack(struct btree_node_iter *,
/* Accounting: */ /* Accounting: */
struct btree_nr_keys bch2_btree_node_count_keys(struct btree *);
static inline void btree_keys_account_key(struct btree_nr_keys *n, static inline void btree_keys_account_key(struct btree_nr_keys *n,
unsigned bset, unsigned bset,
struct bkey_packed *k, struct bkey_packed *k,
......
...@@ -654,6 +654,7 @@ void bch2_btree_node_drop_keys_outside_node(struct btree *b) ...@@ -654,6 +654,7 @@ void bch2_btree_node_drop_keys_outside_node(struct btree *b)
*/ */
bch2_bset_set_no_aux_tree(b, b->set); bch2_bset_set_no_aux_tree(b, b->set);
bch2_btree_build_aux_trees(b); bch2_btree_build_aux_trees(b);
b->nr = bch2_btree_node_count_keys(b);
struct bkey_s_c k; struct bkey_s_c k;
struct bkey unpacked; struct bkey unpacked;
......
...@@ -1543,6 +1543,7 @@ static int btree_split(struct btree_update *as, struct btree_trans *trans, ...@@ -1543,6 +1543,7 @@ static int btree_split(struct btree_update *as, struct btree_trans *trans,
u64 start_time = local_clock(); u64 start_time = local_clock();
int ret = 0; int ret = 0;
bch2_verify_btree_nr_keys(b);
BUG_ON(!parent && (b != btree_node_root(c, b))); BUG_ON(!parent && (b != btree_node_root(c, b)));
BUG_ON(parent && !btree_node_intent_locked(trans->paths + path, b->c.level + 1)); BUG_ON(parent && !btree_node_intent_locked(trans->paths + path, b->c.level + 1));
......
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