bcachefs: ec_stripe_delete_work() now takes ref on c->writes
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 9 Feb 2023 17:22:58 +0000 (12:22 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:50 +0000 (17:09 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/ec.c
fs/bcachefs/ec.h
fs/bcachefs/super.c

index e320868a8b8bfccde5820b44c8ebf5a2a1e7f347..f4b903f2fd2261d1ae0953369764c6562a4e8595 100644 (file)
@@ -672,9 +672,8 @@ void bch2_stripes_heap_update(struct bch_fs *c,
 
        heap_verify_backpointer(c, idx);
 
-       if (stripe_idx_to_delete(c) >= 0 &&
-           !percpu_ref_is_dying(&c->writes))
-               schedule_work(&c->ec_stripe_delete_work);
+       if (stripe_idx_to_delete(c) >= 0)
+               bch2_do_stripe_deletes(c);
 }
 
 /* stripe deletion */
@@ -707,6 +706,15 @@ static void ec_stripe_delete_work(struct work_struct *work)
                if (ec_stripe_delete(c, idx))
                        break;
        }
+
+       percpu_ref_put(&c->writes);
+}
+
+void bch2_do_stripe_deletes(struct bch_fs *c)
+{
+       if (percpu_ref_tryget_live(&c->writes) &&
+           !schedule_work(&c->ec_stripe_delete_work))
+               percpu_ref_put(&c->writes);
 }
 
 /* stripe creation: */
index 8596fa763b4cf17ede558b39d02f3949dce2d70f..4d4e3756dd59bd0dbfc82643d2dc4078731f0210 100644 (file)
@@ -213,6 +213,8 @@ void bch2_stripes_heap_update(struct bch_fs *, struct stripe *, size_t);
 void bch2_stripes_heap_del(struct bch_fs *, struct stripe *, size_t);
 void bch2_stripes_heap_insert(struct bch_fs *, struct stripe *, size_t);
 
+void bch2_do_stripe_deletes(struct bch_fs *);
+
 void bch2_ec_stop_dev(struct bch_fs *, struct bch_dev *);
 
 void bch2_ec_flush_new_stripes(struct bch_fs *);
index c911a07f8e8e9ec905bcb9661d6c447ad9840a83..7dfe9050a006cb88f936151bd7460293048f16e2 100644 (file)
@@ -258,8 +258,6 @@ void bch2_fs_read_only(struct bch_fs *c)
         */
        percpu_ref_kill(&c->writes);
 
-       cancel_work_sync(&c->ec_stripe_delete_work);
-
        /*
         * If we're not doing an emergency shutdown, we want to wait on
         * outstanding writes to complete so they don't see spurious errors due
@@ -391,9 +389,6 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
                bch2_dev_allocator_add(c, ca);
        bch2_recalc_capacity(c);
 
-       bch2_do_discards(c);
-       bch2_do_invalidates(c);
-
        if (!early) {
                ret = bch2_fs_read_write_late(c);
                if (ret)
@@ -403,6 +398,10 @@ static int __bch2_fs_read_write(struct bch_fs *c, bool early)
        percpu_ref_reinit(&c->writes);
        set_bit(BCH_FS_RW, &c->flags);
        set_bit(BCH_FS_WAS_RW, &c->flags);
+
+       bch2_do_discards(c);
+       bch2_do_invalidates(c);
+       bch2_do_stripe_deletes(c);
        return 0;
 err:
        __bch2_fs_read_only(c);