]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/move.h
Update bcachefs sources to 3856459b1b bcachefs: bch2_btree_iter_peek_node_and_restart()
[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 bch_ratelimit    *rate;
15         struct bch_move_stats   *stats;
16         struct write_point_specifier wp;
17         bool                    wait_on_copygc;
18         bool                    write_error;
19
20         /* For waiting on outstanding reads and writes: */
21         struct closure          cl;
22         struct list_head        reads;
23
24         /* in flight sectors: */
25         atomic_t                read_sectors;
26         atomic_t                write_sectors;
27         atomic_t                read_ios;
28         atomic_t                write_ios;
29
30         wait_queue_head_t       wait;
31 };
32
33 void bch2_verify_bucket_evacuated(struct btree_trans *, struct bpos, int);
34
35 #define move_ctxt_wait_event(_ctxt, _trans, _cond)                      \
36 do {                                                                    \
37         bool cond_finished = false;                                     \
38         bch2_moving_ctxt_do_pending_writes(_ctxt, _trans);              \
39                                                                         \
40         if (_cond)                                                      \
41                 break;                                                  \
42         __wait_event((_ctxt)->wait,                                     \
43                      bch2_moving_ctxt_next_pending_write(_ctxt) ||      \
44                      (cond_finished = (_cond)));                        \
45         if (cond_finished)                                              \
46                 break;                                                  \
47 } while (1)
48
49 typedef bool (*move_pred_fn)(struct bch_fs *, void *, struct bkey_s_c,
50                              struct bch_io_opts *, struct data_update_opts *);
51
52 void bch2_moving_ctxt_exit(struct moving_context *);
53 void bch2_moving_ctxt_init(struct moving_context *, struct bch_fs *,
54                            struct bch_ratelimit *, struct bch_move_stats *,
55                            struct write_point_specifier, bool);
56 struct moving_io *bch2_moving_ctxt_next_pending_write(struct moving_context *);
57 void bch2_moving_ctxt_do_pending_writes(struct moving_context *,
58                                         struct btree_trans *);
59
60 int bch2_scan_old_btree_nodes(struct bch_fs *, struct bch_move_stats *);
61
62 int bch2_move_data(struct bch_fs *,
63                    enum btree_id, struct bpos,
64                    enum btree_id, struct bpos,
65                    struct bch_ratelimit *,
66                    struct bch_move_stats *,
67                    struct write_point_specifier,
68                    bool,
69                    move_pred_fn, void *);
70
71 int __bch2_evacuate_bucket(struct btree_trans *,
72                            struct moving_context *,
73                            struct move_bucket_in_flight *,
74                            struct bpos, int,
75                            struct data_update_opts);
76 int bch2_evacuate_bucket(struct bch_fs *, struct bpos, int,
77                          struct data_update_opts,
78                          struct bch_ratelimit *,
79                          struct bch_move_stats *,
80                          struct write_point_specifier,
81                          bool);
82 int bch2_data_job(struct bch_fs *,
83                   struct bch_move_stats *,
84                   struct bch_ioctl_data);
85
86 void bch2_move_stats_init(struct bch_move_stats *stats, char *name);
87
88
89 #endif /* _BCACHEFS_MOVE_H */