diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-01-12 16:44:34 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2021-01-12 16:44:34 -0500 |
commit | 4aed137c424b42420af6abeb597dafaafcff53e6 (patch) | |
tree | 6e4fb8bb57d97c8595f8ffd7917f2f0ca5ff3a45 /libbcachefs/ec.h | |
parent | c1dcd67f7daa03c72c5f9ffac050f9587706163a (diff) |
Update bcachefs sources to 93347f7162 bcachefs: Add btree node prefetching to bch2_btree_and_journal_walk()
Diffstat (limited to 'libbcachefs/ec.h')
-rw-r--r-- | libbcachefs/ec.h | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/libbcachefs/ec.h b/libbcachefs/ec.h index 97a263cf..c3959af4 100644 --- a/libbcachefs/ec.h +++ b/libbcachefs/ec.h @@ -60,9 +60,51 @@ static inline unsigned stripe_val_u64s(const struct bch_stripe *s) } static inline void *stripe_csum(struct bch_stripe *s, - unsigned dev, unsigned csum_idx) + unsigned block, unsigned csum_idx) { - return (void *) s + stripe_csum_offset(s, dev, csum_idx); + EBUG_ON(block >= s->nr_blocks); + EBUG_ON(csum_idx >= stripe_csums_per_device(s)); + + return (void *) s + stripe_csum_offset(s, block, csum_idx); +} + +static inline struct bch_csum stripe_csum_get(struct bch_stripe *s, + unsigned block, unsigned csum_idx) +{ + struct bch_csum csum = { 0 }; + + memcpy(&csum, stripe_csum(s, block, csum_idx), bch_crc_bytes[s->csum_type]); + return csum; +} + +static inline void stripe_csum_set(struct bch_stripe *s, + unsigned block, unsigned csum_idx, + struct bch_csum csum) +{ + memcpy(stripe_csum(s, block, csum_idx), &csum, bch_crc_bytes[s->csum_type]); +} + +static inline bool __bch2_ptr_matches_stripe(const struct bch_stripe *s, + const struct bch_extent_ptr *ptr, + unsigned block) +{ + unsigned nr_data = s->nr_blocks - s->nr_redundant; + + if (block >= nr_data) + return false; + + return ptr->dev == s->ptrs[block].dev && + ptr->gen == s->ptrs[block].gen && + ptr->offset >= s->ptrs[block].offset && + ptr->offset < s->ptrs[block].offset + le16_to_cpu(s->sectors); +} + +static inline bool bch2_ptr_matches_stripe(const struct bch_stripe *s, + struct extent_ptr_decoded p) +{ + BUG_ON(!p.has_ec); + + return __bch2_ptr_matches_stripe(s, &p.ptr, p.ec.block); } struct bch_read_bio; |