bcachefs: extent_ptr_durability() -> bch2_dev_rcu()
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 1 May 2024 00:54:20 +0000 (20:54 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 8 May 2024 21:29:23 +0000 (17:29 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/data_update.c
fs/bcachefs/extents.c
fs/bcachefs/io_write.c
fs/bcachefs/move.c

index 1cf92bea7f9f7e3d579960ee57a72d93d81ec906..7aad6085ef53ef2cd47703e4f394fb0ce2a41f03 100644 (file)
@@ -203,6 +203,8 @@ restart_drop_conflicting_replicas:
 
                /* Now, drop excess replicas: */
 restart_drop_extra_replicas:
+
+               rcu_read_lock();
                bkey_for_each_ptr_decode(old.k, bch2_bkey_ptrs(bkey_i_to_s(insert)), p, entry) {
                        unsigned ptr_durability = bch2_extent_ptr_durability(c, &p);
 
@@ -214,6 +216,7 @@ restart_drop_extra_replicas:
                                goto restart_drop_extra_replicas;
                        }
                }
+               rcu_read_unlock();
 
                /* Finally, add the pointers we just wrote: */
                extent_for_each_ptr_decode(extent_i_to_s(new), p, entry)
@@ -552,6 +555,7 @@ int bch2_data_update_init(struct btree_trans *trans,
                struct bpos bucket = PTR_BUCKET_POS(ca, &p.ptr);
                bool locked;
 
+               rcu_read_lock();
                if (((1U << i) & m->data_opts.rewrite_ptrs)) {
                        BUG_ON(p.ptr.cached);
 
@@ -565,6 +569,7 @@ int bch2_data_update_init(struct btree_trans *trans,
                        bch2_dev_list_add_dev(&m->op.devs_have, p.ptr.dev);
                        durability_have += bch2_extent_ptr_durability(c, &p);
                }
+               rcu_read_unlock();
 
                /*
                 * op->csum_type is normally initialized from the fs/file's
index 46f8164b1a49df1c21c3b049b3407961a390c9c7..dc78ace56181018a7355697b0e42d81e2e6ecccf 100644 (file)
@@ -675,16 +675,16 @@ static inline unsigned __extent_ptr_durability(struct bch_dev *ca, struct extent
 
 unsigned bch2_extent_ptr_desired_durability(struct bch_fs *c, struct extent_ptr_decoded *p)
 {
-       struct bch_dev *ca = bch2_dev_bkey_exists(c, p->ptr.dev);
+       struct bch_dev *ca = bch2_dev_rcu(c, p->ptr.dev);
 
-       return __extent_ptr_durability(ca, p);
+       return ca ? __extent_ptr_durability(ca, p) : 0;
 }
 
 unsigned bch2_extent_ptr_durability(struct bch_fs *c, struct extent_ptr_decoded *p)
 {
-       struct bch_dev *ca = bch2_dev_bkey_exists(c, p->ptr.dev);
+       struct bch_dev *ca = bch2_dev_rcu(c, p->ptr.dev);
 
-       if (ca->mi.state == BCH_MEMBER_STATE_failed)
+       if (!ca || ca->mi.state == BCH_MEMBER_STATE_failed)
                return 0;
 
        return __extent_ptr_durability(ca, p);
@@ -697,8 +697,10 @@ unsigned bch2_bkey_durability(struct bch_fs *c, struct bkey_s_c k)
        struct extent_ptr_decoded p;
        unsigned durability = 0;
 
+       rcu_read_lock();
        bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
                durability += bch2_extent_ptr_durability(c, &p);
+       rcu_read_unlock();
 
        return durability;
 }
@@ -710,9 +712,11 @@ static unsigned bch2_bkey_durability_safe(struct bch_fs *c, struct bkey_s_c k)
        struct extent_ptr_decoded p;
        unsigned durability = 0;
 
+       rcu_read_lock();
        bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
                if (p.ptr.dev < c->sb.nr_devices && c->devs[p.ptr.dev])
                        durability += bch2_extent_ptr_durability(c, &p);
+       rcu_read_unlock();
 
        return durability;
 }
index 5d9f349a150431dcf82b944df2b9e240c035e2bd..285e1a23bde5b5a622049ed53e9945814b41a585 100644 (file)
@@ -1099,12 +1099,17 @@ static bool bch2_extent_is_writeable(struct bch_write_op *op,
                return false;
 
        e = bkey_s_c_to_extent(k);
+
+       rcu_read_lock();
        extent_for_each_ptr_decode(e, p, entry) {
-               if (crc_is_encoded(p.crc) || p.has_ec)
+               if (crc_is_encoded(p.crc) || p.has_ec) {
+                       rcu_read_unlock();
                        return false;
+               }
 
                replicas += bch2_extent_ptr_durability(c, &p);
        }
+       rcu_read_unlock();
 
        return replicas >= op->opts.data_replicas;
 }
index 0e3203de1cd64cff5339d820ca65228b31de3fb9..8171f947fac8f8d75f376d2df4a4ac341a0645d1 100644 (file)
@@ -1033,6 +1033,7 @@ static bool drop_extra_replicas_pred(struct bch_fs *c, void *arg,
        struct extent_ptr_decoded p;
        unsigned i = 0;
 
+       rcu_read_lock();
        bkey_for_each_ptr_decode(k.k, bch2_bkey_ptrs_c(k), p, entry) {
                unsigned d = bch2_extent_ptr_durability(c, &p);
 
@@ -1043,6 +1044,7 @@ static bool drop_extra_replicas_pred(struct bch_fs *c, void *arg,
 
                i++;
        }
+       rcu_read_unlock();
 
        return data_opts->kill_ptrs != 0;
 }