mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
bcachefs: btree_iter_live()
New helper to clean things up a bit - also, improve iter->flags handling. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
6333bd2f13
commit
1f7fdc0abd
@ -1701,7 +1701,8 @@ struct bkey_s_c bch2_btree_iter_peek_with_updates(struct btree_iter *iter)
|
||||
k = __bch2_btree_iter_peek_with_updates(iter);
|
||||
|
||||
if (k.k && bkey_deleted(k.k)) {
|
||||
bch2_btree_iter_advance_pos(iter);
|
||||
if (!bch2_btree_iter_advance_pos(iter))
|
||||
return bkey_s_c_null;
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -2008,7 +2009,7 @@ static void btree_trans_iter_alloc_fail(struct btree_trans *trans)
|
||||
bch2_btree_ids[iter->btree_id],
|
||||
iter->pos.inode,
|
||||
iter->pos.offset,
|
||||
(trans->iters_live & (1ULL << iter->idx)) ? " live" : "",
|
||||
btree_iter_live(trans, iter) ? " live" : "",
|
||||
(trans->iters_touched & (1ULL << iter->idx)) ? " touched" : "",
|
||||
iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT ? " keep" : "",
|
||||
(void *) iter->ip_allocated);
|
||||
@ -2089,31 +2090,20 @@ static struct btree_iter *__btree_trans_get_iter(struct btree_trans *trans,
|
||||
if (!best) {
|
||||
iter = btree_trans_iter_alloc(trans);
|
||||
bch2_btree_iter_init(trans, iter, btree_id, pos, flags);
|
||||
} else if ((trans->iters_live & (1ULL << best->idx)) ||
|
||||
(best->flags & BTREE_ITER_KEEP_UNTIL_COMMIT)) {
|
||||
} else if (btree_iter_keep(trans, best)) {
|
||||
iter = btree_trans_iter_alloc(trans);
|
||||
btree_iter_copy(iter, best);
|
||||
} else {
|
||||
iter = best;
|
||||
}
|
||||
|
||||
iter->flags &= ~BTREE_ITER_KEEP_UNTIL_COMMIT;
|
||||
iter->flags &= ~BTREE_ITER_USER_FLAGS;
|
||||
iter->flags |= flags & BTREE_ITER_USER_FLAGS;
|
||||
flags |= iter->flags & BTREE_ITER_ERROR;
|
||||
iter->flags = flags;
|
||||
|
||||
if (iter->flags & BTREE_ITER_INTENT) {
|
||||
if (!iter->locks_want) {
|
||||
__bch2_btree_iter_unlock(iter);
|
||||
iter->locks_want = 1;
|
||||
}
|
||||
} else
|
||||
if (!(iter->flags & BTREE_ITER_INTENT))
|
||||
bch2_btree_iter_downgrade(iter);
|
||||
|
||||
BUG_ON(iter->btree_id != btree_id);
|
||||
BUG_ON((iter->flags ^ flags) & BTREE_ITER_TYPE);
|
||||
BUG_ON(iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT);
|
||||
BUG_ON(iter->flags & BTREE_ITER_SET_POS_AFTER_COMMIT);
|
||||
BUG_ON(trans->iters_live & (1ULL << iter->idx));
|
||||
else if (!iter->locks_want)
|
||||
__bch2_btree_iter_upgrade_nounlock(iter, 1);
|
||||
|
||||
trans->iters_live |= 1ULL << iter->idx;
|
||||
trans->iters_touched |= 1ULL << iter->idx;
|
||||
|
@ -289,6 +289,17 @@ struct btree_iter *bch2_trans_get_node_iter(struct btree_trans *,
|
||||
enum btree_id, struct bpos,
|
||||
unsigned, unsigned, unsigned);
|
||||
|
||||
static inline bool btree_iter_live(struct btree_trans *trans, struct btree_iter *iter)
|
||||
{
|
||||
return (trans->iters_live & (1ULL << iter->idx)) != 0;
|
||||
}
|
||||
|
||||
static inline bool btree_iter_keep(struct btree_trans *trans, struct btree_iter *iter)
|
||||
{
|
||||
return btree_iter_live(trans, iter) ||
|
||||
(iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT);
|
||||
}
|
||||
|
||||
#define TRANS_RESET_NOTRAVERSE (1 << 0)
|
||||
|
||||
void bch2_trans_reset(struct btree_trans *, unsigned);
|
||||
|
@ -216,13 +216,6 @@ enum btree_iter_type {
|
||||
#define BTREE_ITER_CACHED_NOFILL (1 << 9)
|
||||
#define BTREE_ITER_CACHED_NOCREATE (1 << 10)
|
||||
|
||||
#define BTREE_ITER_USER_FLAGS \
|
||||
(BTREE_ITER_SLOTS \
|
||||
|BTREE_ITER_INTENT \
|
||||
|BTREE_ITER_PREFETCH \
|
||||
|BTREE_ITER_CACHED_NOFILL \
|
||||
|BTREE_ITER_CACHED_NOCREATE)
|
||||
|
||||
enum btree_iter_uptodate {
|
||||
BTREE_ITER_UPTODATE = 0,
|
||||
BTREE_ITER_NEED_PEEK = 1,
|
||||
|
@ -512,8 +512,7 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans,
|
||||
*/
|
||||
trans_for_each_iter(trans, iter) {
|
||||
if (iter->nodes_locked != iter->nodes_intent_locked) {
|
||||
if ((iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT) ||
|
||||
(trans->iters_live & (1ULL << iter->idx))) {
|
||||
if (btree_iter_keep(trans, iter)) {
|
||||
if (!bch2_btree_iter_upgrade(iter, 1)) {
|
||||
trace_trans_restart_upgrade(trans->ip);
|
||||
return -EINTR;
|
||||
@ -945,7 +944,7 @@ retry:
|
||||
goto err;
|
||||
|
||||
trans_for_each_iter(trans, iter)
|
||||
if ((trans->iters_live & (1ULL << iter->idx)) &&
|
||||
if (btree_iter_live(trans, iter) &&
|
||||
(iter->flags & BTREE_ITER_SET_POS_AFTER_COMMIT))
|
||||
bch2_btree_iter_set_pos(iter, iter->pos_after_commit);
|
||||
out:
|
||||
@ -1049,7 +1048,7 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
|
||||
* the iterator pos if some other code is using it, so we may
|
||||
* need to clone it:
|
||||
*/
|
||||
if (trans->iters_live & (1ULL << i->iter->idx)) {
|
||||
if (btree_iter_live(trans, i->iter)) {
|
||||
i->iter = bch2_trans_copy_iter(trans, i->iter);
|
||||
|
||||
i->iter->flags |= BTREE_ITER_KEEP_UNTIL_COMMIT;
|
||||
|
Loading…
Reference in New Issue
Block a user