From f0e70018d14ef94a5f680c977591ccb6cf29e9ca Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 20 Dec 2020 21:42:19 -0500 Subject: [PATCH] bcachefs: Fix iterator overflow in move path The move path was calling bch2_bucket_io_time_reset() for cached pointers (which it shouldn't have been), and then not calling bch2_trans_reset() when it got -EINTR (indicating transaction restart). Oops. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/io.c | 6 +++++- fs/bcachefs/move.c | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index a67bd18f6b8cc..ee2ba1b8aff9b 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -2202,7 +2202,11 @@ get_bio: bch2_increment_clock(c, bio_sectors(&rbio->bio), READ); - if (pick.ptr.cached) + /* + * If it's being moved internally, we don't want to flag it as a cache + * hit: + */ + if (pick.ptr.cached && !(flags & BCH_READ_NODECODE)) bch2_bucket_io_time_reset(trans, pick.ptr.dev, PTR_BUCKET_NR(ca, &pick.ptr), READ); diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c index 62a6bbd676ae9..1b1a14d2fa236 100644 --- a/fs/bcachefs/move.c +++ b/fs/bcachefs/move.c @@ -611,6 +611,12 @@ peek: ret2 = bch2_move_extent(&trans, ctxt, wp, io_opts, btree_id, k, data_cmd, data_opts); if (ret2) { + if (ret2 == -EINTR) { + bch2_trans_reset(&trans, 0); + bch2_trans_cond_resched(&trans); + continue; + } + if (ret2 == -ENOMEM) { /* memory allocation failure, wait for some IO to finish */ bch2_move_ctxt_wait_for_io(ctxt); -- 2.30.2