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

bcachefs: Kill btree_iter->next

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent e542029e
...@@ -1604,67 +1604,8 @@ static inline void bch2_btree_iter_init(struct btree_trans *trans, ...@@ -1604,67 +1604,8 @@ static inline void bch2_btree_iter_init(struct btree_trans *trans,
prefetch(c->btree_roots[btree_id].b); prefetch(c->btree_roots[btree_id].b);
} }
static void bch2_btree_iter_unlink(struct btree_iter *iter)
{
struct btree_iter *linked;
__bch2_btree_iter_unlock(iter);
if (!btree_iter_linked(iter))
return;
trans_for_each_iter(iter->trans, linked)
if (linked->next == iter) {
linked->next = iter->next;
iter->next = iter;
return;
}
BUG();
}
static void bch2_btree_iter_link(struct btree_iter *iter, struct btree_iter *new)
{
BUG_ON(btree_iter_linked(new));
new->next = iter->next;
iter->next = new;
}
static void __bch2_btree_iter_copy(struct btree_iter *dst,
struct btree_iter *src)
{
unsigned i;
memcpy(dst, src, offsetof(struct btree_iter, next));
for (i = 0; i < BTREE_MAX_DEPTH; i++)
if (btree_node_locked(dst, i))
six_lock_increment(&dst->l[i].b->lock,
__btree_lock_want(dst, i));
}
void bch2_btree_iter_copy(struct btree_iter *dst, struct btree_iter *src)
{
__bch2_btree_iter_unlock(dst);
__bch2_btree_iter_copy(dst, src);
}
/* new transactional stuff: */ /* new transactional stuff: */
static void btree_trans_verify(struct btree_trans *trans)
{
unsigned i;
for (i = 0; i < trans->nr_iters; i++) {
struct btree_iter *iter = &trans->iters[i];
BUG_ON(btree_iter_linked(iter) !=
((trans->iters_linked & (1 << i)) &&
!is_power_of_2(trans->iters_linked)));
}
}
static inline unsigned btree_trans_iter_idx(struct btree_trans *trans, static inline unsigned btree_trans_iter_idx(struct btree_trans *trans,
struct btree_iter *iter) struct btree_iter *iter)
{ {
...@@ -1689,12 +1630,12 @@ int bch2_trans_iter_put(struct btree_trans *trans, ...@@ -1689,12 +1630,12 @@ int bch2_trans_iter_put(struct btree_trans *trans,
static inline void __bch2_trans_iter_free(struct btree_trans *trans, static inline void __bch2_trans_iter_free(struct btree_trans *trans,
unsigned idx) unsigned idx)
{ {
__bch2_btree_iter_unlock(&trans->iters[idx]);
trans->iters_linked &= ~(1ULL << idx); trans->iters_linked &= ~(1ULL << idx);
trans->iters_live &= ~(1ULL << idx); trans->iters_live &= ~(1ULL << idx);
trans->iters_touched &= ~(1ULL << idx); trans->iters_touched &= ~(1ULL << idx);
trans->iters_unlink_on_restart &= ~(1ULL << idx); trans->iters_unlink_on_restart &= ~(1ULL << idx);
trans->iters_unlink_on_commit &= ~(1ULL << idx); trans->iters_unlink_on_commit &= ~(1ULL << idx);
bch2_btree_iter_unlink(&trans->iters[idx]);
} }
int bch2_trans_iter_free(struct btree_trans *trans, int bch2_trans_iter_free(struct btree_trans *trans,
...@@ -1720,7 +1661,6 @@ static int btree_trans_realloc_iters(struct btree_trans *trans, ...@@ -1720,7 +1661,6 @@ static int btree_trans_realloc_iters(struct btree_trans *trans,
unsigned new_size) unsigned new_size)
{ {
void *new_iters, *new_updates; void *new_iters, *new_updates;
unsigned i;
BUG_ON(new_size > BTREE_ITER_MAX); BUG_ON(new_size > BTREE_ITER_MAX);
...@@ -1761,20 +1701,6 @@ static int btree_trans_realloc_iters(struct btree_trans *trans, ...@@ -1761,20 +1701,6 @@ static int btree_trans_realloc_iters(struct btree_trans *trans,
trans->updates = new_updates; trans->updates = new_updates;
trans->size = new_size; trans->size = new_size;
for (i = 0; i < trans->nr_iters; i++)
trans->iters[i].next = &trans->iters[i];
if (trans->iters_linked) {
unsigned first_linked = __ffs(trans->iters_linked);
for (i = first_linked + 1; i < trans->nr_iters; i++)
if (trans->iters_linked & (1 << i))
bch2_btree_iter_link(&trans->iters[first_linked],
&trans->iters[i]);
}
btree_trans_verify(trans);
if (trans->iters_live) { if (trans->iters_live) {
trans_restart(); trans_restart();
return -EINTR; return -EINTR;
...@@ -1790,7 +1716,6 @@ void bch2_trans_preload_iters(struct btree_trans *trans) ...@@ -1790,7 +1716,6 @@ void bch2_trans_preload_iters(struct btree_trans *trans)
static int btree_trans_iter_alloc(struct btree_trans *trans) static int btree_trans_iter_alloc(struct btree_trans *trans)
{ {
struct btree_iter *iter;
unsigned idx = ffz(trans->iters_linked); unsigned idx = ffz(trans->iters_linked);
if (idx < trans->nr_iters) if (idx < trans->nr_iters)
...@@ -1805,14 +1730,7 @@ static int btree_trans_iter_alloc(struct btree_trans *trans) ...@@ -1805,14 +1730,7 @@ static int btree_trans_iter_alloc(struct btree_trans *trans)
idx = trans->nr_iters++; idx = trans->nr_iters++;
BUG_ON(trans->nr_iters > trans->size); BUG_ON(trans->nr_iters > trans->size);
got_slot: got_slot:
iter = &trans->iters[idx];
iter->next = iter;
BUG_ON(trans->iters_linked & (1ULL << idx)); BUG_ON(trans->iters_linked & (1ULL << idx));
if (trans->iters_linked)
bch2_btree_iter_link(&trans->iters[__ffs(trans->iters_linked)],
&trans->iters[idx]);
trans->iters_linked |= 1ULL << idx; trans->iters_linked |= 1ULL << idx;
return idx; return idx;
} }
...@@ -1860,8 +1778,6 @@ static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans, ...@@ -1860,8 +1778,6 @@ static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans,
trans->iters_live |= 1ULL << idx; trans->iters_live |= 1ULL << idx;
trans->iters_touched |= 1ULL << idx; trans->iters_touched |= 1ULL << idx;
btree_trans_verify(trans);
BUG_ON(iter->btree_id != btree_id); BUG_ON(iter->btree_id != btree_id);
BUG_ON((iter->flags ^ flags) & BTREE_ITER_TYPE); BUG_ON((iter->flags ^ flags) & BTREE_ITER_TYPE);
...@@ -1909,7 +1825,8 @@ struct btree_iter *bch2_trans_get_node_iter(struct btree_trans *trans, ...@@ -1909,7 +1825,8 @@ struct btree_iter *bch2_trans_get_node_iter(struct btree_trans *trans,
struct btree_iter *bch2_trans_copy_iter(struct btree_trans *trans, struct btree_iter *bch2_trans_copy_iter(struct btree_trans *trans,
struct btree_iter *src) struct btree_iter *src)
{ {
int idx; struct btree_iter *iter;
int i, idx;
idx = btree_trans_iter_alloc(trans); idx = btree_trans_iter_alloc(trans);
if (idx < 0) if (idx < 0)
...@@ -1919,7 +1836,13 @@ struct btree_iter *bch2_trans_copy_iter(struct btree_trans *trans, ...@@ -1919,7 +1836,13 @@ struct btree_iter *bch2_trans_copy_iter(struct btree_trans *trans,
trans->iters_touched |= 1ULL << idx; trans->iters_touched |= 1ULL << idx;
trans->iters_unlink_on_restart |= 1ULL << idx; trans->iters_unlink_on_restart |= 1ULL << idx;
__bch2_btree_iter_copy(&trans->iters[idx], src); iter = &trans->iters[idx];
*iter = *src;
for (i = 0; i < BTREE_MAX_DEPTH; i++)
if (btree_node_locked(iter, i))
six_lock_increment(&iter->l[i].b->lock,
__btree_lock_want(iter, i));
return &trans->iters[idx]; return &trans->iters[idx];
} }
...@@ -1985,8 +1908,6 @@ void __bch2_trans_begin(struct btree_trans *trans) ...@@ -1985,8 +1908,6 @@ void __bch2_trans_begin(struct btree_trans *trans)
{ {
u64 iters_to_unlink; u64 iters_to_unlink;
btree_trans_verify(trans);
/* /*
* On transaction restart, the transaction isn't required to allocate * On transaction restart, the transaction isn't required to allocate
* all the same iterators it on the last iteration: * all the same iterators it on the last iteration:
...@@ -2009,8 +1930,6 @@ void __bch2_trans_begin(struct btree_trans *trans) ...@@ -2009,8 +1930,6 @@ void __bch2_trans_begin(struct btree_trans *trans)
trans->iters_unlink_on_commit = 0; trans->iters_unlink_on_commit = 0;
trans->nr_updates = 0; trans->nr_updates = 0;
trans->mem_top = 0; trans->mem_top = 0;
btree_trans_verify(trans);
} }
void bch2_trans_init(struct btree_trans *trans, struct bch_fs *c) void bch2_trans_init(struct btree_trans *trans, struct bch_fs *c)
......
...@@ -28,11 +28,6 @@ static inline bool btree_trans_has_multiple_iters(const struct btree_trans *tran ...@@ -28,11 +28,6 @@ static inline bool btree_trans_has_multiple_iters(const struct btree_trans *tran
return hweight64(trans->iters_linked) > 1; return hweight64(trans->iters_linked) > 1;
} }
static inline bool btree_iter_linked(const struct btree_iter *iter)
{
return iter->next != iter;
}
static inline int btree_iter_err(const struct btree_iter *iter) static inline int btree_iter_err(const struct btree_iter *iter)
{ {
return iter->flags & BTREE_ITER_ERROR ? -EIO : 0; return iter->flags & BTREE_ITER_ERROR ? -EIO : 0;
...@@ -165,8 +160,6 @@ struct bkey_s_c bch2_btree_iter_next_slot(struct btree_iter *); ...@@ -165,8 +160,6 @@ struct bkey_s_c bch2_btree_iter_next_slot(struct btree_iter *);
void bch2_btree_iter_set_pos_same_leaf(struct btree_iter *, struct bpos); void bch2_btree_iter_set_pos_same_leaf(struct btree_iter *, struct bpos);
void bch2_btree_iter_set_pos(struct btree_iter *, struct bpos); void bch2_btree_iter_set_pos(struct btree_iter *, struct bpos);
void bch2_btree_iter_copy(struct btree_iter *, struct btree_iter *);
static inline struct bpos btree_type_successor(enum btree_id id, static inline struct bpos btree_type_successor(enum btree_id id,
struct bpos pos) struct bpos pos)
{ {
......
...@@ -234,15 +234,6 @@ struct btree_iter { ...@@ -234,15 +234,6 @@ struct btree_iter {
struct bkey k; struct bkey k;
u64 id; u64 id;
/*
* Circular linked list of linked iterators: linked iterators share
* locks (e.g. two linked iterators may have the same node intent
* locked, or read and write locked, at the same time), and insertions
* through one iterator won't invalidate the other linked iterators.
*/
/* Must come last: */
struct btree_iter *next;
}; };
struct deferred_update { struct deferred_update {
......
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