summaryrefslogtreecommitdiff
path: root/fs/bcachefs/bkey_methods.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-07-07 02:23:27 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:10:05 +0300
commit183e9c430ea9775fdd1f7097f309ef61471562fc (patch)
tree604f1353c1c29609c5012e15094e7a83b21a8b38 /fs/bcachefs/bkey_methods.h
parentfaa6cb6c13c7223240366ebbf0217a6191fbfc32 (diff)
downloadlinux-183e9c430ea9775fdd1f7097f309ef61471562fc.tar.xz
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 <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/bkey_methods.h')
-rw-r--r--fs/bcachefs/bkey_methods.h12
1 files changed, 10 insertions, 2 deletions
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)