bcachefs: Move btree lock debugging to slowpath fn
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 31 Mar 2021 18:42:36 +0000 (14:42 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:58 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_locking.h

index 972486a..42113f8 100644 (file)
@@ -246,6 +246,7 @@ bool __bch2_btree_node_lock(struct btree *b, struct bpos pos,
        struct btree_iter *linked, *deadlock_iter = NULL;
        u64 start_time = local_clock();
        unsigned reason = 9;
+       bool ret;
 
        /* Check if it's safe to block: */
        trans_for_each_iter(trans, linked) {
@@ -354,12 +355,23 @@ bool __bch2_btree_node_lock(struct btree *b, struct bpos pos,
        if (six_trylock_type(&b->c.lock, type))
                return true;
 
-       if (six_lock_type(&b->c.lock, type, should_sleep_fn, p))
-               return false;
+#ifdef CONFIG_BCACHEFS_DEBUG
+       trans->locking_iter_idx = iter->idx;
+       trans->locking_pos      = pos;
+       trans->locking_btree_id = iter->btree_id;
+       trans->locking_level    = level;
+       trans->locking          = b;
+#endif
 
-       bch2_time_stats_update(&trans->c->times[lock_to_time_stat(type)],
-                              start_time);
-       return true;
+       ret = six_lock_type(&b->c.lock, type, should_sleep_fn, p) == 0;
+
+#ifdef CONFIG_BCACHEFS_DEBUG
+       trans->locking = NULL;
+#endif
+       if (ret)
+               bch2_time_stats_update(&trans->c->times[lock_to_time_stat(type)],
+                                      start_time);
+       return ret;
 }
 
 /* Btree iterator locking: */
index cc07ef2..1146dd3 100644 (file)
@@ -186,27 +186,14 @@ static inline bool btree_node_lock(struct btree *b,
                        unsigned long ip)
 {
        struct btree_trans *trans = iter->trans;
-       bool ret;
 
        EBUG_ON(level >= BTREE_MAX_DEPTH);
        EBUG_ON(!(trans->iters_linked & (1ULL << iter->idx)));
 
-#ifdef CONFIG_BCACHEFS_DEBUG
-       trans->locking          = b;
-       trans->locking_iter_idx = iter->idx;
-       trans->locking_pos      = pos;
-       trans->locking_btree_id = iter->btree_id;
-       trans->locking_level    = level;
-#endif
-       ret   = likely(six_trylock_type(&b->c.lock, type)) ||
+       return likely(six_trylock_type(&b->c.lock, type)) ||
                btree_node_lock_increment(trans, b, level, type) ||
                __bch2_btree_node_lock(b, pos, level, iter, type,
                                       should_sleep_fn, p, ip);
-
-#ifdef CONFIG_BCACHEFS_DEBUG
-       trans->locking = NULL;
-#endif
-       return ret;
 }
 
 bool __bch2_btree_node_relock(struct btree_iter *, unsigned);