summaryrefslogtreecommitdiff
path: root/libbcachefs/ec.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-03-12 16:56:43 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2021-03-12 16:56:43 -0500
commite7c4380a892297d2f65e1c317a1b6d4c67378299 (patch)
tree5663bfdcc1c2d67f6b1a8a9da517941cdf44888e /libbcachefs/ec.h
parentfb2d506f6f5c582d89596a2d2d1b2cc7d8374a7a (diff)
Update bcachefs sources to 63924135a1 bcachefs: Have fsck check for stripe pointers matching stripe
Diffstat (limited to 'libbcachefs/ec.h')
-rw-r--r--libbcachefs/ec.h37
1 files changed, 26 insertions, 11 deletions
diff --git a/libbcachefs/ec.h b/libbcachefs/ec.h
index 765baa9d..744e51ea 100644
--- a/libbcachefs/ec.h
+++ b/libbcachefs/ec.h
@@ -84,27 +84,42 @@ static inline void stripe_csum_set(struct bch_stripe *s,
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)
+static inline bool __bch2_ptr_matches_stripe(const struct bch_extent_ptr *stripe_ptr,
+ const struct bch_extent_ptr *data_ptr,
+ unsigned sectors)
+{
+ return data_ptr->dev == stripe_ptr->dev &&
+ data_ptr->gen == stripe_ptr->gen &&
+ data_ptr->offset >= stripe_ptr->offset &&
+ data_ptr->offset < stripe_ptr->offset + sectors;
+}
+
+static inline bool bch2_ptr_matches_stripe(const struct bch_stripe *s,
+ struct extent_ptr_decoded p)
{
unsigned nr_data = s->nr_blocks - s->nr_redundant;
- if (block >= nr_data)
+ BUG_ON(!p.has_ec);
+
+ if (p.ec.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);
+ return __bch2_ptr_matches_stripe(&s->ptrs[p.ec.block], &p.ptr,
+ le16_to_cpu(s->sectors));
}
-static inline bool bch2_ptr_matches_stripe(const struct bch_stripe *s,
- struct extent_ptr_decoded p)
+static inline bool bch2_ptr_matches_stripe_m(const struct stripe *m,
+ struct extent_ptr_decoded p)
{
+ unsigned nr_data = m->nr_blocks - m->nr_redundant;
+
BUG_ON(!p.has_ec);
- return __bch2_ptr_matches_stripe(s, &p.ptr, p.ec.block);
+ if (p.ec.block >= nr_data)
+ return false;
+
+ return __bch2_ptr_matches_stripe(&m->ptrs[p.ec.block], &p.ptr,
+ m->sectors);
}
struct bch_read_bio;