bcachefs: Fix iterator overflow in move path
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 21 Dec 2020 02:42:19 +0000 (21:42 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:50 +0000 (17:08 -0400)
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 <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/io.c
fs/bcachefs/move.c

index a67bd18f6b8cc74227e917be3b7b9449a508e34b..ee2ba1b8aff9b1bd91b8960fe0e24e8f206e8a5c 100644 (file)
@@ -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);
 
index 62a6bbd676ae995065d046b60eb0aad6476b836d..1b1a14d2fa2363d5985d9ddea6b20b34616fb949 100644 (file)
@@ -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);