Skip to content

Commit 1cddad0

Browse files
author
Kent Overstreet
committed
bcachefs: Call bch2_fs_init_rw() early if we'll be going rw
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>
1 parent f2a701f commit 1cddad0

5 files changed

Lines changed: 32 additions & 7 deletions

File tree

fs/bcachefs/recovery.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,16 @@ int bch2_fs_recovery(struct bch_fs *c)
762762
c->opts.fsck = true;
763763
}
764764

765+
if (go_rw_in_recovery(c)) {
766+
/*
767+
* start workqueues/kworkers early - kthread creation checks for
768+
* pending signals, which is _very_ annoying
769+
*/
770+
ret = bch2_fs_init_rw(c);
771+
if (ret)
772+
goto err;
773+
}
774+
765775
mutex_lock(&c->sb_lock);
766776
struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
767777
bool write_sb = false;

fs/bcachefs/recovery_passes.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,7 @@ static int bch2_set_may_go_rw(struct bch_fs *c)
217217

218218
set_bit(BCH_FS_may_go_rw, &c->flags);
219219

220-
if (keys->nr ||
221-
!c->opts.read_only ||
222-
!c->sb.clean ||
223-
c->opts.recovery_passes ||
224-
(c->opts.fsck && !(c->sb.features & BIT_ULL(BCH_FEATURE_no_alloc_info)))) {
220+
if (go_rw_in_recovery(c)) {
225221
if (c->sb.features & BIT_ULL(BCH_FEATURE_no_alloc_info)) {
226222
bch_info(c, "mounting a filesystem with no alloc info read-write; will recreate");
227223
bch2_reconstruct_alloc(c);

fs/bcachefs/recovery_passes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ enum bch_run_recovery_pass_flags {
1717
RUN_RECOVERY_PASS_ratelimit = BIT(1),
1818
};
1919

20+
static inline bool go_rw_in_recovery(struct bch_fs *c)
21+
{
22+
return (c->journal_keys.nr ||
23+
!c->opts.read_only ||
24+
!c->sb.clean ||
25+
c->opts.recovery_passes ||
26+
(c->opts.fsck && !(c->sb.features & BIT_ULL(BCH_FEATURE_no_alloc_info))));
27+
}
28+
2029
int bch2_run_print_explicit_recovery_pass(struct bch_fs *, enum bch_recovery_pass);
2130

2231
int __bch2_run_explicit_recovery_pass(struct bch_fs *, struct printbuf *,

fs/bcachefs/super.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ static int bch2_dev_alloc(struct bch_fs *, unsigned);
210210
static int bch2_dev_sysfs_online(struct bch_fs *, struct bch_dev *);
211211
static void bch2_dev_io_ref_stop(struct bch_dev *, int);
212212
static void __bch2_dev_read_only(struct bch_fs *, struct bch_dev *);
213-
static int bch2_fs_init_rw(struct bch_fs *);
214213

215214
struct bch_fs *bch2_dev_to_fs(dev_t dev)
216215
{
@@ -794,7 +793,7 @@ static int bch2_fs_online(struct bch_fs *c)
794793
return ret;
795794
}
796795

797-
static int bch2_fs_init_rw(struct bch_fs *c)
796+
int bch2_fs_init_rw(struct bch_fs *c)
798797
{
799798
if (test_bit(BCH_FS_rw_init_done, &c->flags))
800799
return 0;
@@ -1015,6 +1014,16 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts *opts,
10151014
if (ret)
10161015
goto err;
10171016

1017+
if (go_rw_in_recovery(c)) {
1018+
/*
1019+
* start workqueues/kworkers early - kthread creation checks for
1020+
* pending signals, which is _very_ annoying
1021+
*/
1022+
ret = bch2_fs_init_rw(c);
1023+
if (ret)
1024+
goto err;
1025+
}
1026+
10181027
#ifdef CONFIG_UNICODE
10191028
/* Default encoding until we can potentially have more as an option. */
10201029
c->cf_encoding = utf8_load(BCH_FS_DEFAULT_UTF8_ENCODING);

fs/bcachefs/super.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void __bch2_fs_stop(struct bch_fs *);
4646
void bch2_fs_free(struct bch_fs *);
4747
void bch2_fs_stop(struct bch_fs *);
4848

49+
int bch2_fs_init_rw(struct bch_fs *);
4950
int bch2_fs_start(struct bch_fs *);
5051
struct bch_fs *bch2_fs_open(darray_const_str *, struct bch_opts *);
5152

0 commit comments

Comments
 (0)