#include <linux/random.h>
+static void bch2_btree_insert_node(struct btree_update *, struct btree_trans *,
+ struct btree_iter *, struct btree *,
+ struct keylist *, unsigned);
+
/* Debug code: */
/*
btree_node_interior_verify(as->c, b);
}
-static void btree_split(struct btree_update *as, struct btree *b,
- struct btree_iter *iter, struct keylist *keys,
+static void btree_split(struct btree_update *as,
+ struct btree_trans *trans, struct btree_iter *iter,
+ struct btree *b, struct keylist *keys,
unsigned flags)
{
struct bch_fs *c = as->c;
if (parent) {
/* Split a non root node */
- bch2_btree_insert_node(as, parent, iter, &as->parent_keys, flags);
+ bch2_btree_insert_node(as, trans, iter, parent, &as->parent_keys, flags);
} else if (n3) {
bch2_btree_set_root(as, n3, iter);
} else {
six_unlock_intent(&n2->c.lock);
six_unlock_intent(&n1->c.lock);
- bch2_btree_trans_verify_locks(iter->trans);
+ bch2_btree_trans_verify_locks(trans);
bch2_time_stats_update(&c->times[BCH_TIME_btree_node_split],
start_time);
* If a split occurred, this function will return early. This can only happen
* for leaf nodes -- inserts into interior nodes have to be atomic.
*/
-void bch2_btree_insert_node(struct btree_update *as, struct btree *b,
- struct btree_iter *iter, struct keylist *keys,
- unsigned flags)
+static void bch2_btree_insert_node(struct btree_update *as,
+ struct btree_trans *trans, struct btree_iter *iter,
+ struct btree *b, struct keylist *keys,
+ unsigned flags)
{
struct bch_fs *c = as->c;
int old_u64s = le16_to_cpu(btree_bset_last(b)->u64s);
BUG_ON(!as || as->b);
bch2_verify_keylist_sorted(keys);
- bch2_btree_node_lock_for_insert(c, b, iter);
+ bch2_btree_node_lock_for_insert(trans, iter, b);
if (!bch2_btree_node_insert_fits(c, b, bch2_keylist_u64s(keys))) {
bch2_btree_node_unlock_write(b, iter);
btree_node_interior_verify(c, b);
return;
split:
- btree_split(as, b, iter, keys, flags);
+ btree_split(as, trans, iter, b, keys, flags);
}
-int bch2_btree_split_leaf(struct bch_fs *c, struct btree_iter *iter,
+int bch2_btree_split_leaf(struct btree_trans *trans,
+ struct btree_iter *iter,
unsigned flags)
{
+ struct bch_fs *c = trans->c;
struct btree *b = iter_l(iter)->b;
struct btree_update *as;
unsigned l;
if (IS_ERR(as))
return PTR_ERR(as);
- btree_split(as, b, iter, NULL, flags);
+ btree_split(as, trans, iter, b, NULL, flags);
bch2_btree_update_done(as);
for (l = iter->level + 1; btree_iter_node(iter, l) && !ret; l++)
- ret = bch2_foreground_maybe_merge(c, iter, l, flags);
+ ret = bch2_foreground_maybe_merge(trans, iter, l, flags);
return ret;
}
-int __bch2_foreground_maybe_merge(struct bch_fs *c,
+int __bch2_foreground_maybe_merge(struct btree_trans *trans,
struct btree_iter *iter,
unsigned level,
unsigned flags,
enum btree_node_sibling sib)
{
- struct btree_trans *trans = iter->trans;
+ struct bch_fs *c = trans->c;
struct btree_iter *sib_iter = NULL;
struct btree_update *as;
struct bkey_format_state new_s;
bch2_btree_node_write(c, n, SIX_LOCK_intent);
- bch2_btree_insert_node(as, parent, iter, &as->parent_keys, flags);
+ bch2_btree_insert_node(as, trans, iter, parent, &as->parent_keys, flags);
bch2_btree_update_get_open_buckets(as, n);
/**
* bch_btree_node_rewrite - Rewrite/move a btree node
*/
-int bch2_btree_node_rewrite(struct bch_fs *c, struct btree_iter *iter,
+int bch2_btree_node_rewrite(struct btree_trans *trans,
+ struct btree_iter *iter,
__le64 seq, unsigned flags)
{
+ struct bch_fs *c = trans->c;
struct btree *b, *n, *parent;
struct btree_update *as;
int ret;
if (parent) {
bch2_keylist_add(&as->parent_keys, &n->key);
- bch2_btree_insert_node(as, parent, iter, &as->parent_keys, flags);
+ bch2_btree_insert_node(as, trans, iter, parent,
+ &as->parent_keys, flags);
} else {
bch2_btree_set_root(as, n, iter);
}
bch2_trans_init(&trans, c, 0, 0);
iter = bch2_trans_get_node_iter(&trans, a->btree_id, a->pos,
BTREE_MAX_DEPTH, a->level, 0);
- bch2_btree_node_rewrite(c, iter, a->seq, 0);
+ bch2_btree_node_rewrite(&trans, iter, a->seq, 0);
bch2_trans_iter_put(&trans, iter);
bch2_trans_exit(&trans);
percpu_ref_put(&c->writes);
queue_work(c->btree_interior_update_worker, &a->work);
}
-static void __bch2_btree_node_update_key(struct bch_fs *c,
- struct btree_update *as,
+static void __bch2_btree_node_update_key(struct btree_update *as,
+ struct btree_trans *trans,
struct btree_iter *iter,
struct btree *b, struct btree *new_hash,
struct bkey_i *new_key)
{
+ struct bch_fs *c = as->c;
struct btree *parent;
int ret;
}
bch2_keylist_add(&as->parent_keys, new_key);
- bch2_btree_insert_node(as, parent, iter, &as->parent_keys, 0);
+ bch2_btree_insert_node(as, trans, iter, parent, &as->parent_keys, 0);
if (new_hash) {
mutex_lock(&c->btree_cache.lock);
bch2_btree_update_done(as);
}
-int bch2_btree_node_update_key(struct bch_fs *c, struct btree_iter *iter,
+int bch2_btree_node_update_key(struct btree_trans *trans,
+ struct btree_iter *iter,
struct btree *b,
struct bkey_i *new_key)
{
+ struct bch_fs *c = trans->c;
struct btree *parent = btree_node_parent(iter, b);
struct btree_update *as = NULL;
struct btree *new_hash = NULL;
goto err;
}
- __bch2_btree_node_update_key(c, as, iter, b, new_hash, new_key);
+ __bch2_btree_node_update_key(as, trans, iter, b, new_hash, new_key);
bch2_btree_iter_downgrade(iter);
err:
struct btree *);
void bch2_btree_update_add_new_node(struct btree_update *, struct btree *);
-void bch2_btree_insert_node(struct btree_update *, struct btree *,
- struct btree_iter *, struct keylist *,
- unsigned);
-int bch2_btree_split_leaf(struct bch_fs *, struct btree_iter *, unsigned);
+int bch2_btree_split_leaf(struct btree_trans *, struct btree_iter *, unsigned);
-int __bch2_foreground_maybe_merge(struct bch_fs *, struct btree_iter *,
+int __bch2_foreground_maybe_merge(struct btree_trans *, struct btree_iter *,
unsigned, unsigned, enum btree_node_sibling);
-static inline int bch2_foreground_maybe_merge_sibling(struct bch_fs *c,
+static inline int bch2_foreground_maybe_merge_sibling(struct btree_trans *trans,
struct btree_iter *iter,
unsigned level, unsigned flags,
enum btree_node_sibling sib)
return 0;
b = iter->l[level].b;
- if (b->sib_u64s[sib] > c->btree_foreground_merge_threshold)
+ if (b->sib_u64s[sib] > trans->c->btree_foreground_merge_threshold)
return 0;
- return __bch2_foreground_maybe_merge(c, iter, level, flags, sib);
+ return __bch2_foreground_maybe_merge(trans, iter, level, flags, sib);
}
-static inline int bch2_foreground_maybe_merge(struct bch_fs *c,
- struct btree_iter *iter,
- unsigned level,
- unsigned flags)
+static inline int bch2_foreground_maybe_merge(struct btree_trans *trans,
+ struct btree_iter *iter,
+ unsigned level,
+ unsigned flags)
{
- return bch2_foreground_maybe_merge_sibling(c, iter, level, flags,
+ return bch2_foreground_maybe_merge_sibling(trans, iter, level, flags,
btree_prev_sib) ?:
- bch2_foreground_maybe_merge_sibling(c, iter, level, flags,
+ bch2_foreground_maybe_merge_sibling(trans, iter, level, flags,
btree_next_sib);
}
iter_l(i[0].iter)->b == iter_l(i[-1].iter)->b;
}
-inline void bch2_btree_node_lock_for_insert(struct bch_fs *c, struct btree *b,
- struct btree_iter *iter)
+inline void bch2_btree_node_lock_for_insert(struct btree_trans *trans,
+ struct btree_iter *iter,
+ struct btree *b)
{
+ struct bch_fs *c = trans->c;
+
bch2_btree_node_lock_write(b, iter);
if (btree_iter_type(iter) == BTREE_ITER_CACHED)
* a new bset to insert into:
*/
if (want_new_bset(c, b))
- bch2_btree_init_next(c, b, iter);
+ bch2_btree_init_next(trans, iter, b);
}
/* Inserting into a given leaf node (last stage of insert): */
}
return u64s_delta <= 0
- ? (bch2_foreground_maybe_merge(trans->c, iter, iter->level,
+ ? (bch2_foreground_maybe_merge(trans, iter, iter->level,
trans->flags & ~BTREE_INSERT_NOUNLOCK) ?: -EINTR)
: 0;
}
trans_for_each_update(trans, i)
if (!same_leaf_as_prev(trans, i))
- bch2_btree_node_lock_for_insert(c,
- iter_l(i->iter)->b, i->iter);
+ bch2_btree_node_lock_for_insert(trans, i->iter,
+ iter_l(i->iter)->b);
ret = bch2_trans_commit_write_locked(trans, stopped_at, trace_ip);
switch (ret) {
case BTREE_INSERT_BTREE_NODE_FULL:
- ret = bch2_btree_split_leaf(c, i->iter, flags);
+ ret = bch2_btree_split_leaf(trans, i->iter, flags);
/*
* if the split succeeded without dropping locks the insert will