1 /* SPDX-License-Identifier: GPL-2.0 */
6 #include "keylist_types.h"
8 const char *bch2_stripe_invalid(const struct bch_fs *, struct bkey_s_c);
9 void bch2_stripe_to_text(struct printbuf *, struct bch_fs *,
12 #define bch2_bkey_ops_stripe (struct bkey_ops) { \
13 .key_invalid = bch2_stripe_invalid, \
14 .val_to_text = bch2_stripe_to_text, \
15 .swab = bch2_ptr_swab, \
18 static inline unsigned stripe_csums_per_device(const struct bch_stripe *s)
20 return DIV_ROUND_UP(le16_to_cpu(s->sectors),
21 1 << s->csum_granularity_bits);
24 static inline unsigned stripe_csum_offset(const struct bch_stripe *s,
25 unsigned dev, unsigned csum_idx)
27 unsigned csum_bytes = bch_crc_bytes[s->csum_type];
29 return sizeof(struct bch_stripe) +
30 sizeof(struct bch_extent_ptr) * s->nr_blocks +
31 (dev * stripe_csums_per_device(s) + csum_idx) * csum_bytes;
34 static inline unsigned stripe_blockcount_offset(const struct bch_stripe *s,
37 return stripe_csum_offset(s, s->nr_blocks, 0) +
41 static inline unsigned stripe_blockcount_get(const struct bch_stripe *s,
44 return le16_to_cpup((void *) s + stripe_blockcount_offset(s, idx));
47 static inline void stripe_blockcount_set(struct bch_stripe *s,
48 unsigned idx, unsigned v)
50 __le16 *p = (void *) s + stripe_blockcount_offset(s, idx);
55 static inline unsigned stripe_val_u64s(const struct bch_stripe *s)
57 return DIV_ROUND_UP(stripe_blockcount_offset(s, s->nr_blocks),
61 static inline void *stripe_csum(struct bch_stripe *s,
62 unsigned dev, unsigned csum_idx)
64 return (void *) s + stripe_csum_offset(s, dev, csum_idx);
69 struct ec_stripe_buf {
70 /* might not be buffering the entire stripe: */
73 unsigned long valid[BITS_TO_LONGS(EC_STRIPE_MAX)];
75 void *data[EC_STRIPE_MAX];
78 struct bkey_i_stripe key;
83 struct ec_stripe_head;
85 struct ec_stripe_new {
87 struct ec_stripe_head *h;
89 struct list_head list;
91 /* counts in flight writes, stripe is created when pin == 0 */
96 unsigned long blocks_allocated[BITS_TO_LONGS(EC_STRIPE_MAX)];
98 struct open_buckets blocks;
99 struct open_buckets parity;
102 u64 inline_keys[BKEY_U64s * 8];
104 struct ec_stripe_buf stripe;
107 struct ec_stripe_head {
108 struct list_head list;
111 struct list_head stripes;
117 struct bch_devs_mask devs;
118 unsigned nr_active_devs;
122 struct dev_stripe_state block_stripe;
123 struct dev_stripe_state parity_stripe;
125 struct open_buckets blocks;
126 struct open_buckets parity;
128 struct ec_stripe_new *s;
131 int bch2_ec_read_extent(struct bch_fs *, struct bch_read_bio *);
133 void *bch2_writepoint_ec_buf(struct bch_fs *, struct write_point *);
134 void bch2_ec_add_backpointer(struct bch_fs *, struct write_point *,
135 struct bpos, unsigned);
137 void bch2_ec_bucket_written(struct bch_fs *, struct open_bucket *);
138 void bch2_ec_bucket_cancel(struct bch_fs *, struct open_bucket *);
140 int bch2_ec_stripe_new_alloc(struct bch_fs *, struct ec_stripe_head *);
142 void bch2_ec_stripe_head_put(struct ec_stripe_head *);
143 struct ec_stripe_head *bch2_ec_stripe_head_get(struct bch_fs *, unsigned,
146 void bch2_stripes_heap_update(struct bch_fs *, struct stripe *, size_t);
147 void bch2_stripes_heap_del(struct bch_fs *, struct stripe *, size_t);
148 void bch2_stripes_heap_insert(struct bch_fs *, struct stripe *, size_t);
150 void bch2_ec_stop_dev(struct bch_fs *, struct bch_dev *);
152 void bch2_ec_flush_new_stripes(struct bch_fs *);
155 int bch2_stripes_read(struct bch_fs *, struct journal_keys *);
156 int bch2_stripes_write(struct bch_fs *, unsigned, bool *);
158 int bch2_ec_mem_alloc(struct bch_fs *, bool);
160 int bch2_fs_ec_start(struct bch_fs *);
162 void bch2_fs_ec_exit(struct bch_fs *);
163 int bch2_fs_ec_init(struct bch_fs *);
165 #endif /* _BCACHEFS_EC_H */