Skip to content

Commit 50e029c

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_moving_ctxt_flush_all()
Introduce a new helper to flush all move IOs, and use it in a few places where we should have been. The new helper also drops btree locks before waiting on outstanding move writes, avoiding potential deadlocks. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 6201d91 commit 50e029c

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

fs/bcachefs/move.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,18 @@ void bch2_move_ctxt_wait_for_io(struct moving_context *ctxt)
163163
atomic_read(&ctxt->write_sectors) != sectors_pending);
164164
}
165165

166+
static void bch2_moving_ctxt_flush_all(struct moving_context *ctxt)
167+
{
168+
move_ctxt_wait_event(ctxt, list_empty(&ctxt->reads));
169+
bch2_trans_unlock_long(ctxt->trans);
170+
closure_sync(&ctxt->cl);
171+
}
172+
166173
void bch2_moving_ctxt_exit(struct moving_context *ctxt)
167174
{
168175
struct bch_fs *c = ctxt->trans->c;
169176

170-
move_ctxt_wait_event(ctxt, list_empty(&ctxt->reads));
171-
closure_sync(&ctxt->cl);
177+
bch2_moving_ctxt_flush_all(ctxt);
172178

173179
EBUG_ON(atomic_read(&ctxt->write_sectors));
174180
EBUG_ON(atomic_read(&ctxt->write_ios));
@@ -484,8 +490,8 @@ int bch2_move_ratelimit(struct moving_context *ctxt)
484490
struct bch_fs *c = ctxt->trans->c;
485491
u64 delay;
486492

487-
if (ctxt->wait_on_copygc && !c->copygc_running) {
488-
bch2_trans_unlock_long(ctxt->trans);
493+
if (ctxt->wait_on_copygc && c->copygc_running) {
494+
bch2_moving_ctxt_flush_all(ctxt);
489495
wait_event_killable(c->copygc_running_wq,
490496
!c->copygc_running ||
491497
kthread_should_stop());
@@ -512,7 +518,7 @@ int bch2_move_ratelimit(struct moving_context *ctxt)
512518
schedule_timeout(delay);
513519

514520
if (unlikely(freezing(current))) {
515-
move_ctxt_wait_event(ctxt, list_empty(&ctxt->reads));
521+
bch2_moving_ctxt_flush_all(ctxt);
516522
try_to_freeze();
517523
}
518524
} while (delay);

0 commit comments

Comments
 (0)