Skip to content

Commit 5b7b342

Browse files
author
Kent Overstreet
committed
bcachefs: btree_node_locked_type_nowrite()
Small helper to improve locking assertions. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 659489f commit 5b7b342

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

fs/bcachefs/btree_locking.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -877,14 +877,11 @@ void __bch2_btree_path_verify_locks(struct btree_path *path)
877877

878878
for (unsigned l = 0; l < BTREE_MAX_DEPTH; l++) {
879879
int want = btree_lock_want(path, l);
880-
int have = btree_node_locked_type(path, l);
880+
int have = btree_node_locked_type_nowrite(path, l);
881881

882882
BUG_ON(!is_btree_node(path, l) && have != BTREE_NODE_UNLOCKED);
883883

884-
BUG_ON(is_btree_node(path, l) &&
885-
(want == BTREE_NODE_UNLOCKED ||
886-
have != BTREE_NODE_WRITE_LOCKED) &&
887-
want != have);
884+
BUG_ON(is_btree_node(path, l) && want != have);
888885

889886
BUG_ON(btree_node_locked(path, l) &&
890887
path->l[l].lock_seq != six_lock_seq(&path->l[l].b->c.lock));

fs/bcachefs/btree_locking.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ static inline int btree_node_locked_type(struct btree_path *path,
4343
return BTREE_NODE_UNLOCKED + ((path->nodes_locked >> (level << 1)) & 3);
4444
}
4545

46+
static inline int btree_node_locked_type_nowrite(struct btree_path *path,
47+
unsigned level)
48+
{
49+
int have = btree_node_locked_type(path, level);
50+
return have == BTREE_NODE_WRITE_LOCKED
51+
? BTREE_NODE_INTENT_LOCKED
52+
: have;
53+
}
54+
4655
static inline bool btree_node_write_locked(struct btree_path *path, unsigned l)
4756
{
4857
return btree_node_locked_type(path, l) == BTREE_NODE_WRITE_LOCKED;
@@ -366,8 +375,8 @@ static inline bool bch2_btree_node_relock_notrace(struct btree_trans *trans,
366375
struct btree_path *path, unsigned level)
367376
{
368377
EBUG_ON(btree_node_locked(path, level) &&
369-
!btree_node_write_locked(path, level) &&
370-
btree_node_locked_type(path, level) != __btree_lock_want(path, level));
378+
btree_node_locked_type_nowrite(path, level) !=
379+
__btree_lock_want(path, level));
371380

372381
return likely(btree_node_locked(path, level)) ||
373382
(!IS_ERR_OR_NULL(path->l[level].b) &&

0 commit comments

Comments
 (0)