Skip to content

Commit f44cc26

Browse files
author
Kent Overstreet
committed
bcachefs: fix seqmutex_relock()
We were grabbing the sequence number before unlock incremented it - fix this by moving the increment to seqmutex_lock() (so the seqmutex_relock() failure path skips the mutex_trylock()), and returning the sequence number from unlock(), to make the API simpler and safer. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 9bd0150 commit f44cc26

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

fs/bcachefs/debug.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ static ssize_t bch2_btree_transactions_read(struct file *file, char __user *buf,
575575
struct bch_fs *c = i->c;
576576
struct btree_trans *trans;
577577
ssize_t ret = 0;
578-
u32 seq;
579578

580579
i->ubuf = buf;
581580
i->size = size;
@@ -589,8 +588,7 @@ static ssize_t bch2_btree_transactions_read(struct file *file, char __user *buf,
589588
continue;
590589

591590
closure_get(&trans->ref);
592-
seq = seqmutex_seq(&c->btree_trans_lock);
593-
seqmutex_unlock(&c->btree_trans_lock);
591+
u32 seq = seqmutex_unlock(&c->btree_trans_lock);
594592

595593
ret = flush_buf(i);
596594
if (ret) {
@@ -811,7 +809,6 @@ static ssize_t bch2_btree_deadlock_read(struct file *file, char __user *buf,
811809
struct bch_fs *c = i->c;
812810
struct btree_trans *trans;
813811
ssize_t ret = 0;
814-
u32 seq;
815812

816813
i->ubuf = buf;
817814
i->size = size;
@@ -828,8 +825,7 @@ static ssize_t bch2_btree_deadlock_read(struct file *file, char __user *buf,
828825
continue;
829826

830827
closure_get(&trans->ref);
831-
seq = seqmutex_seq(&c->btree_trans_lock);
832-
seqmutex_unlock(&c->btree_trans_lock);
828+
u32 seq = seqmutex_unlock(&c->btree_trans_lock);
833829

834830
ret = flush_buf(i);
835831
if (ret) {

fs/bcachefs/seqmutex.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ static inline bool seqmutex_trylock(struct seqmutex *lock)
1919
static inline void seqmutex_lock(struct seqmutex *lock)
2020
{
2121
mutex_lock(&lock->lock);
22-
}
23-
24-
static inline void seqmutex_unlock(struct seqmutex *lock)
25-
{
2622
lock->seq++;
27-
mutex_unlock(&lock->lock);
2823
}
2924

30-
static inline u32 seqmutex_seq(struct seqmutex *lock)
25+
static inline u32 seqmutex_unlock(struct seqmutex *lock)
3126
{
32-
return lock->seq;
27+
u32 seq = lock->seq;
28+
mutex_unlock(&lock->lock);
29+
return seq;
3330
}
3431

3532
static inline bool seqmutex_relock(struct seqmutex *lock, u32 seq)

0 commit comments

Comments
 (0)