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 #define move_ctxt_wait_event(_ctxt, _trans, _cond) \
41 bool cond_finished = false; \
42 bch2_moving_ctxt_do_pending_writes(_ctxt, _trans); \
46 __wait_event((_ctxt)->wait, \
47 bch2_moving_ctxt_next_pending_write(_ctxt) || \
48 (cond_finished = (_cond))); \
53 typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,
54 struct bch_io_opts *, struct data_update_opts *);
56 void bch2_moving_ctxt_exit(struct moving_context *);
57 void bch2_moving_ctxt_init(struct moving_context *, struct bch_fs *,
58 struct bch_ratelimit *, struct bch_move_stats *,
59 struct write_point_specifier, bool);
60 struct moving_io *bch2_moving_ctxt_next_pending_write(struct moving_context *);
61 void bch2_moving_ctxt_do_pending_writes(struct moving_context *,
62 struct btree_trans *);
64 int bch2_scan_old_btree_nodes(struct bch_fs *, struct bch_move_stats *);
66 int bch2_move_data(struct bch_fs *,
67 enum btree_id, struct bpos,
68 enum btree_id, struct bpos,
69 struct bch_ratelimit *,
70 struct bch_move_stats *,
71 struct write_point_specifier,
73 move_pred_fn, void *);
75 int __bch2_evacuate_bucket(struct btree_trans *,
76 struct moving_context *,
77 struct move_bucket_in_flight *,
79 struct data_update_opts);
80 int bch2_evacuate_bucket(struct bch_fs *, struct bpos, int,
81 struct data_update_opts,
82 struct bch_ratelimit *,
83 struct bch_move_stats *,
84 struct write_point_specifier,
86 int bch2_data_job(struct bch_fs *,
87 struct bch_move_stats *,
88 struct bch_ioctl_data);
90 void bch2_move_stats_init(struct bch_move_stats *stats, char *name);
91 void bch2_fs_moving_ctxts_to_text(struct printbuf *, struct bch_fs *);
93 void bch2_fs_move_init(struct bch_fs *);
95 #endif /* _BCACHEFS_MOVE_H */