]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/move.h
Update bcachefs sources to 9e7ae5219c bcachefs: Make write points more dynamic
[bcachefs-tools-debian] / libbcachefs / move.h
1 #ifndef _BCACHEFS_MOVE_H
2 #define _BCACHEFS_MOVE_H
3
4 #include "buckets.h"
5 #include "io_types.h"
6
7 enum moving_flag_bitnos {
8         MOVING_FLAG_BITNO_READ = 0,
9         MOVING_FLAG_BITNO_WRITE,
10 };
11
12 #define MOVING_FLAG_READ        (1U << MOVING_FLAG_BITNO_READ)
13 #define MOVING_FLAG_WRITE       (1U << MOVING_FLAG_BITNO_WRITE)
14
15 struct migrate_write {
16         BKEY_PADDED(key);
17         bool                    promote;
18         bool                    move;
19         struct bch_extent_ptr   move_ptr;
20         struct bch_write_op     op;
21 };
22
23 void bch2_migrate_write_init(struct bch_fs *, struct migrate_write *,
24                              struct bch_devs_mask *, struct bkey_s_c,
25                              const struct bch_extent_ptr *, unsigned);
26
27 #define SECTORS_IN_FLIGHT_PER_DEVICE    2048
28
29 struct moving_context {
30         /* Closure for waiting on all reads and writes to complete */
31         struct closure          cl;
32
33         /* Number and types of errors reported */
34         atomic_t                error_count;
35         atomic_t                error_flags;
36
37         /* Key and sector moves issued, updated from submission context */
38         u64                     keys_moved;
39         u64                     sectors_moved;
40
41         /* Rate-limiter counting submitted reads */
42         struct bch_ratelimit    *rate;
43
44         /* Try to avoid reading the following device */
45         struct bch_devs_mask    avoid;
46
47         struct list_head        reads;
48
49         /* Configuration */
50         unsigned                max_sectors_in_flight;
51         atomic_t                sectors_in_flight;
52
53         wait_queue_head_t       wait;
54 };
55
56 struct moving_io {
57         struct list_head        list;
58         struct rb_node          node;
59         struct closure          cl;
60         struct moving_context   *ctxt;
61         struct migrate_write    write;
62         bool                    read_completed;
63
64         struct bch_read_bio     rbio;
65         /* Must be last since it is variable size */
66         struct bio_vec          bi_inline_vecs[0];
67 };
68
69 int bch2_data_move(struct bch_fs *, struct moving_context *,
70                    struct bch_devs_mask *, struct bkey_s_c,
71                    const struct bch_extent_ptr *);
72
73 int bch2_move_ctxt_wait(struct moving_context *);
74 void bch2_move_ctxt_wait_for_io(struct moving_context *);
75
76 void bch2_move_ctxt_exit(struct moving_context *);
77 void bch2_move_ctxt_init(struct moving_context *, struct bch_ratelimit *,
78                         unsigned);
79
80 #endif /* _BCACHEFS_MOVE_H */