bcachefs: bch2_have_enough_devs() checks for nonexistent device
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 30 Apr 2024 19:45:05 +0000 (15:45 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 8 May 2024 21:29:22 +0000 (17:29 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/replicas.c

index f2c99703c73061cd59e15d93537f93bb061e31cd..f8ff7c8bb05ee5a17c99464b3021326e6c3b2ff7 100644 (file)
@@ -947,18 +947,20 @@ bool bch2_have_enough_devs(struct bch_fs *c, struct bch_devs_mask devs,
 
        percpu_down_read(&c->mark_lock);
        for_each_cpu_replicas_entry(&c->replicas, e) {
-               unsigned i, nr_online = 0, nr_failed = 0, dflags = 0;
+               unsigned nr_online = 0, nr_failed = 0, dflags = 0;
                bool metadata = e->data_type < BCH_DATA_user;
 
                if (e->data_type == BCH_DATA_cached)
                        continue;
 
-               for (i = 0; i < e->nr_devs; i++) {
-                       struct bch_dev *ca = bch2_dev_bkey_exists(c, e->devs[i]);
-
+               rcu_read_lock();
+               for (unsigned i = 0; i < e->nr_devs; i++) {
                        nr_online += test_bit(e->devs[i], devs.d);
-                       nr_failed += ca->mi.state == BCH_MEMBER_STATE_failed;
+
+                       struct bch_dev *ca = bch2_dev_rcu(c, e->devs[i]);
+                       nr_failed += ca && ca->mi.state == BCH_MEMBER_STATE_failed;
                }
+               rcu_read_unlock();
 
                if (nr_failed == e->nr_devs)
                        continue;