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

bcachefs: Add iter->idx

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent ecc892e4
......@@ -1606,24 +1606,12 @@ static inline void bch2_btree_iter_init(struct btree_trans *trans,
/* new transactional stuff: */
static inline unsigned btree_trans_iter_idx(struct btree_trans *trans,
struct btree_iter *iter)
{
ssize_t idx = iter - trans->iters;
EBUG_ON(idx < 0 || idx >= trans->nr_iters);
EBUG_ON(!(trans->iters_linked & (1ULL << idx)));
return idx;
}
int bch2_trans_iter_put(struct btree_trans *trans,
struct btree_iter *iter)
{
ssize_t idx = btree_trans_iter_idx(trans, iter);
int ret = btree_iter_err(iter);
trans->iters_live &= ~(1ULL << idx);
trans->iters_live &= ~(1ULL << iter->idx);
return ret;
}
......@@ -1643,7 +1631,7 @@ int bch2_trans_iter_free(struct btree_trans *trans,
{
int ret = btree_iter_err(iter);
__bch2_trans_iter_free(trans, btree_trans_iter_idx(trans, iter));
__bch2_trans_iter_free(trans, iter->idx);
return ret;
}
......@@ -1652,8 +1640,7 @@ int bch2_trans_iter_free_on_commit(struct btree_trans *trans,
{
int ret = btree_iter_err(iter);
trans->iters_unlink_on_commit |=
1ULL << btree_trans_iter_idx(trans, iter);
trans->iters_unlink_on_commit |= 1ULL << iter->idx;
return ret;
}
......@@ -1729,6 +1716,8 @@ static int btree_trans_iter_alloc(struct btree_trans *trans)
idx = trans->nr_iters++;
BUG_ON(trans->nr_iters > trans->size);
trans->iters[idx].idx = idx;
got_slot:
BUG_ON(trans->iters_linked & (1ULL << idx));
trans->iters_linked |= 1ULL << idx;
......@@ -1826,6 +1815,7 @@ struct btree_iter *bch2_trans_copy_iter(struct btree_trans *trans,
struct btree_iter *src)
{
struct btree_iter *iter;
unsigned offset = offsetof(struct btree_iter, trans);
int i, idx;
idx = btree_trans_iter_alloc(trans);
......@@ -1837,7 +1827,10 @@ struct btree_iter *bch2_trans_copy_iter(struct btree_trans *trans,
trans->iters_unlink_on_restart |= 1ULL << idx;
iter = &trans->iters[idx];
*iter = *src;
memcpy((void *) iter + offset,
(void *) src + offset,
sizeof(*iter) - offset);
for (i = 0; i < BTREE_MAX_DEPTH; i++)
if (btree_node_locked(iter, i))
......
......@@ -36,15 +36,11 @@ static inline int btree_iter_err(const struct btree_iter *iter)
/* Iterate over iters within a transaction: */
static inline struct btree_iter *
__trans_next_iter(struct btree_trans *trans, struct btree_iter *iter)
__trans_next_iter(struct btree_trans *trans, unsigned idx)
{
unsigned idx;
EBUG_ON(idx < trans->nr_iters && trans->iters[idx].idx != idx);
/* XXX expensive pointer subtraction: */
for (idx = iter - trans->iters;
idx < trans->nr_iters;
idx++)
for (; idx < trans->nr_iters; idx++)
if (trans->iters_linked & (1ULL << idx))
return &trans->iters[idx];
......@@ -52,9 +48,9 @@ __trans_next_iter(struct btree_trans *trans, struct btree_iter *iter)
}
#define trans_for_each_iter(_trans, _iter) \
for (_iter = (_trans)->iters; \
(_iter = __trans_next_iter((_trans), _iter)); \
_iter++)
for (_iter = __trans_next_iter((_trans), 0); \
(_iter); \
_iter = __trans_next_iter((_trans), (_iter)->idx + 1))
static inline bool __iter_has_node(const struct btree_iter *iter,
const struct btree *b)
......@@ -73,30 +69,23 @@ static inline bool __iter_has_node(const struct btree_iter *iter,
static inline struct btree_iter *
__trans_next_iter_with_node(struct btree_trans *trans, struct btree *b,
struct btree_iter *iter)
unsigned idx)
{
unsigned idx;
/* XXX expensive pointer subtraction: */
for (idx = iter - trans->iters;
idx < trans->nr_iters;
idx++) {
if (!(trans->iters_linked & (1ULL << idx)))
continue;
EBUG_ON(idx < trans->nr_iters && trans->iters[idx].idx != idx);
iter = &trans->iters[idx];
if (__iter_has_node(iter, b))
return iter;
}
for (; idx < trans->nr_iters; idx++)
if ((trans->iters_linked & (1ULL << idx)) &&
__iter_has_node(&trans->iters[idx], b))
return &trans->iters[idx];
return NULL;
}
#define trans_for_each_iter_with_node(_trans, _b, _iter) \
for (_iter = (_trans)->iters; \
(_iter = __trans_next_iter_with_node((_trans), (_b), _iter));\
_iter++)
for (_iter = __trans_next_iter_with_node((_trans), (_b), 0); \
(_iter); \
_iter = __trans_next_iter_with_node((_trans), (_b), \
(_iter)->idx + 1))
#ifdef CONFIG_BCACHEFS_DEBUG
void bch2_btree_iter_verify(struct btree_iter *, struct btree *);
......
......@@ -210,6 +210,8 @@ enum btree_iter_uptodate {
* @nodes_intent_locked - bitmask indicating which locks are intent locks
*/
struct btree_iter {
u8 idx;
struct btree_trans *trans;
struct bpos pos;
......
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