Commit 01e95645 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: x-macro-ify bch_data_ops enum

This will let us add an enum -> string table for a to_text() fn.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 225879f4
...@@ -173,12 +173,17 @@ struct bch_ioctl_disk_set_state { ...@@ -173,12 +173,17 @@ struct bch_ioctl_disk_set_state {
__u64 dev; __u64 dev;
}; };
#define BCH_DATA_OPS() \
x(scrub, 0) \
x(rereplicate, 1) \
x(migrate, 2) \
x(rewrite_old_nodes, 3)
enum bch_data_ops { enum bch_data_ops {
BCH_DATA_OP_SCRUB = 0, #define x(t, n) BCH_DATA_OP_##t = n,
BCH_DATA_OP_REREPLICATE = 1, BCH_DATA_OPS()
BCH_DATA_OP_MIGRATE = 2, #undef x
BCH_DATA_OP_REWRITE_OLD_NODES = 3, BCH_DATA_OP_NR
BCH_DATA_OP_NR = 4,
}; };
/* /*
......
...@@ -27,6 +27,13 @@ ...@@ -27,6 +27,13 @@
#include <linux/ioprio.h> #include <linux/ioprio.h>
#include <linux/kthread.h> #include <linux/kthread.h>
const char * const bch2_data_ops_strs[] = {
#define x(t, n, ...) [n] = #t,
BCH_DATA_OPS()
#undef x
NULL
};
static void trace_move_extent2(struct bch_fs *c, struct bkey_s_c k) static void trace_move_extent2(struct bch_fs *c, struct bkey_s_c k)
{ {
if (trace_move_extent_enabled()) { if (trace_move_extent_enabled()) {
...@@ -211,7 +218,7 @@ void bch2_move_stats_exit(struct bch_move_stats *stats, struct bch_fs *c) ...@@ -211,7 +218,7 @@ void bch2_move_stats_exit(struct bch_move_stats *stats, struct bch_fs *c)
trace_move_data(c, stats); trace_move_data(c, stats);
} }
void bch2_move_stats_init(struct bch_move_stats *stats, char *name) void bch2_move_stats_init(struct bch_move_stats *stats, const char *name)
{ {
memset(stats, 0, sizeof(*stats)); memset(stats, 0, sizeof(*stats));
stats->data_type = BCH_DATA_user; stats->data_type = BCH_DATA_user;
...@@ -1012,9 +1019,13 @@ int bch2_data_job(struct bch_fs *c, ...@@ -1012,9 +1019,13 @@ int bch2_data_job(struct bch_fs *c,
{ {
int ret = 0; int ret = 0;
if (op.op >= BCH_DATA_OP_NR)
return -EINVAL;
bch2_move_stats_init(stats, bch2_data_ops_strs[op.op]);
switch (op.op) { switch (op.op) {
case BCH_DATA_OP_REREPLICATE: case BCH_DATA_OP_rereplicate:
bch2_move_stats_init(stats, "rereplicate");
stats->data_type = BCH_DATA_journal; stats->data_type = BCH_DATA_journal;
ret = bch2_journal_flush_device_pins(&c->journal, -1); ret = bch2_journal_flush_device_pins(&c->journal, -1);
...@@ -1033,14 +1044,11 @@ int bch2_data_job(struct bch_fs *c, ...@@ -1033,14 +1044,11 @@ int bch2_data_job(struct bch_fs *c,
true, true,
rereplicate_pred, c) ?: ret; rereplicate_pred, c) ?: ret;
ret = bch2_replicas_gc2(c) ?: ret; ret = bch2_replicas_gc2(c) ?: ret;
bch2_move_stats_exit(stats, c);
break; break;
case BCH_DATA_OP_MIGRATE: case BCH_DATA_OP_migrate:
if (op.migrate.dev >= c->sb.nr_devices) if (op.migrate.dev >= c->sb.nr_devices)
return -EINVAL; return -EINVAL;
bch2_move_stats_init(stats, "migrate");
stats->data_type = BCH_DATA_journal; stats->data_type = BCH_DATA_journal;
ret = bch2_journal_flush_device_pins(&c->journal, op.migrate.dev); ret = bch2_journal_flush_device_pins(&c->journal, op.migrate.dev);
...@@ -1059,18 +1067,15 @@ int bch2_data_job(struct bch_fs *c, ...@@ -1059,18 +1067,15 @@ int bch2_data_job(struct bch_fs *c,
true, true,
migrate_pred, &op) ?: ret; migrate_pred, &op) ?: ret;
ret = bch2_replicas_gc2(c) ?: ret; ret = bch2_replicas_gc2(c) ?: ret;
bch2_move_stats_exit(stats, c);
break; break;
case BCH_DATA_OP_REWRITE_OLD_NODES: case BCH_DATA_OP_rewrite_old_nodes:
bch2_move_stats_init(stats, "rewrite_old_nodes");
ret = bch2_scan_old_btree_nodes(c, stats); ret = bch2_scan_old_btree_nodes(c, stats);
bch2_move_stats_exit(stats, c);
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
} }
bch2_move_stats_exit(stats, c);
return ret; return ret;
} }
......
...@@ -75,6 +75,8 @@ do { \ ...@@ -75,6 +75,8 @@ do { \
typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c, typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,
struct bch_io_opts *, struct data_update_opts *); struct bch_io_opts *, struct data_update_opts *);
extern const char * const bch2_data_ops_strs[];
void bch2_moving_ctxt_exit(struct moving_context *); void bch2_moving_ctxt_exit(struct moving_context *);
void bch2_moving_ctxt_init(struct moving_context *, struct bch_fs *, void bch2_moving_ctxt_init(struct moving_context *, struct bch_fs *,
struct bch_ratelimit *, struct bch_move_stats *, struct bch_ratelimit *, struct bch_move_stats *,
...@@ -149,7 +151,7 @@ int bch2_data_job(struct bch_fs *, ...@@ -149,7 +151,7 @@ int bch2_data_job(struct bch_fs *,
void bch2_move_stats_to_text(struct printbuf *, struct bch_move_stats *); void bch2_move_stats_to_text(struct printbuf *, struct bch_move_stats *);
void bch2_move_stats_exit(struct bch_move_stats *, struct bch_fs *); void bch2_move_stats_exit(struct bch_move_stats *, struct bch_fs *);
void bch2_move_stats_init(struct bch_move_stats *, char *); void bch2_move_stats_init(struct bch_move_stats *, const char *);
void bch2_fs_moving_ctxts_to_text(struct printbuf *, struct bch_fs *); void bch2_fs_moving_ctxts_to_text(struct printbuf *, struct bch_fs *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment