Commit 955af634 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: __bch2_trans_commit() no longer calls bch2_trans_reset()

It's now the caller's responsibility to call bch2_trans_begin.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent e829b717
......@@ -2382,22 +2382,14 @@ inline void bch2_trans_unlink_iters(struct btree_trans *trans)
}
/**
* bch2_trans_reset() - reset a transaction after a interrupted attempt
* bch2_trans_begin() - reset a transaction after a interrupted attempt
* @trans: transaction to reset
* @flags: transaction reset flags.
*
* While iterating over nodes or updating nodes a attempt to lock a btree
* node may return EINTR when the trylock fails. When this occurs
* bch2_trans_reset() or bch2_trans_begin() should be called and the
* transaction retried.
*
* Transaction reset flags include:
*
* - TRANS_RESET_NOUNLOCK - Do not attempt to unlock and reschedule the
* transaction.
* - TRANS_RESET_NOTRAVERSE - Do not traverse all linked iters.
* bch2_trans_begin() should be called and the transaction retried.
*/
void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
void bch2_trans_begin(struct btree_trans *trans)
{
struct btree_iter *iter;
......@@ -2405,8 +2397,11 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
iter->flags &= ~(BTREE_ITER_KEEP_UNTIL_COMMIT|
BTREE_ITER_SET_POS_AFTER_COMMIT);
/*
* XXX: we shouldn't be doing this if the transaction was restarted, but
* currently we still overflow transaction iterators if we do that
* */
bch2_trans_unlink_iters(trans);
trans->iters_touched &= trans->iters_live;
trans->extra_journal_res = 0;
......@@ -2425,11 +2420,9 @@ void bch2_trans_reset(struct btree_trans *trans, unsigned flags)
(void *) &trans->fs_usage_deltas->memset_start);
}
if (!(flags & TRANS_RESET_NOUNLOCK))
bch2_trans_cond_resched(trans);
bch2_trans_cond_resched(trans);
if (!(flags & TRANS_RESET_NOTRAVERSE) &&
trans->iters_linked)
if (trans->restarted)
bch2_btree_iter_traverse_all(trans);
trans->restarted = false;
......
......@@ -323,22 +323,7 @@ static inline void set_btree_iter_dontneed(struct btree_trans *trans, struct btr
trans->iters_touched &= ~(1ULL << iter->idx);
}
#define TRANS_RESET_NOTRAVERSE (1 << 0)
#define TRANS_RESET_NOUNLOCK (1 << 1)
void bch2_trans_reset(struct btree_trans *, unsigned);
/**
* bch2_trans_begin() - ensure lock consistency of transaction on retry
* @trans: transaction to prepare
*
* Ensure lock ordering is correct before potentially retrying a transaction
* after a failed trylock.
*/
static inline void bch2_trans_begin(struct btree_trans *trans)
{
return bch2_trans_reset(trans, 0);
}
void bch2_trans_begin(struct btree_trans *);
void *bch2_trans_kmalloc(struct btree_trans *, size_t);
void bch2_trans_init(struct btree_trans *, struct bch_fs *, unsigned, size_t);
......
......@@ -923,7 +923,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
struct btree_insert_entry *i = NULL;
struct btree_iter *iter;
bool trans_trigger_run;
unsigned u64s, reset_flags = 0;
unsigned u64s;
int ret = 0;
if (!trans->nr_updates &&
......@@ -1030,11 +1030,19 @@ int __bch2_trans_commit(struct btree_trans *trans)
if (likely(!(trans->flags & BTREE_INSERT_NOCHECK_RW)))
percpu_ref_put(&trans->c->writes);
out_reset:
if (!ret)
reset_flags |= TRANS_RESET_NOTRAVERSE;
if (!ret && (trans->flags & BTREE_INSERT_NOUNLOCK))
reset_flags |= TRANS_RESET_NOUNLOCK;
bch2_trans_reset(trans, reset_flags);
trans->extra_journal_res = 0;
trans->nr_updates = 0;
trans->hooks = NULL;
trans->extra_journal_entries = NULL;
trans->extra_journal_entry_u64s = 0;
if (trans->fs_usage_deltas) {
trans->fs_usage_deltas->used = 0;
memset((void *) trans->fs_usage_deltas +
offsetof(struct replicas_delta_list, memset_start), 0,
(void *) &trans->fs_usage_deltas->memset_end -
(void *) &trans->fs_usage_deltas->memset_start);
}
return ret;
err:
......
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