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 bch_ratelimit *rate;
15 struct bch_move_stats *stats;
16 struct write_point_specifier wp;
20 /* For waiting on outstanding reads and writes: */
22 struct list_head reads;
24 /* in flight sectors: */
25 atomic_t read_sectors;
26 atomic_t write_sectors;
30 wait_queue_head_t wait;
33 #define move_ctxt_wait_event(_ctxt, _trans, _cond) \
35 bool cond_finished = false; \
36 bch2_moving_ctxt_do_pending_writes(_ctxt, _trans); \
40 __wait_event((_ctxt)->wait, \
41 bch2_moving_ctxt_next_pending_write(_ctxt) || \
42 (cond_finished = (_cond))); \
47 typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,
48 struct bch_io_opts *, struct data_update_opts *);
50 void bch2_moving_ctxt_exit(struct moving_context *);
51 void bch2_moving_ctxt_init(struct moving_context *, struct bch_fs *,
52 struct bch_ratelimit *, struct bch_move_stats *,
53 struct write_point_specifier, bool);
54 struct moving_io *bch2_moving_ctxt_next_pending_write(struct moving_context *);
55 void bch2_moving_ctxt_do_pending_writes(struct moving_context *,
56 struct btree_trans *);
58 int bch2_scan_old_btree_nodes(struct bch_fs *, struct bch_move_stats *);
60 int bch2_move_data(struct bch_fs *,
61 enum btree_id, struct bpos,
62 enum btree_id, struct bpos,
63 struct bch_ratelimit *,
64 struct bch_move_stats *,
65 struct write_point_specifier,
67 move_pred_fn, void *);
69 int __bch2_evacuate_bucket(struct moving_context *,
71 struct data_update_opts);
72 int bch2_evacuate_bucket(struct bch_fs *, struct bpos, int,
73 struct data_update_opts,
74 struct bch_ratelimit *,
75 struct bch_move_stats *,
76 struct write_point_specifier,
78 int bch2_data_job(struct bch_fs *,
79 struct bch_move_stats *,
80 struct bch_ioctl_data);
82 void bch2_move_stats_init(struct bch_move_stats *stats, char *name);
85 #endif /* _BCACHEFS_MOVE_H */