Skip to content

Commit f162563

Browse files
author
Kent Overstreet
committed
bcachefs: Assert that we don't lock nodes when !trans->locked
We rely on the trans->locked to know if a trans has nodes locked for assertions about deadlocks; there can't be more than one trans in the same process that is locked. Signed-off-by: Kent Overstreet <[email protected]>
1 parent a8cdf0f commit f162563

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

fs/bcachefs/btree_locking.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,12 @@ static inline int __btree_node_lock_nopath(struct btree_trans *trans,
218218
bool lock_may_not_fail,
219219
unsigned long ip)
220220
{
221-
int ret;
222-
223221
trans->lock_may_not_fail = lock_may_not_fail;
224222
trans->lock_must_abort = false;
225223
trans->locking = b;
226224

227-
ret = six_lock_ip_waiter(&b->lock, type, &trans->locking_wait,
228-
bch2_six_check_for_deadlock, trans, ip);
225+
int ret = six_lock_ip_waiter(&b->lock, type, &trans->locking_wait,
226+
bch2_six_check_for_deadlock, trans, ip);
229227
WRITE_ONCE(trans->locking, NULL);
230228
WRITE_ONCE(trans->locking_wait.start_time, 0);
231229

@@ -284,6 +282,7 @@ static inline int btree_node_lock(struct btree_trans *trans,
284282
int ret = 0;
285283

286284
EBUG_ON(level >= BTREE_MAX_DEPTH);
285+
bch2_trans_verify_not_unlocked(trans);
287286

288287
if (likely(six_trylock_type(&b->lock, type)) ||
289288
btree_node_lock_increment(trans, b, level, (enum btree_node_locked_type) type) ||

fs/bcachefs/btree_update_interior.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,18 @@ static void btree_update_nodes_written(struct btree_update *as)
731731
bch2_fs_fatal_err_on(ret && !bch2_journal_error(&c->journal), c,
732732
"%s", bch2_err_str(ret));
733733
err:
734+
/*
735+
* Ensure transaction is unlocked before using btree_node_lock_nopath()
736+
* (the use of which is always suspect, we need to work on removing this
737+
* in the future)
738+
*
739+
* It should be, but bch2_path_get_unlocked_mut() -> bch2_path_get()
740+
* calls bch2_path_upgrade(), before we call path_make_mut(), so we may
741+
* rarely end up with a locked path besides the one we have here:
742+
*/
743+
bch2_trans_unlock(trans);
744+
bch2_trans_begin(trans);
745+
734746
/*
735747
* We have to be careful because another thread might be getting ready
736748
* to free as->b and calling btree_update_reparent() on us - we'll
@@ -750,18 +762,6 @@ static void btree_update_nodes_written(struct btree_update *as)
750762
* we're in journal error state:
751763
*/
752764

753-
/*
754-
* Ensure transaction is unlocked before using
755-
* btree_node_lock_nopath() (the use of which is always suspect,
756-
* we need to work on removing this in the future)
757-
*
758-
* It should be, but bch2_path_get_unlocked_mut() -> bch2_path_get()
759-
* calls bch2_path_upgrade(), before we call path_make_mut(), so
760-
* we may rarely end up with a locked path besides the one we
761-
* have here:
762-
*/
763-
bch2_trans_unlock(trans);
764-
bch2_trans_begin(trans);
765765
btree_path_idx_t path_idx = bch2_path_get_unlocked_mut(trans,
766766
as->btree_id, b->c.level, b->key.k.p);
767767
struct btree_path *path = trans->paths + path_idx;

fs/bcachefs/btree_update_interior.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ static inline int bch2_foreground_maybe_merge(struct btree_trans *trans,
159159
unsigned level,
160160
unsigned flags)
161161
{
162+
bch2_trans_verify_not_unlocked(trans);
163+
162164
return bch2_foreground_maybe_merge_sibling(trans, path, level, flags,
163165
btree_prev_sib) ?:
164166
bch2_foreground_maybe_merge_sibling(trans, path, level, flags,

0 commit comments

Comments
 (0)