bcachefs: Handle transaction restarts in bch2_blacklist_entries_gc()
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 19 Oct 2021 19:11:45 +0000 (15:11 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:14 +0000 (17:09 -0400)
It shouldn't be necessary when we're only using a single iterator and
not doing updates, but that's harder to debug at the moment.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/journal_seq_blacklist.c
fs/bcachefs/migrate.c
fs/bcachefs/move.c

index f84a63a..79bc0e4 100644 (file)
@@ -253,12 +253,21 @@ void bch2_blacklist_entries_gc(struct work_struct *work)
                struct btree_iter iter;
                struct btree *b;
 
-               for_each_btree_node(&trans, iter, i, POS_MIN,
-                                   BTREE_ITER_PREFETCH, b, ret)
-                       if (test_bit(BCH_FS_STOPPING, &c->flags)) {
-                               bch2_trans_exit(&trans);
-                               return;
-                       }
+               bch2_trans_node_iter_init(&trans, &iter, i, POS_MIN,
+                                         0, 0, BTREE_ITER_PREFETCH);
+retry:
+               bch2_trans_begin(&trans);
+
+               b = bch2_btree_iter_peek_node(&iter);
+
+               while (!(ret = PTR_ERR_OR_ZERO(b)) &&
+                      b &&
+                      !test_bit(BCH_FS_STOPPING, &c->flags))
+                       b = bch2_btree_iter_next_node(&iter);
+
+               if (ret == -EINTR)
+                       goto retry;
+
                bch2_trans_iter_exit(&trans, &iter);
        }
 
index 00ba6e1..6defc33 100644 (file)
@@ -136,6 +136,7 @@ static int bch2_dev_metadata_drop(struct bch_fs *c, unsigned dev_idx, int flags)
                bch2_trans_node_iter_init(&trans, &iter, id, POS_MIN, 0, 0,
                                          BTREE_ITER_PREFETCH);
 retry:
+               ret = 0;
                while (bch2_trans_begin(&trans),
                       (b = bch2_btree_iter_peek_node(&iter)) &&
                       !(ret = PTR_ERR_OR_ZERO(b))) {
index af02f2c..4e2bd14 100644 (file)
@@ -886,6 +886,7 @@ static int bch2_move_btree(struct bch_fs *c,
                bch2_trans_node_iter_init(&trans, &iter, id, POS_MIN, 0, 0,
                                          BTREE_ITER_PREFETCH);
 retry:
+               ret = 0;
                while (bch2_trans_begin(&trans),
                       (b = bch2_btree_iter_peek_node(&iter)) &&
                       !(ret = PTR_ERR_OR_ZERO(b))) {