diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-12-06 16:26:18 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-01 11:47:40 -0500 |
commit | 63508b756443cb38e432dea01fec36248cb25cd7 (patch) | |
tree | cbc9df99973f3ccef973b82516655329556d2d98 /fs/bcachefs/bcachefs.h | |
parent | 483dea4431240dbd6503dc1b2801e391068ba737 (diff) | |
download | linux-stable-63508b756443cb38e432dea01fec36248cb25cd7.tar.gz linux-stable-63508b756443cb38e432dea01fec36248cb25cd7.tar.bz2 linux-stable-63508b756443cb38e432dea01fec36248cb25cd7.zip |
bcachefs: c->ro_ref
Add a new refcount for async ops that don't necessarily need the fs to
be RW, with similar lifetime/rules otherwise as c->writes.
To be used by online fsck.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/bcachefs.h')
-rw-r--r-- | fs/bcachefs/bcachefs.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 06b5cea9980e..ca7c9dea83dd 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -710,6 +710,13 @@ struct bch_fs { #else struct percpu_ref writes; #endif + /* + * Analagous to c->writes, for asynchronous ops that don't necessarily + * need fs to be read-write + */ + refcount_t ro_ref; + wait_queue_head_t ro_ref_wait; + struct work_struct read_only_work; struct bch_dev __rcu *devs[BCH_SB_MEMBERS_MAX]; @@ -1105,6 +1112,20 @@ static inline void bch2_write_ref_put(struct bch_fs *c, enum bch_write_ref ref) #endif } +static inline bool bch2_ro_ref_tryget(struct bch_fs *c) +{ + if (test_bit(BCH_FS_stopping, &c->flags)) + return false; + + return refcount_inc_not_zero(&c->ro_ref); +} + +static inline void bch2_ro_ref_put(struct bch_fs *c) +{ + if (refcount_dec_and_test(&c->ro_ref)) + wake_up(&c->ro_ref_wait); +} + static inline void bch2_set_ra_pages(struct bch_fs *c, unsigned ra_pages) { #ifndef NO_BCACHEFS_FS |