bcachefs: Fix device add
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 21 Jul 2018 02:08:17 +0000 (22:08 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:07 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_gc.c
fs/bcachefs/journal.c

index 155e69056d960b96633848859cdfa4989a9c1131..00c28a0a4d9d0f0116f2384d29fc1a041cf458a1 100644 (file)
@@ -327,9 +327,16 @@ void bch2_mark_dev_superblock(struct bch_fs *c, struct bch_dev *ca,
        unsigned i;
        u64 b;
 
+       /*
+        * This conditional is kind of gross, but we may be called from the
+        * device add path, before the new device has actually been added to the
+        * running filesystem:
+        */
        if (c) {
                lockdep_assert_held(&c->sb_lock);
                percpu_down_read(&c->usage_lock);
+       } else {
+               preempt_disable();
        }
 
        for (i = 0; i < layout->nr_superblocks; i++) {
@@ -357,6 +364,8 @@ void bch2_mark_dev_superblock(struct bch_fs *c, struct bch_dev *ca,
        if (c) {
                spin_unlock(&c->journal.lock);
                percpu_up_read(&c->usage_lock);
+       } else {
+               preempt_enable();
        }
 }
 
index 697f601c2cdf47ef6c37f8dfe653f6526c80c742..fe29260957704c588d8820a7667b8f98aa4ce475 100644 (file)
@@ -727,6 +727,10 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
        if (!journal_buckets)
                goto err;
 
+       /*
+        * We may be called from the device add path, before the new device has
+        * actually been added to the running filesystem:
+        */
        if (c)
                spin_lock(&c->journal.lock);
 
@@ -743,10 +747,7 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
                long bucket;
 
                if (new_fs) {
-                       percpu_down_read(&c->usage_lock);
                        bucket = bch2_bucket_alloc_new_fs(ca);
-                       percpu_up_read(&c->usage_lock);
-
                        if (bucket < 0) {
                                ret = -ENOSPC;
                                goto err;
@@ -765,6 +766,8 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
                if (c) {
                        percpu_down_read(&c->usage_lock);
                        spin_lock(&c->journal.lock);
+               } else {
+                       preempt_disable();
                }
 
                __array_insert_item(ja->buckets,                ja->nr, ja->last_idx);
@@ -792,6 +795,8 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
                if (c) {
                        spin_unlock(&c->journal.lock);
                        percpu_up_read(&c->usage_lock);
+               } else {
+                       preempt_enable();
                }
 
                if (!new_fs)