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;
}
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);
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;
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);
*/
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;
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:
* 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;