bcachefs: Fix a bug when shutting down before allocator started
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 9 Feb 2019 21:15:29 +0000 (16:15 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:15 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/bcachefs.h
fs/bcachefs/super.c

index 686287d12d14c92c914459df64cc02b29c651d3b..83b3445cc76fa0a8765f01a555570c924bdef9a8 100644 (file)
@@ -1535,6 +1535,8 @@ int bch2_fs_allocator_start(struct bch_fs *c)
                }
        }
 
+       set_bit(BCH_FS_ALLOCATOR_RUNNING, &c->flags);
+
        return bch2_alloc_write(c, false, &wrote);
 }
 
index 2d67c9911fbba72f7609e022df2a389f344520c9..4a0e2f63e645b58badd7f34d050f9c19d0685cb4 100644 (file)
@@ -477,6 +477,7 @@ enum {
        /* startup: */
        BCH_FS_ALLOC_READ_DONE,
        BCH_FS_ALLOCATOR_STARTED,
+       BCH_FS_ALLOCATOR_RUNNING,
        BCH_FS_INITIAL_GC_DONE,
        BCH_FS_FSCK_DONE,
        BCH_FS_STARTED,
index f1e60c377fa2dfb9cf2c22d497c2ee860049b7d6..9ec05410aeb43e197c8bbc074dc58f659e60e573 100644 (file)
@@ -191,6 +191,9 @@ static void __bch2_fs_read_only(struct bch_fs *c)
         */
        bch2_journal_flush_all_pins(&c->journal);
 
+       if (!test_bit(BCH_FS_ALLOCATOR_RUNNING, &c->flags))
+               goto allocator_not_running;
+
        do {
                ret = bch2_alloc_write(c, false, &wrote);
                if (ret) {
@@ -219,10 +222,12 @@ static void __bch2_fs_read_only(struct bch_fs *c)
                closure_wait_event(&c->btree_interior_update_wait,
                                   !bch2_btree_interior_updates_nr_pending(c));
        } while (wrote);
-
+allocator_not_running:
        for_each_member_device(ca, c, i)
                bch2_dev_allocator_stop(ca);
 
+       clear_bit(BCH_FS_ALLOCATOR_RUNNING, &c->flags);
+
        bch2_fs_journal_stop(&c->journal);
 
        /* XXX: mark super that alloc info is persistent */
@@ -349,6 +354,8 @@ const char *bch2_fs_read_write(struct bch_fs *c)
                        goto err;
                }
 
+       set_bit(BCH_FS_ALLOCATOR_RUNNING, &c->flags);
+
        err = "error starting btree GC thread";
        if (bch2_gc_thread_start(c))
                goto err;