bcachefs: bch2_dev_tryget()
Most uses of bch2_dev_bkey_exists() are going away, where we assume that because a key references a device the device most exist - instead, we'll be explicitly checking if the device exists and getting a reference to it. This adds the new helpers. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
@@ -9,6 +9,11 @@
|
||||
#include "sb-members.h"
|
||||
#include "super-io.h"
|
||||
|
||||
void bch2_dev_missing(struct bch_fs *c, unsigned dev)
|
||||
{
|
||||
bch2_fs_inconsistent(c, "pointer to nonexistent device %u", dev);
|
||||
}
|
||||
|
||||
#define x(t, n, ...) [n] = #t,
|
||||
static const char * const bch2_iops_measurements[] = {
|
||||
BCH_IOPS_MEASUREMENTS()
|
||||
|
||||
@@ -217,6 +217,26 @@ static inline struct bch_dev *bch2_dev_rcu(struct bch_fs *c, unsigned dev)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
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);
|
||||
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)
|
||||
bch2_dev_missing(c, dev);
|
||||
return ca;
|
||||
}
|
||||
|
||||
/* XXX kill, move to struct bch_fs */
|
||||
static inline struct bch_devs_mask bch2_online_devs(struct bch_fs *c)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user