mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
bcachefs: New helper __bch2_btree_insert_keys_interior()
Consolidate common parts of bch2_btree_insert_keys_interior() and btree_split_insert_keys() - prep work for adding some new topology assertions. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
bcd25dac53
commit
0098376f03
@ -1154,6 +1154,27 @@ static void bch2_insert_fixup_btree_ptr(struct btree_update *as, struct btree *b
|
||||
set_btree_node_need_write(b);
|
||||
}
|
||||
|
||||
static void
|
||||
__bch2_btree_insert_keys_interior(struct btree_update *as, struct btree *b,
|
||||
struct btree_iter *iter, struct keylist *keys,
|
||||
struct btree_node_iter node_iter)
|
||||
{
|
||||
struct bkey_i *insert = bch2_keylist_front(keys);
|
||||
struct bkey_packed *k;
|
||||
|
||||
BUG_ON(btree_node_type(b) != BKEY_TYPE_btree);
|
||||
|
||||
while ((k = bch2_btree_node_iter_prev_all(&node_iter, b)) &&
|
||||
(bkey_cmp_left_packed(b, k, &insert->k.p) >= 0))
|
||||
;
|
||||
|
||||
while (!bch2_keylist_empty(keys)) {
|
||||
bch2_insert_fixup_btree_ptr(as, b, iter,
|
||||
bch2_keylist_front(keys), &node_iter);
|
||||
bch2_keylist_pop_front(keys);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Move keys from n1 (original replacement node, now lower node) to n2 (higher
|
||||
* node)
|
||||
@ -1284,16 +1305,9 @@ static void btree_split_insert_keys(struct btree_update *as, struct btree *b,
|
||||
struct bkey_packed *src, *dst, *n;
|
||||
struct bset *i;
|
||||
|
||||
BUG_ON(btree_node_type(b) != BKEY_TYPE_btree);
|
||||
|
||||
bch2_btree_node_iter_init(&node_iter, b, &k->k.p);
|
||||
|
||||
while (!bch2_keylist_empty(keys)) {
|
||||
k = bch2_keylist_front(keys);
|
||||
|
||||
bch2_insert_fixup_btree_ptr(as, b, iter, k, &node_iter);
|
||||
bch2_keylist_pop_front(keys);
|
||||
}
|
||||
__bch2_btree_insert_keys_interior(as, b, iter, keys, node_iter);
|
||||
|
||||
/*
|
||||
* We can't tolerate whiteouts here - with whiteouts there can be
|
||||
@ -1439,24 +1453,8 @@ bch2_btree_insert_keys_interior(struct btree_update *as, struct btree *b,
|
||||
struct btree_iter *iter, struct keylist *keys)
|
||||
{
|
||||
struct btree_iter *linked;
|
||||
struct btree_node_iter node_iter;
|
||||
struct bkey_i *insert = bch2_keylist_front(keys);
|
||||
struct bkey_packed *k;
|
||||
|
||||
/* Don't screw up @iter's position: */
|
||||
node_iter = iter->l[b->c.level].iter;
|
||||
|
||||
/*
|
||||
* btree_split(), btree_gc_coalesce() will insert keys before
|
||||
* the iterator's current position - they know the keys go in
|
||||
* the node the iterator points to:
|
||||
*/
|
||||
while ((k = bch2_btree_node_iter_prev_all(&node_iter, b)) &&
|
||||
(bkey_cmp_left_packed(b, k, &insert->k.p) >= 0))
|
||||
;
|
||||
|
||||
for_each_keylist_key(keys, insert)
|
||||
bch2_insert_fixup_btree_ptr(as, b, iter, insert, &node_iter);
|
||||
__bch2_btree_insert_keys_interior(as, b, iter, keys, iter->l[b->c.level].iter);
|
||||
|
||||
btree_update_updated_node(as, b);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user