bch2_move_data_btree() can already walk btree nodes, and it properly
handles btree roots.

This is a code cleanup - and it fixes the rereplicate2 test, we can now
reliably rerereplicate in one psas.

Signed-off-by: Kent Overstreet <[email protected]>
---
 fs/bcachefs/move.c | 95 ++++++++++++++++++----------------------------
 fs/bcachefs/move.h | 12 ------
 2 files changed, 36 insertions(+), 71 deletions(-)

diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c
index 3f44bb54f91a..3419e406f0c7 100644
--- a/fs/bcachefs/move.c
+++ b/fs/bcachefs/move.c
@@ -795,50 +795,50 @@ int bch2_move_data_btree(struct moving_context *ctxt,
        return ret;
 }
 
-int __bch2_move_data(struct moving_context *ctxt,
-                    struct bbpos start,
-                    struct bbpos end,
-                    move_pred_fn pred, void *arg)
+static int bch2_move_data(struct bch_fs *c,
+                         struct bbpos start,
+                         struct bbpos end,
+                         unsigned min_depth,
+                         struct bch_ratelimit *rate,
+                         struct bch_move_stats *stats,
+                         struct write_point_specifier wp,
+                         bool wait_on_copygc,
+                         move_pred_fn pred, void *arg)
 {
-       struct bch_fs *c = ctxt->trans->c;
-       enum btree_id id;
        int ret = 0;
 
-       for (id = start.btree;
+       struct moving_context ctxt;
+       bch2_moving_ctxt_init(&ctxt, c, rate, stats, wp, wait_on_copygc);
+
+       for (enum btree_id id = start.btree;
             id <= min_t(unsigned, end.btree, btree_id_nr_alive(c) - 1);
             id++) {
-               ctxt->stats->pos = BBPOS(id, POS_MIN);
+               ctxt.stats->pos = BBPOS(id, POS_MIN);
 
-               if (!btree_type_has_ptrs(id) ||
-                   !bch2_btree_id_root(c, id)->b)
+               if (!bch2_btree_id_root(c, id)->b)
                        continue;
 
-               ret = bch2_move_data_btree(ctxt,
-                                      id == start.btree ? start.pos : POS_MIN,
-                                      id == end.btree   ? end.pos   : POS_MAX,
-                                      pred, arg, id, 0);
+               unsigned min_depth_this_btree = min_depth;
+
+               if (!btree_type_has_ptrs(id))
+                       min_depth_this_btree = max(min_depth_this_btree, 1);
+
+               for (unsigned level = min_depth_this_btree;
+                    level < BTREE_MAX_DEPTH;
+                    level++) {
+                       ret = bch2_move_data_btree(&ctxt,
+                                                  id == start.btree ? 
start.pos : POS_MIN,
+                                                  id == end.btree   ? end.pos  
 : POS_MAX,
+                                                  pred, arg, id, level);
+                       if (ret)
+                               break;
+               }
+
                if (ret)
                        break;
        }
 
-       return ret;
-}
-
-int bch2_move_data(struct bch_fs *c,
-                  struct bbpos start,
-                  struct bbpos end,
-                  struct bch_ratelimit *rate,
-                  struct bch_move_stats *stats,
-                  struct write_point_specifier wp,
-                  bool wait_on_copygc,
-                  move_pred_fn pred, void *arg)
-{
-       struct moving_context ctxt;
-
-       bch2_moving_ctxt_init(&ctxt, c, rate, stats, wp, wait_on_copygc);
-       int ret = __bch2_move_data(&ctxt, start, end, pred, arg);
        bch2_moving_ctxt_exit(&ctxt);
-
        return ret;
 }
 
@@ -1206,14 +1206,6 @@ static bool migrate_pred(struct bch_fs *c, void *arg,
        return data_opts->rewrite_ptrs != 0;
 }
 
-static bool rereplicate_btree_pred(struct bch_fs *c, void *arg,
-                                  struct btree *b,
-                                  struct bch_io_opts *io_opts,
-                                  struct data_update_opts *data_opts)
-{
-       return rereplicate_pred(c, arg, b->c.btree_id, bkey_i_to_s_c(&b->key), 
io_opts, data_opts);
-}
-
 /*
  * Ancient versions of bcachefs produced packed formats which could represent
  * keys that the in memory format cannot represent; this checks for those
@@ -1293,15 +1285,6 @@ static bool drop_extra_replicas_pred(struct bch_fs *c, 
void *arg,
        return data_opts->kill_ptrs != 0;
 }
 
-static bool drop_extra_replicas_btree_pred(struct bch_fs *c, void *arg,
-                                  struct btree *b,
-                                  struct bch_io_opts *io_opts,
-                                  struct data_update_opts *data_opts)
-{
-       return drop_extra_replicas_pred(c, arg, b->c.btree_id, 
bkey_i_to_s_c(&b->key),
-                                       io_opts, data_opts);
-}
-
 static bool scrub_pred(struct bch_fs *c, void *_arg,
                       enum btree_id btree, struct bkey_s_c k,
                       struct bch_io_opts *io_opts,
@@ -1359,11 +1342,7 @@ int bch2_data_job(struct bch_fs *c,
        case BCH_DATA_OP_rereplicate:
                stats->data_type = BCH_DATA_journal;
                ret = bch2_journal_flush_device_pins(&c->journal, -1);
-               ret = bch2_move_btree(c, start, end,
-                                     rereplicate_btree_pred, c, stats) ?: ret;
-               ret = bch2_move_data(c, start, end,
-                                    NULL,
-                                    stats,
+               ret = bch2_move_data(c, start, end, 0, NULL, stats,
                                     writepoint_hashed((unsigned long) current),
                                     true,
                                     rereplicate_pred, c) ?: ret;
@@ -1389,12 +1368,10 @@ int bch2_data_job(struct bch_fs *c,
                ret = bch2_scan_old_btree_nodes(c, stats);
                break;
        case BCH_DATA_OP_drop_extra_replicas:
-               ret = bch2_move_btree(c, start, end,
-                               drop_extra_replicas_btree_pred, c, stats) ?: 
ret;
-               ret = bch2_move_data(c, start, end, NULL, stats,
-                               writepoint_hashed((unsigned long) current),
-                               true,
-                               drop_extra_replicas_pred, c) ?: ret;
+               ret = bch2_move_data(c, start, end, 0, NULL, stats,
+                                    writepoint_hashed((unsigned long) current),
+                                    true,
+                                    drop_extra_replicas_pred, c) ?: ret;
                ret = bch2_replicas_gc2(c) ?: ret;
                break;
        default:
diff --git a/fs/bcachefs/move.h b/fs/bcachefs/move.h
index fe92ca6d418d..481026ff99ab 100644
--- a/fs/bcachefs/move.h
+++ b/fs/bcachefs/move.h
@@ -128,18 +128,6 @@ struct bch_io_opts *bch2_move_get_io_opts(struct 
btree_trans *,
 
 int bch2_move_data_btree(struct moving_context *, struct bpos, struct bpos,
                         move_pred_fn, void *, enum btree_id, unsigned);
-int __bch2_move_data(struct moving_context *,
-                    struct bbpos,
-                    struct bbpos,
-                    move_pred_fn, void *);
-int bch2_move_data(struct bch_fs *,
-                  struct bbpos start,
-                  struct bbpos end,
-                  struct bch_ratelimit *,
-                  struct bch_move_stats *,
-                  struct write_point_specifier,
-                  bool,
-                  move_pred_fn, void *);
 
 int bch2_move_data_phys(struct bch_fs *, unsigned, u64, u64, unsigned,
                        struct bch_ratelimit *, struct bch_move_stats *,
-- 
2.50.0


Reply via email to