Commit 923ed0ae authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_trans_relock_fail() - factor out slowpath

Factor out slowpath into a separate helper
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 0c0cbfdb
...@@ -723,35 +723,36 @@ void bch2_trans_downgrade(struct btree_trans *trans) ...@@ -723,35 +723,36 @@ void bch2_trans_downgrade(struct btree_trans *trans)
bch2_btree_path_downgrade(trans, path); bch2_btree_path_downgrade(trans, path);
} }
int bch2_trans_relock(struct btree_trans *trans) static inline void __bch2_trans_unlock(struct btree_trans *trans)
{ {
struct btree_path *path; struct btree_path *path;
unsigned i; unsigned i;
if (unlikely(trans->restarted)) trans_for_each_path(trans, path, i)
return -((int) trans->restarted); __bch2_btree_path_unlock(trans, path);
}
trans_for_each_path(trans, path, i) { static noinline __cold int bch2_trans_relock_fail(struct btree_trans *trans, struct btree_path *path,
struct get_locks_fail f; struct get_locks_fail *f, bool trace)
{
if (!trace)
goto out;
if (path->should_be_locked &&
!btree_path_get_locks(trans, path, false, &f)) {
if (trace_trans_restart_relock_enabled()) { if (trace_trans_restart_relock_enabled()) {
struct printbuf buf = PRINTBUF; struct printbuf buf = PRINTBUF;
bch2_bpos_to_text(&buf, path->pos); bch2_bpos_to_text(&buf, path->pos);
prt_printf(&buf, " l=%u seq=%u node seq=", prt_printf(&buf, " l=%u seq=%u node seq=", f->l, path->l[f->l].lock_seq);
f.l, path->l[f.l].lock_seq); if (IS_ERR_OR_NULL(f->b)) {
if (IS_ERR_OR_NULL(f.b)) { prt_str(&buf, bch2_err_str(PTR_ERR(f->b)));
prt_str(&buf, bch2_err_str(PTR_ERR(f.b)));
} else { } else {
prt_printf(&buf, "%u", f.b->c.lock.seq); prt_printf(&buf, "%u", f->b->c.lock.seq);
struct six_lock_count c = struct six_lock_count c =
bch2_btree_node_lock_counts(trans, NULL, &f.b->c, f.l); bch2_btree_node_lock_counts(trans, NULL, &f->b->c, f->l);
prt_printf(&buf, " self locked %u.%u.%u", c.n[0], c.n[1], c.n[2]); prt_printf(&buf, " self locked %u.%u.%u", c.n[0], c.n[1], c.n[2]);
c = six_lock_counts(&f.b->c.lock); c = six_lock_counts(&f->b->c.lock);
prt_printf(&buf, " total locked %u.%u.%u", c.n[0], c.n[1], c.n[2]); prt_printf(&buf, " total locked %u.%u.%u", c.n[0], c.n[1], c.n[2]);
} }
...@@ -760,14 +761,13 @@ int bch2_trans_relock(struct btree_trans *trans) ...@@ -760,14 +761,13 @@ int bch2_trans_relock(struct btree_trans *trans)
} }
count_event(trans->c, trans_restart_relock); count_event(trans->c, trans_restart_relock);
out:
__bch2_trans_unlock(trans);
bch2_trans_verify_locks(trans);
return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock); return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock);
}
}
return 0;
} }
int bch2_trans_relock_notrace(struct btree_trans *trans) static inline int __bch2_trans_relock(struct btree_trans *trans, bool trace)
{ {
struct btree_path *path; struct btree_path *path;
unsigned i; unsigned i;
...@@ -775,30 +775,36 @@ int bch2_trans_relock_notrace(struct btree_trans *trans) ...@@ -775,30 +775,36 @@ int bch2_trans_relock_notrace(struct btree_trans *trans)
if (unlikely(trans->restarted)) if (unlikely(trans->restarted))
return -((int) trans->restarted); return -((int) trans->restarted);
trans_for_each_path(trans, path, i) trans_for_each_path(trans, path, i) {
struct get_locks_fail f;
if (path->should_be_locked && if (path->should_be_locked &&
!bch2_btree_path_relock_norestart(trans, path)) { !btree_path_get_locks(trans, path, false, &f))
return btree_trans_restart(trans, BCH_ERR_transaction_restart_relock); return bch2_trans_relock_fail(trans, path, &f, trace);
} }
bch2_trans_verify_locks(trans);
return 0; return 0;
} }
void bch2_trans_unlock_noassert(struct btree_trans *trans) int bch2_trans_relock(struct btree_trans *trans)
{ {
struct btree_path *path; return __bch2_trans_relock(trans, true);
unsigned i; }
trans_for_each_path(trans, path, i) int bch2_trans_relock_notrace(struct btree_trans *trans)
__bch2_btree_path_unlock(trans, path); {
return __bch2_trans_relock(trans, false);
} }
void bch2_trans_unlock(struct btree_trans *trans) void bch2_trans_unlock_noassert(struct btree_trans *trans)
{ {
struct btree_path *path; __bch2_trans_unlock(trans);
unsigned i; }
trans_for_each_path(trans, path, i) void bch2_trans_unlock(struct btree_trans *trans)
__bch2_btree_path_unlock(trans, path); {
__bch2_trans_unlock(trans);
} }
void bch2_trans_unlock_long(struct btree_trans *trans) void bch2_trans_unlock_long(struct btree_trans *trans)
......
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