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