bcachefs: Call bch2_fs_init_rw() early if we'll be going rw
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 15 Jun 2025 20:43:34 +0000 (16:43 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 16 Jun 2025 23:04:48 +0000 (19:04 -0400)
kthread creation checks for pending signals, which is _very_ annoying if
we have to do a long recovery and don't go rw until we've done
significant work.

Check if we'll be going rw and pre-allocate kthreads/workqueues.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/recovery.c
fs/bcachefs/recovery_passes.c
fs/bcachefs/recovery_passes.h
fs/bcachefs/super.c
fs/bcachefs/super.h

index 37f2cc1ec2f8e2414c7776b7d4b2c466d5c55c94..fa5d1ef5bea69a80082b0e84f8519fc2d72a5c2b 100644 (file)
@@ -762,6 +762,16 @@ int bch2_fs_recovery(struct bch_fs *c)
                c->opts.fsck = true;
        }
 
+       if (go_rw_in_recovery(c)) {
+               /*
+                * start workqueues/kworkers early - kthread creation checks for
+                * pending signals, which is _very_ annoying
+                */
+               ret = bch2_fs_init_rw(c);
+               if (ret)
+                       goto err;
+       }
+
        mutex_lock(&c->sb_lock);
        struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
        bool write_sb = false;
index 35ac0d64d73afdd0e405a57610424c9f7adaebfa..c2c18c0a54293c7ca8ee87de9336e1bf65bbed88 100644 (file)
@@ -217,11 +217,7 @@ static int bch2_set_may_go_rw(struct bch_fs *c)
 
        set_bit(BCH_FS_may_go_rw, &c->flags);
 
-       if (keys->nr ||
-           !c->opts.read_only ||
-           !c->sb.clean ||
-           c->opts.recovery_passes ||
-           (c->opts.fsck && !(c->sb.features & BIT_ULL(BCH_FEATURE_no_alloc_info)))) {
+       if (go_rw_in_recovery(c)) {
                if (c->sb.features & BIT_ULL(BCH_FEATURE_no_alloc_info)) {
                        bch_info(c, "mounting a filesystem with no alloc info read-write; will recreate");
                        bch2_reconstruct_alloc(c);
index 260571c7105edc35b6a37bc32dc8e26c3a5db7f7..2117f0ce19229a02168815a14b67eb7131293834 100644 (file)
@@ -17,6 +17,15 @@ enum bch_run_recovery_pass_flags {
        RUN_RECOVERY_PASS_ratelimit     = BIT(1),
 };
 
+static inline bool go_rw_in_recovery(struct bch_fs *c)
+{
+       return (c->journal_keys.nr ||
+               !c->opts.read_only ||
+               !c->sb.clean ||
+               c->opts.recovery_passes ||
+               (c->opts.fsck && !(c->sb.features & BIT_ULL(BCH_FEATURE_no_alloc_info))));
+}
+
 int bch2_run_print_explicit_recovery_pass(struct bch_fs *, enum bch_recovery_pass);
 
 int __bch2_run_explicit_recovery_pass(struct bch_fs *, struct printbuf *,
index a5b97c9c5163545a7ff91a69b53884dc81a059c9..69c097ff54e7803d10441cf07badc4dc0ca1d846 100644 (file)
@@ -210,7 +210,6 @@ static int bch2_dev_alloc(struct bch_fs *, unsigned);
 static int bch2_dev_sysfs_online(struct bch_fs *, struct bch_dev *);
 static void bch2_dev_io_ref_stop(struct bch_dev *, int);
 static void __bch2_dev_read_only(struct bch_fs *, struct bch_dev *);
-static int bch2_fs_init_rw(struct bch_fs *);
 
 struct bch_fs *bch2_dev_to_fs(dev_t dev)
 {
@@ -794,7 +793,7 @@ err:
        return ret;
 }
 
-static int bch2_fs_init_rw(struct bch_fs *c)
+int bch2_fs_init_rw(struct bch_fs *c)
 {
        if (test_bit(BCH_FS_rw_init_done, &c->flags))
                return 0;
@@ -1015,6 +1014,16 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts *opts,
        if (ret)
                goto err;
 
+       if (go_rw_in_recovery(c)) {
+               /*
+                * start workqueues/kworkers early - kthread creation checks for
+                * pending signals, which is _very_ annoying
+                */
+               ret = bch2_fs_init_rw(c);
+               if (ret)
+                       goto err;
+       }
+
 #ifdef CONFIG_UNICODE
        /* Default encoding until we can potentially have more as an option. */
        c->cf_encoding = utf8_load(BCH_FS_DEFAULT_UTF8_ENCODING);
index dc52f06cb2b9ee2c3d58b0877b93b67548e5e1ac..e90bab9afe78bd932457c772bdd5f3bec9e15c30 100644 (file)
@@ -46,6 +46,7 @@ void __bch2_fs_stop(struct bch_fs *);
 void bch2_fs_free(struct bch_fs *);
 void bch2_fs_stop(struct bch_fs *);
 
+int bch2_fs_init_rw(struct bch_fs *);
 int bch2_fs_start(struct bch_fs *);
 struct bch_fs *bch2_fs_open(darray_const_str *, struct bch_opts *);