1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_MOVE_H
3 #define _BCACHEFS_MOVE_H
5 #include "bcachefs_ioctl.h"
6 #include "btree_iter.h"
8 #include "data_update.h"
9 #include "move_types.h"
13 struct moving_context {
15 struct list_head list;
18 struct bch_ratelimit *rate;
19 struct bch_move_stats *stats;
20 struct write_point_specifier wp;
24 /* For waiting on outstanding reads and writes: */
28 struct list_head reads;
31 /* in flight sectors: */
32 atomic_t read_sectors;
33 atomic_t write_sectors;
37 wait_queue_head_t wait;
40 #define move_ctxt_wait_event(_ctxt, _trans, _cond) \
42 bool cond_finished = false; \
43 bch2_moving_ctxt_do_pending_writes(_ctxt, _trans); \
47 __wait_event((_ctxt)->wait, \
48 bch2_moving_ctxt_next_pending_write(_ctxt) || \
49 (cond_finished = (_cond))); \
54 typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,
55 struct bch_io_opts *, struct data_update_opts *);
57 void bch2_moving_ctxt_exit(struct moving_context *);
58 void bch2_moving_ctxt_init(struct moving_context *, struct bch_fs *,
59 struct bch_ratelimit *, struct bch_move_stats *,
60 struct write_point_specifier, bool);
61 struct moving_io *bch2_moving_ctxt_next_pending_write(struct moving_context *);
62 void bch2_moving_ctxt_do_pending_writes(struct moving_context *,
63 struct btree_trans *);
65 int bch2_scan_old_btree_nodes(struct bch_fs *, struct bch_move_stats *);
67 int bch2_move_data(struct bch_fs *,
68 enum btree_id, struct bpos,
69 enum btree_id, struct bpos,
70 struct bch_ratelimit *,
71 struct bch_move_stats *,
72 struct write_point_specifier,
74 move_pred_fn, void *);
76 int __bch2_evacuate_bucket(struct btree_trans *,
77 struct moving_context *,
78 struct move_bucket_in_flight *,
80 struct data_update_opts);
81 int bch2_evacuate_bucket(struct bch_fs *, struct bpos, int,
82 struct data_update_opts,
83 struct bch_ratelimit *,
84 struct bch_move_stats *,
85 struct write_point_specifier,
87 int bch2_data_job(struct bch_fs *,
88 struct bch_move_stats *,
89 struct bch_ioctl_data);
91 void bch2_move_stats_init(struct bch_move_stats *stats, char *name);
92 void bch2_fs_moving_ctxts_to_text(struct printbuf *, struct bch_fs *);
94 void bch2_fs_move_init(struct bch_fs *);
96 #endif /* _BCACHEFS_MOVE_H */