1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_MOVE_H
3 #define _BCACHEFS_MOVE_H
5 #include "btree_iter.h"
7 #include "data_update.h"
8 #include "move_types.h"
12 struct moving_context {
14 struct list_head list;
17 struct bch_ratelimit *rate;
18 struct bch_move_stats *stats;
19 struct write_point_specifier wp;
23 /* For waiting on outstanding reads and writes: */
27 struct list_head reads;
30 /* in flight sectors: */
31 atomic_t read_sectors;
32 atomic_t write_sectors;
36 wait_queue_head_t wait;
39 void bch2_verify_bucket_evacuated(struct btree_trans *, struct bpos, int);
41 #define move_ctxt_wait_event(_ctxt, _trans, _cond) \
43 bool cond_finished = false; \
44 bch2_moving_ctxt_do_pending_writes(_ctxt, _trans); \
48 __wait_event((_ctxt)->wait, \
49 bch2_moving_ctxt_next_pending_write(_ctxt) || \
50 (cond_finished = (_cond))); \
55 typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,
56 struct bch_io_opts *, struct data_update_opts *);
58 void bch2_moving_ctxt_exit(struct moving_context *);
59 void bch2_moving_ctxt_init(struct moving_context *, struct bch_fs *,
60 struct bch_ratelimit *, struct bch_move_stats *,
61 struct write_point_specifier, bool);
62 struct moving_io *bch2_moving_ctxt_next_pending_write(struct moving_context *);
63 void bch2_moving_ctxt_do_pending_writes(struct moving_context *,
64 struct btree_trans *);
66 int bch2_scan_old_btree_nodes(struct bch_fs *, struct bch_move_stats *);
68 int bch2_move_data(struct bch_fs *,
69 enum btree_id, struct bpos,
70 enum btree_id, struct bpos,
71 struct bch_ratelimit *,
72 struct bch_move_stats *,
73 struct write_point_specifier,
75 move_pred_fn, void *);
77 int __bch2_evacuate_bucket(struct btree_trans *,
78 struct moving_context *,
79 struct move_bucket_in_flight *,
81 struct data_update_opts);
82 int bch2_evacuate_bucket(struct bch_fs *, struct bpos, int,
83 struct data_update_opts,
84 struct bch_ratelimit *,
85 struct bch_move_stats *,
86 struct write_point_specifier,
88 int bch2_data_job(struct bch_fs *,
89 struct bch_move_stats *,
90 struct bch_ioctl_data);
92 void bch2_move_stats_init(struct bch_move_stats *stats, char *name);
93 void bch2_data_jobs_to_text(struct printbuf *, struct bch_fs *);
94 void bch2_fs_moving_ctxts_to_text(struct printbuf *, struct bch_fs *);
96 void bch2_fs_move_init(struct bch_fs *);
98 #endif /* _BCACHEFS_MOVE_H */