diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-04-29 13:24:18 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:10:00 -0400 |
commit | 174f930b8e1cad3915819a46bb20da214f68f2b5 (patch) | |
tree | 413eb321e97d3184f68716c8df8a4eef9c1e5b44 /fs/bcachefs/bkey_methods.c | |
parent | ab158fce47220df20f0fe2360767227328f6765b (diff) |
bcachefs: bkey_ops.min_val_size
This adds a new field to bkey_ops for the minimum size of the value,
which standardizes that check and also enforces the new rule (previously
done somewhat ad-hoc) that we can extend value types by adding new
fields on to the end.
To make that work we do _not_ initialize min_val_size with sizeof,
instead we initialize it to the size of the first version of those
values.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/bkey_methods.c')
-rw-r--r-- | fs/bcachefs/bkey_methods.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/fs/bcachefs/bkey_methods.c b/fs/bcachefs/bkey_methods.c index 72d95831d65d..47f0ab023d64 100644 --- a/fs/bcachefs/bkey_methods.c +++ b/fs/bcachefs/bkey_methods.c @@ -56,17 +56,12 @@ static int empty_val_key_invalid(const struct bch_fs *c, struct bkey_s_c k, static int key_type_cookie_invalid(const struct bch_fs *c, struct bkey_s_c k, unsigned flags, struct printbuf *err) { - if (bkey_val_bytes(k.k) != sizeof(struct bch_cookie)) { - prt_printf(err, "incorrect value size (%zu != %zu)", - bkey_val_bytes(k.k), sizeof(struct bch_cookie)); - return -BCH_ERR_invalid_bkey; - } - return 0; } #define bch2_bkey_ops_cookie ((struct bkey_ops) { \ - .key_invalid = key_type_cookie_invalid, \ + .key_invalid = key_type_cookie_invalid, \ + .min_val_size = 8, \ }) #define bch2_bkey_ops_hash_whiteout ((struct bkey_ops) {\ @@ -126,12 +121,22 @@ const struct bkey_ops bch2_bkey_ops[] = { int bch2_bkey_val_invalid(struct bch_fs *c, struct bkey_s_c k, unsigned flags, struct printbuf *err) { + const struct bkey_ops *ops; + if (k.k->type >= KEY_TYPE_MAX) { prt_printf(err, "invalid type (%u >= %u)", k.k->type, KEY_TYPE_MAX); return -BCH_ERR_invalid_bkey; } - return bch2_bkey_ops[k.k->type].key_invalid(c, k, flags, err); + ops = &bch2_bkey_ops[k.k->type]; + + if (bkey_val_bytes(k.k) < ops->min_val_size) { + prt_printf(err, "bad val size (%zu < %u)", + bkey_val_bytes(k.k), ops->min_val_size); + return -BCH_ERR_invalid_bkey; + } + + return ops->key_invalid(c, k, flags, err); } static unsigned bch2_key_types_allowed[] = { |