diff options
Diffstat (limited to 'libbcachefs/bkey_methods.h')
-rw-r--r-- | libbcachefs/bkey_methods.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/libbcachefs/bkey_methods.h b/libbcachefs/bkey_methods.h index c2bd72f5..36a08e30 100644 --- a/libbcachefs/bkey_methods.h +++ b/libbcachefs/bkey_methods.h @@ -11,6 +11,13 @@ struct bkey; enum btree_node_type; extern const char * const bch2_bkey_types[]; +extern const struct bkey_ops bch2_bkey_null_ops; + +enum bkey_invalid_flags { + BKEY_INVALID_WRITE = (1U << 0), + BKEY_INVALID_COMMIT = (1U << 1), + BKEY_INVALID_JOURNAL = (1U << 2), +}; /* * key_invalid: checks validity of @k, returns 0 if good or -EINVAL if bad. If @@ -21,7 +28,7 @@ extern const char * const bch2_bkey_types[]; */ struct bkey_ops { int (*key_invalid)(const struct bch_fs *c, struct bkey_s_c k, - unsigned flags, struct printbuf *err); + enum bkey_invalid_flags flags, struct printbuf *err); void (*val_to_text)(struct printbuf *, struct bch_fs *, struct bkey_s_c); void (*swab)(struct bkey_s); @@ -41,7 +48,12 @@ struct bkey_ops { extern const struct bkey_ops bch2_bkey_ops[]; -#define BKEY_INVALID_FROM_JOURNAL (1 << 1) +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; +} int bch2_bkey_val_invalid(struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *); int __bch2_bkey_invalid(struct bch_fs *, struct bkey_s_c, @@ -75,7 +87,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) @@ -115,7 +127,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) |