]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/move.h
Update bcachefs sources to 717b356d1d bcachefs: Convert journal validation to bkey_in...
[bcachefs-tools-debian] / libbcachefs / move.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_MOVE_H
3 #define _BCACHEFS_MOVE_H
4
5 #include "btree_iter.h"
6 #include "buckets.h"
7 #include "data_update.h"
8 #include "move_types.h"
9
10 struct bch_read_bio;
11
12 struct moving_context {
13         struct bch_fs           *c;
14         struct list_head        list;
15         void                    *fn;
16
17         struct bch_ratelimit    *rate;
18         struct bch_move_stats   *stats;
19         struct write_point_specifier wp;
20         bool                    wait_on_copygc;
21         bool                    write_error;
22
23         /* For waiting on outstanding reads and writes: */
24         struct closure          cl;
25
26         struct mutex            lock;
27         struct list_head        reads;
28         struct list_head        ios;
29
30         /* in flight sectors: */
31         atomic_t                read_sectors;
32         atomic_t                write_sectors;
33         atomic_t                read_ios;
34         atomic_t                write_ios;
35
36         wait_queue_head_t       wait;
37 };
38
39 #define move_ctxt_wait_event(_ctxt, _trans, _cond)                      \
40 do {                                                                    \
41         bool cond_finished = false;                                     \
42         bch2_moving_ctxt_do_pending_writes(_ctxt, _trans);              \
43                                                                         \
44         if (_cond)                                                      \
45                 break;                                                  \
46         __wait_event((_ctxt)->wait,                                     \
47                      bch2_moving_ctxt_next_pending_write(_ctxt) ||      \
48                      (cond_finished = (_cond)));                        \
49         if (cond_finished)                                              \
50                 break;                                                  \
51 } while (1)
52
53 typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,
54                              struct bch_io_opts *, struct data_update_opts *);
55
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 *);
63
64 int bch2_scan_old_btree_nodes(struct bch_fs *, struct bch_move_stats *);
65
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,
72                    bool,
73                    move_pred_fn, void *);
74
75 int __bch2_evacuate_bucket(struct btree_trans *,
76                            struct moving_context *,
77                            struct move_bucket_in_flight *,
78                            struct bpos, int,
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,
85                          bool);
86 int bch2_data_job(struct bch_fs *,
87                   struct bch_move_stats *,
88                   struct bch_ioctl_data);
89
90 void bch2_move_stats_init(struct bch_move_stats *stats, char *name);
91 void bch2_data_jobs_to_text(struct printbuf *, struct bch_fs *);
92 void bch2_fs_moving_ctxts_to_text(struct printbuf *, struct bch_fs *);
93
94 void bch2_fs_move_init(struct bch_fs *);
95
96 #endif /* _BCACHEFS_MOVE_H */