summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/bkey_methods.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-03-13 06:26:52 +0100
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 23:09:28 +0200
commit880e2275f9f1461c87cd113a8da291861cc01400 (patch)
tree8e8962da1c1e71c93758ce2b4a8374dbfc9f1bfa /fs/bcachefs/bkey_methods.h
parentbcachefs: Revalidate pointer to old bkey val before calling mem triggers (diff)
downloadlinux-880e2275f9f1461c87cd113a8da291861cc01400.tar.xz
linux-880e2275f9f1461c87cd113a8da291861cc01400.zip
bcachefs: Move trigger fns to bkey_ops
This replaces the switch statements in bch2_mark_key(), bch2_trans_mark_key() with new bkey methods - prep work for the next patch, which fixes BTREE_TRIGGER_WANTS_OLD_AND_NEW. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/bkey_methods.h')
-rw-r--r--fs/bcachefs/bkey_methods.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/fs/bcachefs/bkey_methods.h b/fs/bcachefs/bkey_methods.h
index 520f7d93993d..2b1086971bbb 100644
--- a/fs/bcachefs/bkey_methods.h
+++ b/fs/bcachefs/bkey_methods.h
@@ -6,6 +6,7 @@
struct bch_fs;
struct btree;
+struct btree_trans;
struct bkey;
enum btree_node_type;
@@ -20,6 +21,10 @@ struct bkey_ops {
void (*swab)(struct bkey_s);
bool (*key_normalize)(struct bch_fs *, struct bkey_s);
bool (*key_merge)(struct bch_fs *, struct bkey_s, struct bkey_s_c);
+ int (*trans_trigger)(struct btree_trans *, struct bkey_s_c,
+ struct bkey_i *, unsigned);
+ int (*atomic_trigger)(struct btree_trans *, struct bkey_s_c,
+ struct bkey_s_c, unsigned);
void (*compat)(enum btree_id id, unsigned version,
unsigned big_endian, int write,
struct bkey_s);
@@ -54,6 +59,28 @@ static inline bool bch2_bkey_maybe_mergable(const struct bkey *l, const struct b
bool bch2_bkey_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
+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];
+
+ return ops->atomic_trigger
+ ? ops->atomic_trigger(trans, old, new, flags)
+ : 0;
+}
+
+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];
+
+ return ops->trans_trigger
+ ? ops->trans_trigger(trans, old, new, flags)
+ : 0;
+}
+
void bch2_bkey_renumber(enum btree_node_type, struct bkey_packed *, int);
void __bch2_bkey_compat(unsigned, enum btree_id, unsigned, unsigned,