mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-17 02:36:21 +00:00
bcachefs: Clean up/rename bch2_trans_node_* fns
These utility functions are for managing btree node state within a btree_trans - rename them for consistency, and drop some unneeded arguments. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
parent
78cf784eaa
commit
f7a966a3e2
@ -459,16 +459,13 @@ void bch2_btree_build_aux_trees(struct btree *b)
|
||||
*
|
||||
* Returns true if we sorted (i.e. invalidated iterators
|
||||
*/
|
||||
void bch2_btree_init_next(struct btree_trans *trans,
|
||||
struct btree_iter *iter,
|
||||
struct btree *b)
|
||||
void bch2_btree_init_next(struct btree_trans *trans, struct btree *b)
|
||||
{
|
||||
struct bch_fs *c = trans->c;
|
||||
struct btree_node_entry *bne;
|
||||
bool reinit_iter = false;
|
||||
|
||||
EBUG_ON(!(b->c.lock.state.seq & 1));
|
||||
EBUG_ON(iter && iter->l[b->c.level].b != b);
|
||||
BUG_ON(bset_written(b, bset(b, &b->set[1])));
|
||||
|
||||
if (b->nsets == MAX_BSETS &&
|
||||
@ -497,8 +494,8 @@ void bch2_btree_init_next(struct btree_trans *trans,
|
||||
|
||||
bch2_btree_build_aux_trees(b);
|
||||
|
||||
if (iter && reinit_iter)
|
||||
bch2_btree_iter_reinit_node(trans, iter, b);
|
||||
if (reinit_iter)
|
||||
bch2_trans_node_reinit_iter(trans, b);
|
||||
}
|
||||
|
||||
static void btree_pos_to_text(struct printbuf *out, struct bch_fs *c,
|
||||
|
@ -134,8 +134,7 @@ void bch2_btree_sort_into(struct bch_fs *, struct btree *, struct btree *);
|
||||
void bch2_btree_node_drop_keys_outside_node(struct btree *);
|
||||
|
||||
void bch2_btree_build_aux_trees(struct btree *);
|
||||
void bch2_btree_init_next(struct btree_trans *, struct btree_iter *,
|
||||
struct btree *);
|
||||
void bch2_btree_init_next(struct btree_trans *, struct btree *);
|
||||
|
||||
int bch2_btree_node_read_done(struct bch_fs *, struct bch_dev *,
|
||||
struct btree *, bool);
|
||||
|
@ -757,15 +757,14 @@ static void __bch2_btree_iter_fix_key_modified(struct btree_iter *iter,
|
||||
}
|
||||
|
||||
void bch2_btree_iter_fix_key_modified(struct btree_trans *trans,
|
||||
struct btree_iter *iter,
|
||||
struct btree *b,
|
||||
struct bkey_packed *where)
|
||||
{
|
||||
struct btree_iter *linked;
|
||||
struct btree_iter *iter;
|
||||
|
||||
trans_for_each_iter_with_node(trans, b, linked) {
|
||||
__bch2_btree_iter_fix_key_modified(linked, b, where);
|
||||
bch2_btree_iter_verify_level(trans, linked, b->c.level);
|
||||
trans_for_each_iter_with_node(trans, b, iter) {
|
||||
__bch2_btree_iter_fix_key_modified(iter, b, where);
|
||||
bch2_btree_iter_verify_level(trans, iter, b->c.level);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1062,42 +1061,40 @@ static inline void btree_iter_level_init(struct btree_trans *trans,
|
||||
* A btree node is being replaced - update the iterator to point to the new
|
||||
* node:
|
||||
*/
|
||||
void bch2_btree_iter_node_replace(struct btree_trans *trans,
|
||||
struct btree_iter *iter, struct btree *b)
|
||||
void bch2_trans_node_add(struct btree_trans *trans, struct btree *b)
|
||||
{
|
||||
enum btree_node_locked_type t;
|
||||
struct btree_iter *linked;
|
||||
struct btree_iter *iter;
|
||||
|
||||
trans_for_each_iter(trans, linked)
|
||||
if (btree_iter_type(linked) != BTREE_ITER_CACHED &&
|
||||
btree_iter_pos_in_node(linked, b)) {
|
||||
trans_for_each_iter(trans, iter)
|
||||
if (btree_iter_type(iter) != BTREE_ITER_CACHED &&
|
||||
btree_iter_pos_in_node(iter, b)) {
|
||||
/*
|
||||
* bch2_btree_iter_node_drop() has already been called -
|
||||
* bch2_trans_node_drop() has already been called -
|
||||
* the old node we're replacing has already been
|
||||
* unlocked and the pointer invalidated
|
||||
*/
|
||||
BUG_ON(btree_node_locked(linked, b->c.level));
|
||||
BUG_ON(btree_node_locked(iter, b->c.level));
|
||||
|
||||
t = btree_lock_want(linked, b->c.level);
|
||||
t = btree_lock_want(iter, b->c.level);
|
||||
if (t != BTREE_NODE_UNLOCKED) {
|
||||
six_lock_increment(&b->c.lock, (enum six_lock_type) t);
|
||||
mark_btree_node_locked(linked, b->c.level, (enum six_lock_type) t);
|
||||
mark_btree_node_locked(iter, b->c.level, (enum six_lock_type) t);
|
||||
}
|
||||
|
||||
btree_iter_level_init(trans, linked, b);
|
||||
btree_iter_level_init(trans, iter, b);
|
||||
}
|
||||
}
|
||||
|
||||
void bch2_btree_iter_node_drop(struct btree_trans *trans,
|
||||
struct btree_iter *iter, struct btree *b)
|
||||
void bch2_trans_node_drop(struct btree_trans *trans, struct btree *b)
|
||||
{
|
||||
struct btree_iter *linked;
|
||||
struct btree_iter *iter;
|
||||
unsigned level = b->c.level;
|
||||
|
||||
trans_for_each_iter(trans, linked)
|
||||
if (linked->l[level].b == b) {
|
||||
btree_node_unlock(linked, level);
|
||||
linked->l[level].b = BTREE_ITER_NO_NODE_DROP;
|
||||
trans_for_each_iter(trans, iter)
|
||||
if (iter->l[level].b == b) {
|
||||
btree_node_unlock(iter, level);
|
||||
iter->l[level].b = BTREE_ITER_NO_NODE_DROP;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1105,13 +1102,12 @@ void bch2_btree_iter_node_drop(struct btree_trans *trans,
|
||||
* A btree node has been modified in such a way as to invalidate iterators - fix
|
||||
* them:
|
||||
*/
|
||||
void bch2_btree_iter_reinit_node(struct btree_trans *trans,
|
||||
struct btree_iter *iter, struct btree *b)
|
||||
void bch2_trans_node_reinit_iter(struct btree_trans *trans, struct btree *b)
|
||||
{
|
||||
struct btree_iter *linked;
|
||||
struct btree_iter *iter;
|
||||
|
||||
trans_for_each_iter_with_node(trans, b, linked)
|
||||
__btree_iter_level_init(linked, b->c.level);
|
||||
trans_for_each_iter_with_node(trans, b, iter)
|
||||
__btree_iter_level_init(iter, b->c.level);
|
||||
}
|
||||
|
||||
static int lock_root_check_fn(struct six_lock *lock, void *p)
|
||||
|
@ -135,7 +135,7 @@ static inline void bch2_btree_trans_verify_iters(struct btree_trans *trans,
|
||||
static inline void bch2_btree_trans_verify_locks(struct btree_trans *iter) {}
|
||||
#endif
|
||||
|
||||
void bch2_btree_iter_fix_key_modified(struct btree_trans *trans, struct btree_iter *,
|
||||
void bch2_btree_iter_fix_key_modified(struct btree_trans *trans,
|
||||
struct btree *, struct bkey_packed *);
|
||||
void bch2_btree_node_iter_fix(struct btree_trans *trans, struct btree_iter *,
|
||||
struct btree *, struct btree_node_iter *,
|
||||
@ -180,13 +180,9 @@ static inline void bch2_btree_iter_downgrade(struct btree_iter *iter)
|
||||
|
||||
void bch2_trans_downgrade(struct btree_trans *);
|
||||
|
||||
void bch2_btree_iter_node_replace(struct btree_trans *trans,
|
||||
struct btree_iter *, struct btree *);
|
||||
void bch2_btree_iter_node_drop(struct btree_trans *,
|
||||
struct btree_iter *, struct btree *);
|
||||
|
||||
void bch2_btree_iter_reinit_node(struct btree_trans *,
|
||||
struct btree_iter *, struct btree *);
|
||||
void bch2_trans_node_add(struct btree_trans *trans, struct btree *);
|
||||
void bch2_trans_node_drop(struct btree_trans *, struct btree *);
|
||||
void bch2_trans_node_reinit_iter(struct btree_trans *, struct btree *);
|
||||
|
||||
int __must_check bch2_btree_iter_traverse(struct btree_iter *);
|
||||
|
||||
|
@ -161,14 +161,13 @@ static void __btree_node_free(struct bch_fs *c, struct btree *b)
|
||||
}
|
||||
|
||||
static void bch2_btree_node_free_inmem(struct btree_trans *trans,
|
||||
struct btree_iter *iter,
|
||||
struct btree *b)
|
||||
{
|
||||
struct bch_fs *c = trans->c;
|
||||
struct btree_iter *linked;
|
||||
struct btree_iter *iter;
|
||||
|
||||
trans_for_each_iter(trans, linked)
|
||||
BUG_ON(linked->l[b->c.level].b == b);
|
||||
trans_for_each_iter(trans, iter)
|
||||
BUG_ON(iter->l[b->c.level].b == b);
|
||||
|
||||
six_lock_write(&b->c.lock, NULL, NULL);
|
||||
__btree_node_free(c, b);
|
||||
@ -1431,12 +1430,12 @@ static void btree_split(struct btree_update *as,
|
||||
/* Successful split, update the iterator to point to the new nodes: */
|
||||
|
||||
six_lock_increment(&b->c.lock, SIX_LOCK_intent);
|
||||
bch2_btree_iter_node_drop(trans, iter, b);
|
||||
bch2_trans_node_drop(trans, b);
|
||||
if (n3)
|
||||
bch2_btree_iter_node_replace(trans, iter, n3);
|
||||
bch2_trans_node_add(trans, n3);
|
||||
if (n2)
|
||||
bch2_btree_iter_node_replace(trans, iter, n2);
|
||||
bch2_btree_iter_node_replace(trans, iter, n1);
|
||||
bch2_trans_node_add(trans, n2);
|
||||
bch2_trans_node_add(trans, n1);
|
||||
|
||||
/*
|
||||
* The old node must be freed (in memory) _before_ unlocking the new
|
||||
@ -1444,7 +1443,7 @@ static void btree_split(struct btree_update *as,
|
||||
* node after another thread has locked and updated the new node, thus
|
||||
* seeing stale data:
|
||||
*/
|
||||
bch2_btree_node_free_inmem(trans, iter, b);
|
||||
bch2_btree_node_free_inmem(trans, b);
|
||||
|
||||
if (n3)
|
||||
six_unlock_intent(&n3->c.lock);
|
||||
@ -1527,7 +1526,7 @@ static void bch2_btree_insert_node(struct btree_update *as,
|
||||
|
||||
if (u64s_added > live_u64s_added &&
|
||||
bch2_maybe_compact_whiteouts(c, b))
|
||||
bch2_btree_iter_reinit_node(trans, iter, b);
|
||||
bch2_trans_node_reinit_iter(trans, b);
|
||||
|
||||
bch2_btree_node_unlock_write(trans, iter, b);
|
||||
|
||||
@ -1702,15 +1701,15 @@ retry:
|
||||
|
||||
six_lock_increment(&b->c.lock, SIX_LOCK_intent);
|
||||
six_lock_increment(&m->c.lock, SIX_LOCK_intent);
|
||||
bch2_btree_iter_node_drop(trans, iter, b);
|
||||
bch2_btree_iter_node_drop(trans, iter, m);
|
||||
bch2_trans_node_drop(trans, b);
|
||||
bch2_trans_node_drop(trans, m);
|
||||
|
||||
bch2_btree_iter_node_replace(trans, iter, n);
|
||||
bch2_trans_node_add(trans, n);
|
||||
|
||||
bch2_btree_trans_verify_iters(trans, n);
|
||||
|
||||
bch2_btree_node_free_inmem(trans, iter, b);
|
||||
bch2_btree_node_free_inmem(trans, iter, m);
|
||||
bch2_btree_node_free_inmem(trans, b);
|
||||
bch2_btree_node_free_inmem(trans, m);
|
||||
|
||||
six_unlock_intent(&n->c.lock);
|
||||
|
||||
@ -1798,9 +1797,9 @@ retry:
|
||||
bch2_btree_update_get_open_buckets(as, n);
|
||||
|
||||
six_lock_increment(&b->c.lock, SIX_LOCK_intent);
|
||||
bch2_btree_iter_node_drop(trans, iter, b);
|
||||
bch2_btree_iter_node_replace(trans, iter, n);
|
||||
bch2_btree_node_free_inmem(trans, iter, b);
|
||||
bch2_trans_node_drop(trans, b);
|
||||
bch2_trans_node_add(trans, n);
|
||||
bch2_btree_node_free_inmem(trans, b);
|
||||
six_unlock_intent(&n->c.lock);
|
||||
|
||||
bch2_btree_update_done(as);
|
||||
|
@ -56,14 +56,14 @@ inline void bch2_btree_node_lock_for_insert(struct btree_trans *trans,
|
||||
|
||||
if (unlikely(btree_node_just_written(b)) &&
|
||||
bch2_btree_post_write_cleanup(c, b))
|
||||
bch2_btree_iter_reinit_node(trans, iter, b);
|
||||
bch2_trans_node_reinit_iter(trans, b);
|
||||
|
||||
/*
|
||||
* If the last bset has been written, or if it's gotten too big - start
|
||||
* a new bset to insert into:
|
||||
*/
|
||||
if (want_new_bset(c, b))
|
||||
bch2_btree_init_next(trans, iter, b);
|
||||
bch2_btree_init_next(trans, b);
|
||||
}
|
||||
|
||||
/* Inserting into a given leaf node (last stage of insert): */
|
||||
@ -85,7 +85,6 @@ bool bch2_btree_bset_insert_key(struct btree_trans *trans,
|
||||
EBUG_ON(bpos_cmp(insert->k.p, b->data->max_key) > 0);
|
||||
EBUG_ON(insert->k.u64s >
|
||||
bch_btree_keys_u64s_remaining(trans->c, b));
|
||||
EBUG_ON(iter->flags & BTREE_ITER_IS_EXTENTS);
|
||||
|
||||
k = bch2_btree_node_iter_peek_all(node_iter, b);
|
||||
if (k && bkey_cmp_left_packed(b, k, &insert->k.p))
|
||||
@ -112,7 +111,7 @@ bool bch2_btree_bset_insert_key(struct btree_trans *trans,
|
||||
bch2_bset_delete(b, k, clobber_u64s);
|
||||
goto fix_iter;
|
||||
} else {
|
||||
bch2_btree_iter_fix_key_modified(trans, iter, b, k);
|
||||
bch2_btree_iter_fix_key_modified(trans, b, k);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -130,7 +129,7 @@ bool bch2_btree_bset_insert_key(struct btree_trans *trans,
|
||||
clobber_u64s = k->u64s;
|
||||
goto overwrite;
|
||||
} else {
|
||||
bch2_btree_iter_fix_key_modified(trans, iter, b, k);
|
||||
bch2_btree_iter_fix_key_modified(trans, b, k);
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,7 +219,7 @@ static bool btree_insert_key_leaf(struct btree_trans *trans,
|
||||
|
||||
if (u64s_added > live_u64s_added &&
|
||||
bch2_maybe_compact_whiteouts(c, b))
|
||||
bch2_btree_iter_reinit_node(trans, iter, b);
|
||||
bch2_trans_node_reinit_iter(trans, b);
|
||||
|
||||
trace_btree_insert_key(c, b, insert);
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user