Skip to content

Commit a56da69

Browse files
author
Kent Overstreet
committed
bcachefs: Fix bch2_trans_put()
reference: koverstreet/bcachefs#692 trans->ref is the reference used by the cycle detector, which walks btree_trans objects of other threads to walk the graph of held locks and issue wakeups when an abort is required. We have to wait for the ref to go to 1 before freeing trans->paths or clearing trans->locking_wait.task. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 0a2a507 commit a56da69

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,7 @@ struct btree_trans *__bch2_trans_get(struct bch_fs *c, unsigned fn_idx)
31613161
list_add_done:
31623162
seqmutex_unlock(&c->btree_trans_lock);
31633163
got_trans:
3164+
trans->ref.closure_get_happened = false;
31643165
trans->c = c;
31653166
trans->last_begin_time = local_clock();
31663167
trans->fn_idx = fn_idx;
@@ -3235,7 +3236,6 @@ void bch2_trans_put(struct btree_trans *trans)
32353236
trans_for_each_update(trans, i)
32363237
__btree_path_put(trans->paths + i->path, true);
32373238
trans->nr_updates = 0;
3238-
trans->locking_wait.task = NULL;
32393239

32403240
check_btree_paths_leaked(trans);
32413241

@@ -3256,6 +3256,13 @@ void bch2_trans_put(struct btree_trans *trans)
32563256
if (unlikely(trans->journal_replay_not_finished))
32573257
bch2_journal_keys_put(c);
32583258

3259+
/*
3260+
* trans->ref protects trans->locking_wait.task, btree_paths arary; used
3261+
* by cycle detector
3262+
*/
3263+
closure_sync(&trans->ref);
3264+
trans->locking_wait.task = NULL;
3265+
32593266
unsigned long *paths_allocated = trans->paths_allocated;
32603267
trans->paths_allocated = NULL;
32613268
trans->paths = NULL;
@@ -3273,8 +3280,6 @@ void bch2_trans_put(struct btree_trans *trans)
32733280
trans = this_cpu_xchg(c->btree_trans_bufs->trans, trans);
32743281

32753282
if (trans) {
3276-
closure_sync(&trans->ref);
3277-
32783283
seqmutex_lock(&c->btree_trans_lock);
32793284
list_del(&trans->list);
32803285
seqmutex_unlock(&c->btree_trans_lock);

0 commit comments

Comments
 (0)