summaryrefslogtreecommitdiff
path: root/fs/bcachefs/ec.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-11-01 15:10:01 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:12 -0400
commit26609b619fa2301eb7eb5855a7005d99f8a07a73 (patch)
tree40c8e4ec363aad8ede4ffa4e12f7dffb31841a39 /fs/bcachefs/ec.c
parent01a0108f0139a2f6dbace54dd5d592d2d76415c1 (diff)
downloadlwn-26609b619fa2301eb7eb5855a7005d99f8a07a73.tar.gz
lwn-26609b619fa2301eb7eb5855a7005d99f8a07a73.zip
bcachefs: Make bkey types globally unique
this lets us get rid of a lot of extra switch statements - in a lot of places we dispatch on the btree node type, and then the key type, so this is a nice cleanup across a lot of code. Also improve the on disk format versioning stuff. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/ec.c')
-rw-r--r--fs/bcachefs/ec.c60
1 files changed, 25 insertions, 35 deletions
diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c
index 091a1f0a0432..010b9b90f2fc 100644
--- a/fs/bcachefs/ec.c
+++ b/fs/bcachefs/ec.c
@@ -123,49 +123,39 @@ static void *stripe_csum(struct bch_stripe *s, unsigned dev, unsigned csum_idx)
return csums + (dev * stripe_csums_per_device(s) + csum_idx) * csum_bytes;
}
-const char *bch2_ec_key_invalid(const struct bch_fs *c, struct bkey_s_c k)
+const char *bch2_stripe_invalid(const struct bch_fs *c, struct bkey_s_c k)
{
+ const struct bch_stripe *s = bkey_s_c_to_stripe(k).v;
+
if (k.k->p.inode)
return "invalid stripe key";
- switch (k.k->type) {
- case BCH_STRIPE: {
- const struct bch_stripe *s = bkey_s_c_to_stripe(k).v;
-
- if (bkey_val_bytes(k.k) < sizeof(*s))
- return "incorrect value size";
+ if (bkey_val_bytes(k.k) < sizeof(*s))
+ return "incorrect value size";
- if (bkey_val_u64s(k.k) != stripe_val_u64s(s))
- return "incorrect value size";
+ if (bkey_val_u64s(k.k) != stripe_val_u64s(s))
+ return "incorrect value size";
- return NULL;
- }
- default:
- return "invalid type";
- }
+ return NULL;
}
-void bch2_ec_key_to_text(struct printbuf *out, struct bch_fs *c,
+void bch2_stripe_to_text(struct printbuf *out, struct bch_fs *c,
struct bkey_s_c k)
{
- switch (k.k->type) {
- case BCH_STRIPE: {
- const struct bch_stripe *s = bkey_s_c_to_stripe(k).v;
- unsigned i;
-
- pr_buf(out, "algo %u sectors %u blocks %u:%u csum %u gran %u",
- s->algorithm,
- le16_to_cpu(s->sectors),
- s->nr_blocks - s->nr_redundant,
- s->nr_redundant,
- s->csum_type,
- 1U << s->csum_granularity_bits);
-
- for (i = 0; i < s->nr_blocks; i++)
- pr_buf(out, " %u:%llu", s->ptrs[i].dev,
- (u64) s->ptrs[i].offset);
- }
- }
+ const struct bch_stripe *s = bkey_s_c_to_stripe(k).v;
+ unsigned i;
+
+ pr_buf(out, "algo %u sectors %u blocks %u:%u csum %u gran %u",
+ s->algorithm,
+ le16_to_cpu(s->sectors),
+ s->nr_blocks - s->nr_redundant,
+ s->nr_redundant,
+ s->csum_type,
+ 1U << s->csum_granularity_bits);
+
+ for (i = 0; i < s->nr_blocks; i++)
+ pr_buf(out, " %u:%llu", s->ptrs[i].dev,
+ (u64) s->ptrs[i].offset);
}
static int ptr_matches_stripe(struct bch_fs *c,
@@ -454,7 +444,7 @@ int bch2_ec_read_extent(struct bch_fs *c, struct bch_read_bio *rbio)
POS(0, stripe_idx),
BTREE_ITER_SLOTS);
k = bch2_btree_iter_peek_slot(&iter);
- if (btree_iter_err(k) || k.k->type != BCH_STRIPE) {
+ if (btree_iter_err(k) || k.k->type != KEY_TYPE_stripe) {
__bcache_io_error(c,
"error doing reconstruct read: stripe not found");
kfree(buf);
@@ -695,7 +685,7 @@ static void ec_stripe_delete(struct bch_fs *c, size_t idx)
POS(0, idx),
BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
k = bch2_btree_iter_peek_slot(&iter);
- if (btree_iter_err(k) || k.k->type != BCH_STRIPE)
+ if (btree_iter_err(k) || k.k->type != KEY_TYPE_stripe)
goto out;
v = kmalloc(bkey_val_bytes(k.k), GFP_KERNEL);