diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-05-03 18:07:40 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-05-08 17:29:22 -0400 |
commit | 552aa5486579c18b4f8e7ca03ef88fa573c517b5 (patch) | |
tree | c64a06534b0b4de946fababe7f7800347172298c /fs/bcachefs/sb-members.h | |
parent | f295298b8c6413f0ed2a5a69dd7f32409cc54f1d (diff) |
bcachefs: Debug asserts for ca->ref
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/sb-members.h')
-rw-r--r-- | fs/bcachefs/sb-members.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/fs/bcachefs/sb-members.h b/fs/bcachefs/sb-members.h index 0aeb7285dc8c..ecb8284af0de 100644 --- a/fs/bcachefs/sb-members.h +++ b/fs/bcachefs/sb-members.h @@ -107,12 +107,25 @@ static inline struct bch_dev *__bch2_next_dev(struct bch_fs *c, struct bch_dev * static inline void bch2_dev_get(struct bch_dev *ca) { +#ifdef CONFIG_BCACHEFS_DEBUG + BUG_ON(atomic_long_inc_return(&ca->ref) <= 1L); +#else percpu_ref_get(&ca->ref); +#endif } static inline void __bch2_dev_put(struct bch_dev *ca) { +#ifdef CONFIG_BCACHEFS_DEBUG + long r = atomic_long_dec_return(&ca->ref); + if (r < (long) !ca->dying) + panic("bch_dev->ref underflow, last put: %pS\n", (void *) ca->last_put); + ca->last_put = _THIS_IP_; + if (!r) + complete(&ca->ref_completion); +#else percpu_ref_put(&ca->ref); +#endif } static inline void bch2_dev_put(struct bch_dev *ca) |