summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/btree_locking.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-09-02 04:05:16 +0200
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 23:09:40 +0200
commit6b81f194f345d15dd15601ee7b604a0640445895 (patch)
tree1b496804097ee8f9502ede363bffb24b3408a51c /fs/bcachefs/btree_locking.c
parentbcachefs: bch2_btree_node_lock_write_nofail() (diff)
downloadlinux-6b81f194f345d15dd15601ee7b604a0640445895.tar.xz
linux-6b81f194f345d15dd15601ee7b604a0640445895.zip
bcachefs: Fix six_lock_readers_add()
Have to be careful with bit fields - when subtracting, this was overflowing into the write_locking bit. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/btree_locking.c')
-rw-r--r--fs/bcachefs/btree_locking.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/bcachefs/btree_locking.c b/fs/bcachefs/btree_locking.c
index 24d0ea903380..158cb7ac64f2 100644
--- a/fs/bcachefs/btree_locking.c
+++ b/fs/bcachefs/btree_locking.c
@@ -10,10 +10,12 @@ struct lock_class_key bch2_btree_node_lock_key;
static inline void six_lock_readers_add(struct six_lock *lock, int nr)
{
- if (!lock->readers)
+ if (lock->readers)
+ this_cpu_add(*lock->readers, nr);
+ else if (nr > 0)
atomic64_add(__SIX_VAL(read_lock, nr), &lock->state.counter);
else
- this_cpu_add(*lock->readers, nr);
+ atomic64_sub(__SIX_VAL(read_lock, -nr), &lock->state.counter);
}
struct six_lock_count bch2_btree_node_lock_counts(struct btree_trans *trans,