]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: bch2_dev_allocator_set_rw()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 13 Apr 2025 20:29:36 +0000 (16:29 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:13 +0000 (20:14 -0400)
Add a helper that lets us change bch_member.data_allowed at runtime.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/alloc_background.h

index 94ea9e49aec451591096fed74af07afc71bacf4b..8b8c2344855f1f32395c5aeef60aa7efb5bc347a 100644 (file)
@@ -2593,15 +2593,22 @@ static bool bch2_dev_has_open_write_point(struct bch_fs *c, struct bch_dev *ca)
        return ret;
 }
 
+void bch2_dev_allocator_set_rw(struct bch_fs *c, struct bch_dev *ca, bool rw)
+{
+       for (unsigned i = 0; i < ARRAY_SIZE(c->rw_devs); i++)
+               if (rw && (ca->mi.data_allowed & BIT(i)))
+                       set_bit(ca->dev_idx, c->rw_devs[i].d);
+               else
+                       clear_bit(ca->dev_idx, c->rw_devs[i].d);
+}
+
 /* device goes ro: */
 void bch2_dev_allocator_remove(struct bch_fs *c, struct bch_dev *ca)
 {
        lockdep_assert_held(&c->state_lock);
 
        /* First, remove device from allocation groups: */
-
-       for (unsigned i = 0; i < ARRAY_SIZE(c->rw_devs); i++)
-               clear_bit(ca->dev_idx, c->rw_devs[i].d);
+       bch2_dev_allocator_set_rw(c, ca, false);
 
        c->rw_devs_change_count++;
 
@@ -2635,10 +2642,7 @@ void bch2_dev_allocator_add(struct bch_fs *c, struct bch_dev *ca)
 {
        lockdep_assert_held(&c->state_lock);
 
-       for (unsigned i = 0; i < ARRAY_SIZE(c->rw_devs); i++)
-               if (ca->mi.data_allowed & (1 << i))
-                       set_bit(ca->dev_idx, c->rw_devs[i].d);
-
+       bch2_dev_allocator_set_rw(c, ca, true);
        c->rw_devs_change_count++;
 }
 
index 34b3d6ac4fbb74a2c5cc492b875f8aa2b3955361..4f94c6a661bf2949b43666711b1d5553d74fecac 100644 (file)
@@ -350,6 +350,7 @@ int bch2_dev_remove_alloc(struct bch_fs *, struct bch_dev *);
 void bch2_recalc_capacity(struct bch_fs *);
 u64 bch2_min_rw_member_capacity(struct bch_fs *);
 
+void bch2_dev_allocator_set_rw(struct bch_fs *, struct bch_dev *, bool);
 void bch2_dev_allocator_remove(struct bch_fs *, struct bch_dev *);
 void bch2_dev_allocator_add(struct bch_fs *, struct bch_dev *);