]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/move.h
Update bcachefs sources to fd381c355c bcachefs: Fix a null ptr deref in fsck check_ex...
[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 void bch2_verify_bucket_evacuated(struct btree_trans *, struct bpos, int);
40
41 #define move_ctxt_wait_event(_ctxt, _trans, _cond)                      \
42 do {                                                                    \
43         bool cond_finished = false;                                     \
44         bch2_moving_ctxt_do_pending_writes(_ctxt, _trans);              \
45                                                                         \
46         if (_cond)                                                      \
47                 break;                                                  \
48         __wait_event((_ctxt)->wait,                                     \
49                      bch2_moving_ctxt_next_pending_write(_ctxt) ||      \
50                      (cond_finished = (_cond)));                        \
51         if (cond_finished)                                              \
52                 break;                                                  \
53 } while (1)
54
55 typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,
56                              struct bch_io_opts *, struct data_update_opts *);
57
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 *);
65
66 int bch2_scan_old_btree_nodes(struct bch_fs *, struct bch_move_stats *);
67
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,
74                    bool,
75                    move_pred_fn, void *);
76
77 int __bch2_evacuate_bucket(struct btree_trans *,
78                            struct moving_context *,
79                            struct move_bucket_in_flight *,
80                            struct bpos, int,
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,
87                          bool);
88 int bch2_data_job(struct bch_fs *,
89                   struct bch_move_stats *,
90                   struct bch_ioctl_data);
91
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 *);
95
96 void bch2_fs_move_init(struct bch_fs *);
97
98 #endif /* _BCACHEFS_MOVE_H */