This is a note to let you know that I've just added the patch titled bcachefs: rebalance should wakeup on shutdown if disabled to the 6.7-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: bcachefs-rebalance-should-wakeup-on-shutdown-if-disabled.patch and it can be found in the queue-6.7 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 0c069781ddfa4e31c169a8eced1ee90b8929d522 Mon Sep 17 00:00:00 2001 From: Daniel Hill <daniel@xxxxxxx> Date: Sun, 26 Nov 2023 19:33:31 +1300 Subject: bcachefs: rebalance should wakeup on shutdown if disabled From: Daniel Hill <daniel@xxxxxxx> commit 0c069781ddfa4e31c169a8eced1ee90b8929d522 upstream. Signed-off-by: Daniel Hill <daniel@xxxxxxx> Signed-off-by: Kent Overstreet <kent.overstreet@xxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/bcachefs/move.c | 2 +- fs/bcachefs/move.h | 1 + fs/bcachefs/rebalance.c | 12 ++++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) --- a/fs/bcachefs/move.c +++ b/fs/bcachefs/move.c @@ -152,7 +152,7 @@ void bch2_move_ctxt_wait_for_io(struct m atomic_read(&ctxt->write_sectors) != sectors_pending); } -static void bch2_moving_ctxt_flush_all(struct moving_context *ctxt) +void bch2_moving_ctxt_flush_all(struct moving_context *ctxt) { move_ctxt_wait_event(ctxt, list_empty(&ctxt->reads)); bch2_trans_unlock_long(ctxt->trans); --- a/fs/bcachefs/move.h +++ b/fs/bcachefs/move.h @@ -81,6 +81,7 @@ void bch2_moving_ctxt_init(struct moving struct write_point_specifier, bool); struct moving_io *bch2_moving_ctxt_next_pending_write(struct moving_context *); void bch2_moving_ctxt_do_pending_writes(struct moving_context *); +void bch2_moving_ctxt_flush_all(struct moving_context *); void bch2_move_ctxt_wait_for_io(struct moving_context *); int bch2_move_ratelimit(struct moving_context *); --- a/fs/bcachefs/rebalance.c +++ b/fs/bcachefs/rebalance.c @@ -317,8 +317,16 @@ static int do_rebalance(struct moving_co BTREE_ID_rebalance_work, POS_MIN, BTREE_ITER_ALL_SNAPSHOTS); - while (!bch2_move_ratelimit(ctxt) && - !kthread_wait_freezable(r->enabled)) { + while (!bch2_move_ratelimit(ctxt)) { + if (!r->enabled) { + bch2_moving_ctxt_flush_all(ctxt); + kthread_wait_freezable(r->enabled || + kthread_should_stop()); + } + + if (kthread_should_stop()) + break; + bch2_trans_begin(trans); ret = bkey_err(k = next_rebalance_entry(trans, &rebalance_work_iter)); Patches currently in stable-queue which might be from daniel@xxxxxxx are queue-6.7/bcachefs-rebalance-should-wakeup-on-shutdown-if-disabled.patch