From 9f20ed157d521c7a1af0fe01e80d9e0ee880f9f7 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 15 Oct 2020 22:50:48 -0400 Subject: [PATCH] bcachefs: Fix copygc dying on startup The copygc threads errors out and makes the filesystem go RO if it ever tries to run and discovers it has no reserve allocated - which is a problem if it races with the allocator thread and its reserve hasn't been filled yet. The allocator thread doesn't start filling the copygc reserve until after BCH_FS_STARTED has been set, so make sure to wake up the allocator threads after setting that and before starting copygc. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/alloc_background.h | 4 +++- fs/bcachefs/super.c | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/bcachefs/alloc_background.h b/fs/bcachefs/alloc_background.h index f6b9f27f07134..4f462696b747a 100644 --- a/fs/bcachefs/alloc_background.h +++ b/fs/bcachefs/alloc_background.h @@ -61,8 +61,10 @@ static inline void bch2_wake_allocator(struct bch_dev *ca) rcu_read_lock(); p = rcu_dereference(ca->alloc_thread); - if (p) + if (p) { wake_up_process(p); + ca->allocator_state = ALLOCATOR_RUNNING; + } rcu_read_unlock(); } diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 988c678de9fc6..85ba96cb2292e 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -888,6 +888,13 @@ int bch2_fs_start(struct bch_fs *c) set_bit(BCH_FS_STARTED, &c->flags); + /* + * Allocator threads don't start filling copygc reserve until after we + * set BCH_FS_STARTED - wake them now: + */ + for_each_online_member(ca, c, i) + bch2_wake_allocator(ca); + if (c->opts.read_only || c->opts.nochanges) { bch2_fs_read_only(c); } else { -- 2.30.2