From 183e9c430ea9775fdd1f7097f309ef61471562fc Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 6 Jul 2023 19:23:27 -0400 Subject: bcachefs: Allow for unknown key types This adds a new helper for lookups bkey_ops for a given key type, which returns a null bkey_ops for unknown key types; various bkey_ops users are tweaked as well to handle unknown key types. Signed-off-by: Kent Overstreet --- fs/bcachefs/bkey_methods.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'fs/bcachefs/bkey_methods.h') diff --git a/fs/bcachefs/bkey_methods.h b/fs/bcachefs/bkey_methods.h index a65756e306b0..32b86c74cc9a 100644 --- a/fs/bcachefs/bkey_methods.h +++ b/fs/bcachefs/bkey_methods.h @@ -11,6 +11,7 @@ struct bkey; enum btree_node_type; extern const char * const bch2_bkey_types[]; +extern const struct bkey_ops bch2_bkey_null_ops; /* * key_invalid: checks validity of @k, returns 0 if good or -EINVAL if bad. If @@ -41,6 +42,13 @@ struct bkey_ops { extern const struct bkey_ops bch2_bkey_ops[]; +static inline const struct bkey_ops *bch2_bkey_type_ops(enum bch_bkey_type type) +{ + return likely(type < KEY_TYPE_MAX) + ? &bch2_bkey_ops[type] + : &bch2_bkey_null_ops; +} + #define BKEY_INVALID_FROM_JOURNAL (1 << 1) int bch2_bkey_val_invalid(struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *); @@ -75,7 +83,7 @@ static inline int bch2_mark_key(struct btree_trans *trans, struct bkey_s_c old, struct bkey_s_c new, unsigned flags) { - const struct bkey_ops *ops = &bch2_bkey_ops[old.k->type ?: new.k->type]; + const struct bkey_ops *ops = bch2_bkey_type_ops(old.k->type ?: new.k->type); return ops->atomic_trigger ? ops->atomic_trigger(trans, btree, level, old, new, flags) @@ -125,7 +133,7 @@ static inline int bch2_trans_mark_key(struct btree_trans *trans, struct bkey_s_c old, struct bkey_i *new, unsigned flags) { - const struct bkey_ops *ops = &bch2_bkey_ops[old.k->type ?: new->k.type]; + const struct bkey_ops *ops = bch2_bkey_type_ops(old.k->type ?: new->k.type); return ops->trans_trigger ? ops->trans_trigger(trans, btree_id, level, old, new, flags) -- cgit v1.2.3