summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-11-24 19:01:45 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2018-12-27 11:38:35 -0500
commit8f519f2751e8d075f100baa9e545a7dbaeb1af86 (patch)
treec0f6fff3cec6397e73ffaddeef0f2e570bac9126
parentdf371a1a7f2fc6263fd0982eb557c0de90e0118f (diff)
bcachefs: New blockcount field for bch_stripe
-rw-r--r--fs/bcachefs/ec.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c
index c8115f63bcdf..755a26039ccc 100644
--- a/fs/bcachefs/ec.c
+++ b/fs/bcachefs/ec.c
@@ -104,22 +104,32 @@ static unsigned stripe_csums_per_device(const struct bch_stripe *s)
1 << s->csum_granularity_bits);
}
-static unsigned stripe_val_u64s(const struct bch_stripe *s)
+static unsigned stripe_csum_offset(const struct bch_stripe *s,
+ unsigned dev, unsigned csum_idx)
{
- unsigned bytes = sizeof(struct bch_stripe) +
+ unsigned csum_bytes = bch_crc_bytes[s->csum_type];
+
+ return sizeof(struct bch_stripe) +
sizeof(struct bch_extent_ptr) * s->nr_blocks +
- bch_crc_bytes[s->csum_type] * s->nr_blocks * stripe_csums_per_device(s);
- return DIV_ROUND_UP(bytes, sizeof(u64));
+ (dev * stripe_csums_per_device(s) + csum_idx) * csum_bytes;
}
-static void *stripe_csum(struct bch_stripe *s, unsigned dev, unsigned csum_idx)
+static unsigned stripe_blockcount_offset(const struct bch_stripe *s,
+ unsigned idx)
{
- unsigned csum_bytes = bch_crc_bytes[s->csum_type];
- void *csums = s->ptrs + s->nr_blocks;
+ return stripe_csum_offset(s, s->nr_blocks, 0) +
+ sizeof(16) * idx;
+}
- BUG_ON(!csum_bytes);
+static unsigned stripe_val_u64s(const struct bch_stripe *s)
+{
+ return DIV_ROUND_UP(stripe_blockcount_offset(s, s->nr_blocks),
+ sizeof(u64));
+}
- return csums + (dev * stripe_csums_per_device(s) + csum_idx) * csum_bytes;
+static void *stripe_csum(struct bch_stripe *s, unsigned dev, unsigned csum_idx)
+{
+ return (void *) s + stripe_csum_offset(s, dev, csum_idx);
}
const char *bch2_stripe_invalid(const struct bch_fs *c, struct bkey_s_c k)
@@ -132,7 +142,8 @@ const char *bch2_stripe_invalid(const struct bch_fs *c, struct bkey_s_c k)
if (bkey_val_bytes(k.k) < sizeof(*s))
return "incorrect value size";
- if (bkey_val_u64s(k.k) != stripe_val_u64s(s))
+ if (bkey_val_bytes(k.k) < sizeof(*s) ||
+ bkey_val_u64s(k.k) < stripe_val_u64s(s))
return "incorrect value size";
return NULL;