Commit 415e5107 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Extra kthread_should_stop() calls for copygc

This fixes a bug where going read-only was taking longer than it should
have due to copygc forgetting to check kthread_should_stop()

Additionally: fix a missing is_kthread check in bch2_move_ratelimit().
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 463086d9
...@@ -441,24 +441,26 @@ int bch2_move_get_io_opts_one(struct btree_trans *trans, ...@@ -441,24 +441,26 @@ int bch2_move_get_io_opts_one(struct btree_trans *trans,
int bch2_move_ratelimit(struct moving_context *ctxt) int bch2_move_ratelimit(struct moving_context *ctxt)
{ {
struct bch_fs *c = ctxt->trans->c; struct bch_fs *c = ctxt->trans->c;
bool is_kthread = current->flags & PF_KTHREAD;
u64 delay; u64 delay;
if (ctxt->wait_on_copygc && c->copygc_running) { if (ctxt->wait_on_copygc && c->copygc_running) {
bch2_moving_ctxt_flush_all(ctxt); bch2_moving_ctxt_flush_all(ctxt);
wait_event_killable(c->copygc_running_wq, wait_event_killable(c->copygc_running_wq,
!c->copygc_running || !c->copygc_running ||
kthread_should_stop()); (is_kthread && kthread_should_stop()));
} }
do { do {
delay = ctxt->rate ? bch2_ratelimit_delay(ctxt->rate) : 0; delay = ctxt->rate ? bch2_ratelimit_delay(ctxt->rate) : 0;
if ((current->flags & PF_KTHREAD) && kthread_should_stop()) if (is_kthread && kthread_should_stop())
return 1; return 1;
if (delay) if (delay)
move_ctxt_wait_event_timeout(ctxt, move_ctxt_wait_event_timeout(ctxt,
freezing(current) || kthread_should_stop(), freezing(current) ||
(is_kthread && kthread_should_stop()),
delay); delay);
if (unlikely(freezing(current))) { if (unlikely(freezing(current))) {
...@@ -633,6 +635,7 @@ int __bch2_evacuate_bucket(struct moving_context *ctxt, ...@@ -633,6 +635,7 @@ int __bch2_evacuate_bucket(struct moving_context *ctxt,
{ {
struct btree_trans *trans = ctxt->trans; struct btree_trans *trans = ctxt->trans;
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
bool is_kthread = current->flags & PF_KTHREAD;
struct bch_io_opts io_opts = bch2_opts_to_inode_opts(c->opts); struct bch_io_opts io_opts = bch2_opts_to_inode_opts(c->opts);
struct btree_iter iter; struct btree_iter iter;
struct bkey_buf sk; struct bkey_buf sk;
...@@ -678,6 +681,9 @@ int __bch2_evacuate_bucket(struct moving_context *ctxt, ...@@ -678,6 +681,9 @@ int __bch2_evacuate_bucket(struct moving_context *ctxt,
} }
while (!(ret = bch2_move_ratelimit(ctxt))) { while (!(ret = bch2_move_ratelimit(ctxt))) {
if (is_kthread && kthread_should_stop())
break;
bch2_trans_begin(trans); bch2_trans_begin(trans);
ret = bch2_get_next_backpointer(trans, bucket, gen, ret = bch2_get_next_backpointer(trans, bucket, gen,
......
...@@ -207,7 +207,7 @@ static int bch2_copygc(struct moving_context *ctxt, ...@@ -207,7 +207,7 @@ static int bch2_copygc(struct moving_context *ctxt,
goto err; goto err;
darray_for_each(buckets, i) { darray_for_each(buckets, i) {
if (unlikely(freezing(current))) if (kthread_should_stop() || freezing(current))
break; break;
f = move_bucket_in_flight_add(buckets_in_flight, *i); f = move_bucket_in_flight_add(buckets_in_flight, *i);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment