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
*/
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);
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,
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)
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)