summaryrefslogtreecommitdiff
path: root/fs/bcachefs/ec.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-03-12 16:55:28 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:55 -0400
commitb3b66e30445e42a94fa171fad99e0b4e4e43c1ac (patch)
treee2a425848894d9e0fddd1b740e72d8ceb1cd62a9 /fs/bcachefs/ec.h
parent53b3e3c0e2f14f661cd61bbc9b82dc9383f783b9 (diff)
bcachefs: Have fsck check for stripe pointers matching stripe
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/ec.h')
-rw-r--r--fs/bcachefs/ec.h37
1 files changed, 26 insertions, 11 deletions
diff --git a/fs/bcachefs/ec.h b/fs/bcachefs/ec.h
index 765baa9d9264..744e51eaf327 100644
--- a/fs/bcachefs/ec.h
+++ b/fs/bcachefs/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;