summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/btree_locking.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-09-03 17:18:57 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:11 -0400
commit068bcaa589e268fe0bca1f972b3a08a18be8c5dc (patch)
treea7ce7f8ba72f74c5174194b5f8f0c003c89686d7 /fs/bcachefs/btree_locking.h
parent807dda8c83620ab0fd1d93bbe8bdc4a289cbd045 (diff)
downloadlinux-068bcaa589e268fe0bca1f972b3a08a18be8c5dc.tar.gz
linux-068bcaa589e268fe0bca1f972b3a08a18be8c5dc.tar.bz2
linux-068bcaa589e268fe0bca1f972b3a08a18be8c5dc.zip
bcachefs: Add more assertions for locking btree iterators out of order
btree_path_traverse_all() traverses btree iterators in sorted order, and thus shouldn't see transaction restarts due to potential deadlocks - but sometimes we do. This patch adds some more assertions and tracks some more state to help track this down. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/btree_locking.h')
-rw-r--r--fs/bcachefs/btree_locking.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/fs/bcachefs/btree_locking.h b/fs/bcachefs/btree_locking.h
index d05689180c63..ff58870311f3 100644
--- a/fs/bcachefs/btree_locking.h
+++ b/fs/bcachefs/btree_locking.h
@@ -57,7 +57,8 @@ static inline void mark_btree_node_unlocked(struct btree_path *path,
path->nodes_intent_locked &= ~(1 << level);
}
-static inline void mark_btree_node_locked(struct btree_path *path,
+static inline void mark_btree_node_locked(struct btree_trans *trans,
+ struct btree_path *path,
unsigned level,
enum six_lock_type type)
{
@@ -67,12 +68,20 @@ static inline void mark_btree_node_locked(struct btree_path *path,
path->nodes_locked |= 1 << level;
path->nodes_intent_locked |= type << level;
+#ifdef CONFIG_BCACHEFS_DEBUG
+ path->ip_locked = _RET_IP_;
+ btree_trans_sort_paths(trans);
+ BUG_ON(trans->in_traverse_all &&
+ trans->traverse_all_idx != U8_MAX &&
+ path->sorted_idx > trans->paths[trans->traverse_all_idx].sorted_idx);
+#endif
}
-static inline void mark_btree_node_intent_locked(struct btree_path *path,
+static inline void mark_btree_node_intent_locked(struct btree_trans *trans,
+ struct btree_path *path,
unsigned level)
{
- mark_btree_node_locked(path, level, SIX_LOCK_intent);
+ mark_btree_node_locked(trans, path, level, SIX_LOCK_intent);
}
static inline enum six_lock_type __btree_lock_want(struct btree_path *path, int level)
@@ -111,6 +120,9 @@ static inline void __bch2_btree_path_unlock(struct btree_path *path)
while (path->nodes_locked)
btree_node_unlock(path, __ffs(path->nodes_locked));
+#ifdef CONFIG_BCACHEFS_DEBUG
+ path->ip_locked = 0;
+#endif
}
static inline enum bch_time_stats lock_to_time_stat(enum six_lock_type type)