bcachefs: Fix locking in allocator thread
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 24 Jul 2018 23:45:22 +0000 (19:45 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:08 +0000 (17:08 -0400)
gc lock must be held while invalidating buckets - fixes
"1f7a95698e bcachefs: Invalidate buckets when writing to alloc btree"

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

index ea1dc52..192ab65 100644 (file)
@@ -964,16 +964,21 @@ static int bch2_allocator_thread(void *arg)
                if (ret)
                        goto stop;
 
+               down_read(&c->gc_lock);
+
                ret = bch2_invalidate_buckets(c, ca);
-               if (ret)
+               if (ret) {
+                       up_read(&c->gc_lock);
                        goto stop;
+               }
 
-               if (!fifo_empty(&ca->free_inc))
+               if (!fifo_empty(&ca->free_inc)) {
+                       up_read(&c->gc_lock);
                        continue;
+               }
 
                pr_debug("free_inc now empty");
 
-               down_read(&c->gc_lock);
                do {
                        if (test_bit(BCH_FS_GC_FAILURE, &c->flags)) {
                                up_read(&c->gc_lock);