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