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

bcachefs: Free iterator if we have duplicate

This helps - but does not fully fix - the outstanding "transaction
iterator overflow" bugs.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent f4ccfe07
...@@ -2204,6 +2204,22 @@ static inline void __bch2_trans_iter_free(struct btree_trans *trans, ...@@ -2204,6 +2204,22 @@ static inline void __bch2_trans_iter_free(struct btree_trans *trans,
btree_trans_verify_sorted_refs(trans); btree_trans_verify_sorted_refs(trans);
} }
static bool have_iter_at_pos(struct btree_trans *trans,
struct btree_iter *iter)
{
struct btree_iter *n;
n = prev_btree_iter(trans, iter);
if (n && !btree_iter_cmp(n, iter))
return true;
n = next_btree_iter(trans, iter);
if (n && !btree_iter_cmp(n, iter))
return true;
return false;
}
int bch2_trans_iter_put(struct btree_trans *trans, int bch2_trans_iter_put(struct btree_trans *trans,
struct btree_iter *iter) struct btree_iter *iter)
{ {
...@@ -2217,8 +2233,9 @@ int bch2_trans_iter_put(struct btree_trans *trans, ...@@ -2217,8 +2233,9 @@ int bch2_trans_iter_put(struct btree_trans *trans,
ret = btree_iter_err(iter); ret = btree_iter_err(iter);
if (!(trans->iters_touched & (1ULL << iter->idx)) && if (!(iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT) &&
!(iter->flags & BTREE_ITER_KEEP_UNTIL_COMMIT)) (!(trans->iters_touched & (1ULL << iter->idx)) ||
have_iter_at_pos(trans, iter)))
__bch2_trans_iter_free(trans, iter->idx); __bch2_trans_iter_free(trans, iter->idx);
trans->iters_live &= ~(1ULL << iter->idx); trans->iters_live &= ~(1ULL << iter->idx);
......
...@@ -1040,6 +1040,7 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter, ...@@ -1040,6 +1040,7 @@ int bch2_trans_update(struct btree_trans *trans, struct btree_iter *iter,
n.iter = bch2_trans_get_iter(trans, n.btree_id, n.k->k.p, n.iter = bch2_trans_get_iter(trans, n.btree_id, n.k->k.p,
BTREE_ITER_INTENT| BTREE_ITER_INTENT|
BTREE_ITER_NOT_EXTENTS); BTREE_ITER_NOT_EXTENTS);
n.iter->flags |= BTREE_ITER_KEEP_UNTIL_COMMIT;
ret = bch2_btree_iter_traverse(n.iter); ret = bch2_btree_iter_traverse(n.iter);
bch2_trans_iter_put(trans, n.iter); bch2_trans_iter_put(trans, n.iter);
......
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