]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/ec.h
Update bcachefs sources to da7fefde29 bcachefs: shim for userspace raid library
[bcachefs-tools-debian] / libbcachefs / ec.h
1 #ifndef _BCACHEFS_EC_H
2 #define _BCACHEFS_EC_H
3
4 #include "ec_types.h"
5 #include "keylist_types.h"
6
7 const char *bch2_ec_key_invalid(const struct bch_fs *, struct bkey_s_c);
8 void bch2_ec_key_to_text(struct printbuf *, struct bch_fs *,
9                          struct bkey_s_c);
10
11 #define bch2_bkey_ec_ops (struct bkey_ops) {            \
12         .key_invalid    = bch2_ec_key_invalid,          \
13         .val_to_text    = bch2_ec_key_to_text,          \
14 }
15
16 struct bch_read_bio;
17
18 struct ec_stripe_buf {
19         /* might not be buffering the entire stripe: */
20         unsigned                offset;
21         unsigned                size;
22         unsigned long           valid[BITS_TO_LONGS(EC_STRIPE_MAX)];
23
24         void                    *data[EC_STRIPE_MAX];
25
26         union {
27                 struct bkey_i_stripe    key;
28                 u64                     pad[255];
29         };
30 };
31
32 struct ec_stripe_head;
33
34 struct ec_stripe_new {
35         struct bch_fs           *c;
36         struct ec_stripe_head   *h;
37         struct mutex            lock;
38         struct list_head        list;
39
40         /* counts in flight writes, stripe is created when pin == 0 */
41         atomic_t                pin;
42
43         int                     err;
44
45         unsigned long           blocks_allocated[BITS_TO_LONGS(EC_STRIPE_MAX)];
46
47         struct open_buckets     blocks;
48         struct open_buckets     parity;
49
50         struct keylist          keys;
51         u64                     inline_keys[BKEY_U64s * 8];
52
53         struct ec_stripe_buf    stripe;
54 };
55
56 struct ec_stripe_head {
57         struct list_head        list;
58         struct mutex            lock;
59
60         struct list_head        stripes;
61
62         unsigned                target;
63         unsigned                algo;
64         unsigned                redundancy;
65
66         struct bch_devs_mask    devs;
67         unsigned                nr_active_devs;
68
69         unsigned                blocksize;
70
71         struct dev_stripe_state block_stripe;
72         struct dev_stripe_state parity_stripe;
73
74         struct open_buckets     blocks;
75         struct open_buckets     parity;
76
77         struct ec_stripe_new    *s;
78 };
79
80 int bch2_ec_read_extent(struct bch_fs *, struct bch_read_bio *);
81
82 void *bch2_writepoint_ec_buf(struct bch_fs *, struct write_point *);
83 void bch2_ec_add_backpointer(struct bch_fs *, struct write_point *,
84                              struct bpos, unsigned);
85
86 void bch2_ec_bucket_written(struct bch_fs *, struct open_bucket *);
87 void bch2_ec_bucket_cancel(struct bch_fs *, struct open_bucket *);
88
89 int bch2_ec_stripe_new_alloc(struct bch_fs *, struct ec_stripe_head *);
90
91 void bch2_ec_stripe_head_put(struct ec_stripe_head *);
92 struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *, unsigned,
93                                                unsigned, unsigned);
94
95 void bch2_stripes_heap_update(struct bch_fs *, struct ec_stripe *, size_t);
96 void bch2_stripes_heap_del(struct bch_fs *, struct ec_stripe *, size_t);
97 void bch2_stripes_heap_insert(struct bch_fs *, struct ec_stripe *, size_t);
98
99 void bch2_ec_stop_dev(struct bch_fs *, struct bch_dev *);
100
101 void bch2_ec_flush_new_stripes(struct bch_fs *);
102
103 int bch2_fs_ec_start(struct bch_fs *);
104
105 void bch2_fs_ec_exit(struct bch_fs *);
106 int bch2_fs_ec_init(struct bch_fs *);
107
108 #endif /* _BCACHEFS_EC_H */