summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/sb-members.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-09-02 00:12:26 +0200
committerKent Overstreet <kent.overstreet@linux.dev>2024-09-21 17:39:48 +0200
commit805ddc204287e74ebd2640c0f088e04f94e98b48 (patch)
tree9c10193e84cba7da633ad0434fb4e57948577767 /fs/bcachefs/sb-members.h
parentbcachefs: Progress indicator for extents_to_backpointers (diff)
downloadlinux-805ddc204287e74ebd2640c0f088e04f94e98b48.tar.xz
linux-805ddc204287e74ebd2640c0f088e04f94e98b48.zip
bcachefs: bch2_dev_rcu_noerror()
bch2_dev_rcu() now properly errors if the device is invalid Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to '')
-rw-r--r--fs/bcachefs/sb-members.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/fs/bcachefs/sb-members.h b/fs/bcachefs/sb-members.h
index 1a21d1f15a9c..762083b564ee 100644
--- a/fs/bcachefs/sb-members.h
+++ b/fs/bcachefs/sb-members.h
@@ -198,29 +198,37 @@ static inline struct bch_dev *bch2_dev_locked(struct bch_fs *c, unsigned dev)
lockdep_is_held(&c->state_lock));
}
-static inline struct bch_dev *bch2_dev_rcu(struct bch_fs *c, unsigned dev)
+static inline struct bch_dev *bch2_dev_rcu_noerror(struct bch_fs *c, unsigned dev)
{
return c && dev < c->sb.nr_devices
? rcu_dereference(c->devs[dev])
: NULL;
}
+void bch2_dev_missing(struct bch_fs *, unsigned);
+
+static inline struct bch_dev *bch2_dev_rcu(struct bch_fs *c, unsigned dev)
+{
+ struct bch_dev *ca = bch2_dev_rcu_noerror(c, dev);
+ if (unlikely(!ca))
+ bch2_dev_missing(c, dev);
+ return ca;
+}
+
static inline struct bch_dev *bch2_dev_tryget_noerror(struct bch_fs *c, unsigned dev)
{
rcu_read_lock();
- struct bch_dev *ca = bch2_dev_rcu(c, dev);
+ struct bch_dev *ca = bch2_dev_rcu_noerror(c, dev);
if (ca)
bch2_dev_get(ca);
rcu_read_unlock();
return ca;
}
-void bch2_dev_missing(struct bch_fs *, unsigned);
-
static inline struct bch_dev *bch2_dev_tryget(struct bch_fs *c, unsigned dev)
{
struct bch_dev *ca = bch2_dev_tryget_noerror(c, dev);
- if (!ca)
+ if (unlikely(!ca))
bch2_dev_missing(c, dev);
return ca;
}