]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Convert migrate to move_data_phys()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 23 Jan 2025 16:45:22 +0000 (11:45 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 15 Mar 2025 01:02:12 +0000 (21:02 -0400)
Iterating over backpointers on a specific device is potentially much
cheaper than walking all filesystem data.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bcachefs_ioctl.h
fs/bcachefs/chardev.c
fs/bcachefs/move.c

index e8a89d375d2f0f08b8a6fc29d35f5c14eb99ff8e..52594e925eb7ea0196040ec3c870b84540928208 100644 (file)
@@ -234,6 +234,11 @@ enum bch_data_event {
        BCH_DATA_EVENT_NR       = 1,
 };
 
+enum data_progress_data_type_special {
+       DATA_PROGRESS_DATA_TYPE_phys    = 254,
+       DATA_PROGRESS_DATA_TYPE_done    = 255,
+};
+
 struct bch_ioctl_data_progress {
        __u8                    data_type;
        __u8                    btree_id;
index b38a3c6fe04c961cf65623247a04627844cfbcb5..57d55b3ddc716bcc236eb3504e38b75e06bd3119 100644 (file)
@@ -315,8 +315,10 @@ static int bch2_data_thread(void *arg)
        ctx->thr.ret = bch2_data_job(ctx->c, &ctx->stats, ctx->arg);
        if (ctx->thr.ret == -BCH_ERR_device_offline)
                ctx->stats.ret = BCH_IOCTL_DATA_EVENT_RET_device_offline;
-       else
+       else {
                ctx->stats.ret = BCH_IOCTL_DATA_EVENT_RET_done;
+               ctx->stats.data_type = (int) DATA_PROGRESS_DATA_TYPE_done;
+       }
        return 0;
 }
 
index 1be1edfbc8302ef7a8d422e84b652fe69169cbb4..12519181026f5a22e84013e30d05965a4335e116 100644 (file)
@@ -859,6 +859,7 @@ static int bch2_move_data_phys(struct bch_fs *c,
 
        bch2_moving_ctxt_init(&ctxt, c, rate, stats, wp, wait_on_copygc);
        ctxt.stats->phys = true;
+       ctxt.stats->data_type = (int) DATA_PROGRESS_DATA_TYPE_phys;
 
        int ret = __bch2_move_data_phys(&ctxt, NULL, dev, start, end, data_types, pred, arg);
        bch2_moving_ctxt_exit(&ctxt);
@@ -1048,14 +1049,6 @@ static bool rereplicate_btree_pred(struct bch_fs *c, void *arg,
        return rereplicate_pred(c, arg, bkey_i_to_s_c(&b->key), io_opts, data_opts);
 }
 
-static bool migrate_btree_pred(struct bch_fs *c, void *arg,
-                              struct btree *b,
-                              struct bch_io_opts *io_opts,
-                              struct data_update_opts *data_opts)
-{
-       return migrate_pred(c, arg, 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
@@ -1218,14 +1211,14 @@ int bch2_data_job(struct bch_fs *c,
 
                stats->data_type = BCH_DATA_journal;
                ret = bch2_journal_flush_device_pins(&c->journal, op.migrate.dev);
-               ret = bch2_move_btree(c, start, end,
-                                     migrate_btree_pred, &op, stats) ?: ret;
-               ret = bch2_move_data(c, start, end,
-                                    NULL,
-                                    stats,
-                                    writepoint_hashed((unsigned long) current),
-                                    true,
-                                    migrate_pred, &op) ?: ret;
+               ret = bch2_move_data_phys(c, op.migrate.dev, 0, U64_MAX,
+                                         ~0,
+                                         NULL,
+                                         stats,
+                                         writepoint_hashed((unsigned long) current),
+                                         true,
+                                         migrate_pred, &op) ?: ret;
+               bch2_btree_interior_updates_flush(c);
                ret = bch2_replicas_gc2(c) ?: ret;
                break;
        case BCH_DATA_OP_rewrite_old_nodes: