bcachefs: fix a deadlock on startup
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 20 Feb 2019 21:00:03 +0000 (16:00 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:16 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/journal_io.c

index 04b75367fcde5ba47cede82f237bbd66214e1474..fd39eeae5740ee621cc66257483324333d3b1ea2 100644 (file)
@@ -1678,7 +1678,6 @@ int bch2_fs_allocator_start(struct bch_fs *c)
 {
        struct bch_dev *ca;
        unsigned i;
-       bool wrote;
        int ret;
 
        down_read(&c->gc_lock);
@@ -1697,8 +1696,7 @@ int bch2_fs_allocator_start(struct bch_fs *c)
        }
 
        set_bit(BCH_FS_ALLOCATOR_RUNNING, &c->flags);
-
-       return bch2_alloc_write(c, false, &wrote);
+       return 0;
 }
 
 void bch2_fs_allocator_background_init(struct bch_fs *c)
index e5e50be80126fb798ef4eb53da80e5c4c4cc2eba..1f7bd314f61eeef8f6e57199b5f010436956ea2c 100644 (file)
@@ -888,9 +888,18 @@ err:
 static unsigned journal_dev_buckets_available(struct journal *j,
                                              struct journal_device *ja)
 {
+       struct bch_fs *c = container_of(j, struct bch_fs, journal);
        unsigned next = (ja->cur_idx + 1) % ja->nr;
        unsigned available = (ja->last_idx + ja->nr - next) % ja->nr;
 
+       /*
+        * Allocator startup needs some journal space before we can do journal
+        * replay:
+        */
+       if (available &&
+           test_bit(BCH_FS_ALLOCATOR_STARTED, &c->flags))
+               available--;
+
        /*
         * Don't use the last bucket unless writing the new last_seq
         * will make another bucket available: