]> git.dujemihanovic.xyz Git - linux.git/commitdiff
bcachefs: bch_fs.rw_devs_change_count
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 6 Sep 2024 23:12:53 +0000 (19:12 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Sep 2024 15:39:49 +0000 (11:39 -0400)
Add a counter that's incremented whenever rw devices change; this will
be used for erasure coding so that it can keep ec_stripe_head in sync
and not deadlock on a new stripe when a device it wants goes away.

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

index 87ce65e4630417e0145409a4225c5db8d791dcb1..645b5ed4babb187d25567c07412727d782a1660d 100644 (file)
@@ -2463,13 +2463,15 @@ static bool bch2_dev_has_open_write_point(struct bch_fs *c, struct bch_dev *ca)
 /* device goes ro: */
 void bch2_dev_allocator_remove(struct bch_fs *c, struct bch_dev *ca)
 {
-       unsigned i;
+       lockdep_assert_held(&c->state_lock);
 
        /* First, remove device from allocation groups: */
 
-       for (i = 0; i < ARRAY_SIZE(c->rw_devs); i++)
+       for (unsigned i = 0; i < ARRAY_SIZE(c->rw_devs); i++)
                clear_bit(ca->dev_idx, c->rw_devs[i].d);
 
+       c->rw_devs_change_count++;
+
        /*
         * Capacity is calculated based off of devices in allocation groups:
         */
@@ -2498,11 +2500,13 @@ void bch2_dev_allocator_remove(struct bch_fs *c, struct bch_dev *ca)
 /* device goes rw: */
 void bch2_dev_allocator_add(struct bch_fs *c, struct bch_dev *ca)
 {
-       unsigned i;
+       lockdep_assert_held(&c->state_lock);
 
-       for (i = 0; i < ARRAY_SIZE(c->rw_devs); i++)
+       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);
+
+       c->rw_devs_change_count++;
 }
 
 void bch2_dev_allocator_background_exit(struct bch_dev *ca)
index b2475b9555ac4e3f283a19693cfb0790a15bb4dd..c711d4c27a03f6ecde9a834e4c8cb42e72a4c39d 100644 (file)
@@ -871,6 +871,7 @@ struct bch_fs {
 
        /* ALLOCATION */
        struct bch_devs_mask    rw_devs[BCH_DATA_NR];
+       unsigned long           rw_devs_change_count;
 
        u64                     capacity; /* sectors */
        u64                     reserved; /* sectors */