]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Move trigger fns to bkey_ops
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 13 Mar 2022 05:26:52 +0000 (00:26 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:28 +0000 (17:09 -0400)
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>
fs/bcachefs/alloc_background.h
fs/bcachefs/bkey_methods.h
fs/bcachefs/buckets.c
fs/bcachefs/buckets.h
fs/bcachefs/ec.h
fs/bcachefs/extents.h
fs/bcachefs/inode.h
fs/bcachefs/reflink.h

index 98c7866e20b57ded9f8d629d8427d5966f97bfb5..3eaa6d2042861f6ba46020ee0fa2f7d79140ea7e 100644 (file)
@@ -65,16 +65,19 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 #define bch2_bkey_ops_alloc (struct bkey_ops) {                \
        .key_invalid    = bch2_alloc_v1_invalid,        \
        .val_to_text    = bch2_alloc_to_text,           \
+       .atomic_trigger = bch2_mark_alloc,              \
 }
 
 #define bch2_bkey_ops_alloc_v2 (struct bkey_ops) {     \
        .key_invalid    = bch2_alloc_v2_invalid,        \
        .val_to_text    = bch2_alloc_to_text,           \
+       .atomic_trigger = bch2_mark_alloc,              \
 }
 
 #define bch2_bkey_ops_alloc_v3 (struct bkey_ops) {     \
        .key_invalid    = bch2_alloc_v3_invalid,        \
        .val_to_text    = bch2_alloc_to_text,           \
+       .atomic_trigger = bch2_mark_alloc,              \
 }
 
 static inline bool bkey_is_alloc(const struct bkey *k)
index 520f7d93993da11c9848cc5dbe66b9c65e54378d..2b1086971bbb54f29ea33f62af83a8fb5965cae8 100644 (file)
@@ -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,
index 2ff64276304fe4ffb8c69d977c8c1933b00617e9..a681a6045dc9a66686985cfae82f810d6bf07beb 100644 (file)
@@ -501,9 +501,9 @@ void bch2_mark_alloc_bucket(struct bch_fs *c, struct bch_dev *ca,
        BUG_ON(owned_by_allocator == old.owned_by_allocator);
 }
 
-static int bch2_mark_alloc(struct btree_trans *trans,
-                          struct bkey_s_c old, struct bkey_s_c new,
-                          unsigned flags)
+int bch2_mark_alloc(struct btree_trans *trans,
+                   struct bkey_s_c old, struct bkey_s_c new,
+                   unsigned flags)
 {
        bool gc = flags & BTREE_TRIGGER_GC;
        u64 journal_seq = trans->journal_res.seq;
@@ -933,9 +933,9 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans,
        return 0;
 }
 
-static int bch2_mark_extent(struct btree_trans *trans,
-                           struct bkey_s_c old, struct bkey_s_c new,
-                           unsigned flags)
+int bch2_mark_extent(struct btree_trans *trans,
+                    struct bkey_s_c old, struct bkey_s_c new,
+                    unsigned flags)
 {
        u64 journal_seq = trans->journal_res.seq;
        struct bch_fs *c = trans->c;
@@ -1015,9 +1015,9 @@ static int bch2_mark_extent(struct btree_trans *trans,
        return 0;
 }
 
-static int bch2_mark_stripe(struct btree_trans *trans,
-                           struct bkey_s_c old, struct bkey_s_c new,
-                           unsigned flags)
+int bch2_mark_stripe(struct btree_trans *trans,
+                    struct bkey_s_c old, struct bkey_s_c new,
+                    unsigned flags)
 {
        bool gc = flags & BTREE_TRIGGER_GC;
        u64 journal_seq = trans->journal_res.seq;
@@ -1122,9 +1122,9 @@ static int bch2_mark_stripe(struct btree_trans *trans,
        return 0;
 }
 
-static int bch2_mark_inode(struct btree_trans *trans,
-                          struct bkey_s_c old, struct bkey_s_c new,
-                          unsigned flags)
+int bch2_mark_inode(struct btree_trans *trans,
+                   struct bkey_s_c old, struct bkey_s_c new,
+                   unsigned flags)
 {
        struct bch_fs *c = trans->c;
        struct bch_fs_usage __percpu *fs_usage;
@@ -1153,9 +1153,9 @@ static int bch2_mark_inode(struct btree_trans *trans,
        return 0;
 }
 
-static int bch2_mark_reservation(struct btree_trans *trans,
-                                struct bkey_s_c old, struct bkey_s_c new,
-                                unsigned flags)
+int bch2_mark_reservation(struct btree_trans *trans,
+                         struct bkey_s_c old, struct bkey_s_c new,
+                         unsigned flags)
 {
        struct bch_fs *c = trans->c;
        struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
@@ -1232,9 +1232,9 @@ fsck_err:
        return ret;
 }
 
-static int bch2_mark_reflink_p(struct btree_trans *trans,
-                              struct bkey_s_c old, struct bkey_s_c new,
-                              unsigned flags)
+int bch2_mark_reflink_p(struct btree_trans *trans,
+                       struct bkey_s_c old, struct bkey_s_c new,
+                       unsigned flags)
 {
        struct bch_fs *c = trans->c;
        struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
@@ -1271,39 +1271,6 @@ static int bch2_mark_reflink_p(struct btree_trans *trans,
        return ret;
 }
 
-int bch2_mark_key(struct btree_trans *trans,
-                 struct bkey_s_c old,
-                 struct bkey_s_c new,
-                 unsigned flags)
-{
-       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old: new;
-
-       switch (k.k->type) {
-       case KEY_TYPE_alloc:
-       case KEY_TYPE_alloc_v2:
-       case KEY_TYPE_alloc_v3:
-               return bch2_mark_alloc(trans, old, new, flags);
-       case KEY_TYPE_btree_ptr:
-       case KEY_TYPE_btree_ptr_v2:
-       case KEY_TYPE_extent:
-       case KEY_TYPE_reflink_v:
-               return bch2_mark_extent(trans, old, new, flags);
-       case KEY_TYPE_stripe:
-               return bch2_mark_stripe(trans, old, new, flags);
-       case KEY_TYPE_inode:
-       case KEY_TYPE_inode_v2:
-               return bch2_mark_inode(trans, old, new, flags);
-       case KEY_TYPE_reservation:
-               return bch2_mark_reservation(trans, old, new, flags);
-       case KEY_TYPE_reflink_p:
-               return bch2_mark_reflink_p(trans, old, new, flags);
-       case KEY_TYPE_snapshot:
-               return bch2_mark_snapshot(trans, old, new, flags);
-       default:
-               return 0;
-       }
-}
-
 static noinline __cold
 void fs_usage_apply_warn(struct btree_trans *trans,
                         unsigned disk_res_sectors,
@@ -1518,10 +1485,14 @@ err:
        return ret;
 }
 
-static int bch2_trans_mark_extent(struct btree_trans *trans,
-                       struct bkey_s_c k, unsigned flags)
+int bch2_trans_mark_extent(struct btree_trans *trans,
+                          struct bkey_s_c old, struct bkey_i *new,
+                          unsigned flags)
 {
        struct bch_fs *c = trans->c;
+       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE
+               ? old
+               : bkey_i_to_s_c(new);
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
        const union bch_extent_entry *entry;
        struct extent_ptr_decoded p;
@@ -1652,9 +1623,9 @@ err:
        return ret;
 }
 
-static int bch2_trans_mark_stripe(struct btree_trans *trans,
-                                 struct bkey_s_c old, struct bkey_i *new,
-                                 unsigned flags)
+int bch2_trans_mark_stripe(struct btree_trans *trans,
+                          struct bkey_s_c old, struct bkey_i *new,
+                          unsigned flags)
 {
        const struct bch_stripe *old_s = NULL;
        struct bch_stripe *new_s = NULL;
@@ -1722,10 +1693,10 @@ static int bch2_trans_mark_stripe(struct btree_trans *trans,
        return ret;
 }
 
-static int bch2_trans_mark_inode(struct btree_trans *trans,
-                                struct bkey_s_c old,
-                                struct bkey_i *new,
-                                unsigned flags)
+int bch2_trans_mark_inode(struct btree_trans *trans,
+                         struct bkey_s_c old,
+                         struct bkey_i *new,
+                         unsigned flags)
 {
        int nr = bkey_is_inode(&new->k) - bkey_is_inode(old.k);
 
@@ -1738,9 +1709,14 @@ static int bch2_trans_mark_inode(struct btree_trans *trans,
        return 0;
 }
 
-static int bch2_trans_mark_reservation(struct btree_trans *trans,
-                                      struct bkey_s_c k, unsigned flags)
+int bch2_trans_mark_reservation(struct btree_trans *trans,
+                               struct bkey_s_c old,
+                               struct bkey_i *new,
+                               unsigned flags)
 {
+       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE
+               ? old
+               : bkey_i_to_s_c(new);
        unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas;
        s64 sectors = (s64) k.k->size;
        struct replicas_delta_list *d;
@@ -1839,9 +1815,14 @@ err:
        return ret;
 }
 
-static int bch2_trans_mark_reflink_p(struct btree_trans *trans,
-                                    struct bkey_s_c k, unsigned flags)
+int bch2_trans_mark_reflink_p(struct btree_trans *trans,
+                             struct bkey_s_c old,
+                             struct bkey_i *new,
+                             unsigned flags)
 {
+       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE
+               ? old
+               : bkey_i_to_s_c(new);
        struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
        u64 idx, end_idx;
        int ret = 0;
@@ -1862,33 +1843,6 @@ static int bch2_trans_mark_reflink_p(struct btree_trans *trans,
        return ret;
 }
 
-int bch2_trans_mark_key(struct btree_trans *trans, struct bkey_s_c old,
-                       struct bkey_i *new, unsigned flags)
-{
-       struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE
-               ? old
-               : bkey_i_to_s_c(new);
-
-       switch (k.k->type) {
-       case KEY_TYPE_btree_ptr:
-       case KEY_TYPE_btree_ptr_v2:
-       case KEY_TYPE_extent:
-       case KEY_TYPE_reflink_v:
-               return bch2_trans_mark_extent(trans, k, flags);
-       case KEY_TYPE_stripe:
-               return bch2_trans_mark_stripe(trans, old, new, flags);
-       case KEY_TYPE_inode:
-       case KEY_TYPE_inode_v2:
-               return bch2_trans_mark_inode(trans, old, new, flags);
-       case KEY_TYPE_reservation:
-               return bch2_trans_mark_reservation(trans, k, flags);
-       case KEY_TYPE_reflink_p:
-               return bch2_trans_mark_reflink_p(trans, k, flags);
-       default:
-               return 0;
-       }
-}
-
 static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
                                    struct bch_dev *ca, size_t b,
                                    enum bch_data_type type,
index ca34d5d3b9618b87ed418fd1aa36643351faee57..90f53e677281a512ef7dde6d5fa3710a15ee52a5 100644 (file)
@@ -229,6 +229,19 @@ void bch2_mark_metadata_bucket(struct bch_fs *, struct bch_dev *,
                               size_t, enum bch_data_type, unsigned,
                               struct gc_pos, unsigned);
 
+int bch2_mark_alloc(struct btree_trans *, struct bkey_s_c, struct bkey_s_c, unsigned);
+int bch2_mark_extent(struct btree_trans *, struct bkey_s_c, struct bkey_s_c, unsigned);
+int bch2_mark_stripe(struct btree_trans *, struct bkey_s_c, struct bkey_s_c, unsigned);
+int bch2_mark_inode(struct btree_trans *, struct bkey_s_c, struct bkey_s_c, unsigned);
+int bch2_mark_reservation(struct btree_trans *, struct bkey_s_c, struct bkey_s_c, unsigned);
+int bch2_mark_reflink_p(struct btree_trans *, struct bkey_s_c, struct bkey_s_c, unsigned);
+
+int bch2_trans_mark_extent(struct btree_trans *, struct bkey_s_c, struct bkey_i *, unsigned);
+int bch2_trans_mark_stripe(struct btree_trans *, struct bkey_s_c, struct bkey_i *, unsigned);
+int bch2_trans_mark_inode(struct btree_trans *, struct bkey_s_c, struct bkey_i *, unsigned);
+int bch2_trans_mark_reservation(struct btree_trans *, struct bkey_s_c, struct bkey_i *, unsigned);
+int bch2_trans_mark_reflink_p(struct btree_trans *, struct bkey_s_c, struct bkey_i *, unsigned);
+
 int bch2_mark_key(struct btree_trans *, struct bkey_s_c, struct bkey_s_c, unsigned);
 
 int bch2_trans_mark_key(struct btree_trans *, struct bkey_s_c,
index 78d468c7680a2f167070297392dbcabba1204f95..9d508a2f3bbcbd813160565211ad8dfe99ebfa2f 100644 (file)
@@ -14,6 +14,8 @@ void bch2_stripe_to_text(struct printbuf *, struct bch_fs *,
        .key_invalid    = bch2_stripe_invalid,          \
        .val_to_text    = bch2_stripe_to_text,          \
        .swab           = bch2_ptr_swab,                \
+       .trans_trigger  = bch2_trans_mark_stripe,       \
+       .atomic_trigger = bch2_mark_stripe,             \
 }
 
 static inline unsigned stripe_csums_per_device(const struct bch_stripe *s)
index 9c2567274a2b8d286707d6b1b3594b3d04007ac3..ae650849d98a9c51f4cbf66c2d0b19aa7c1fad78 100644 (file)
@@ -381,6 +381,8 @@ void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
        .key_invalid    = bch2_btree_ptr_invalid,               \
        .val_to_text    = bch2_btree_ptr_to_text,               \
        .swab           = bch2_ptr_swab,                        \
+       .trans_trigger  = bch2_trans_mark_extent,               \
+       .atomic_trigger = bch2_mark_extent,                     \
 }
 
 #define bch2_bkey_ops_btree_ptr_v2 (struct bkey_ops) {         \
@@ -388,6 +390,8 @@ void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
        .val_to_text    = bch2_btree_ptr_v2_to_text,            \
        .swab           = bch2_ptr_swab,                        \
        .compat         = bch2_btree_ptr_v2_compat,             \
+       .trans_trigger  = bch2_trans_mark_extent,               \
+       .atomic_trigger = bch2_mark_extent,                     \
 }
 
 /* KEY_TYPE_extent: */
@@ -402,6 +406,8 @@ bool bch2_extent_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
        .swab           = bch2_ptr_swab,                        \
        .key_normalize  = bch2_extent_normalize,                \
        .key_merge      = bch2_extent_merge,                    \
+       .trans_trigger  = bch2_trans_mark_extent,               \
+       .atomic_trigger = bch2_mark_extent,                     \
 }
 
 /* KEY_TYPE_reservation: */
@@ -414,6 +420,8 @@ bool bch2_reservation_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
        .key_invalid    = bch2_reservation_invalid,             \
        .val_to_text    = bch2_reservation_to_text,             \
        .key_merge      = bch2_reservation_merge,               \
+       .trans_trigger  = bch2_trans_mark_reservation,          \
+       .atomic_trigger = bch2_mark_reservation,                \
 }
 
 /* Extent checksum entries: */
index 77957cc7f9dda3eac49a9bd435969c72184c6545..2337ecfc600ea7ac0fa00d69c1545fa722f59a4f 100644 (file)
@@ -13,11 +13,15 @@ void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 #define bch2_bkey_ops_inode (struct bkey_ops) {                \
        .key_invalid    = bch2_inode_invalid,           \
        .val_to_text    = bch2_inode_to_text,           \
+       .trans_trigger  = bch2_trans_mark_inode,        \
+       .atomic_trigger = bch2_mark_inode,              \
 }
 
 #define bch2_bkey_ops_inode_v2 (struct bkey_ops) {     \
        .key_invalid    = bch2_inode_v2_invalid,        \
        .val_to_text    = bch2_inode_to_text,           \
+       .trans_trigger  = bch2_trans_mark_inode,        \
+       .atomic_trigger = bch2_mark_inode,              \
 }
 
 static inline bool bkey_is_inode(const struct bkey *k)
index 3745873fd88d90947f610de256931cecec4d9181..4da4330014a82167fd48fdd6fc2c19b116581e65 100644 (file)
@@ -10,7 +10,9 @@ bool bch2_reflink_p_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
 #define bch2_bkey_ops_reflink_p (struct bkey_ops) {            \
        .key_invalid    = bch2_reflink_p_invalid,               \
        .val_to_text    = bch2_reflink_p_to_text,               \
-       .key_merge      = bch2_reflink_p_merge,         \
+       .key_merge      = bch2_reflink_p_merge,                 \
+       .trans_trigger  = bch2_trans_mark_reflink_p,            \
+       .atomic_trigger = bch2_mark_reflink_p,                  \
 }
 
 const char *bch2_reflink_v_invalid(const struct bch_fs *, struct bkey_s_c);
@@ -21,6 +23,8 @@ void bch2_reflink_v_to_text(struct printbuf *, struct bch_fs *,
        .key_invalid    = bch2_reflink_v_invalid,               \
        .val_to_text    = bch2_reflink_v_to_text,               \
        .swab           = bch2_ptr_swab,                        \
+       .trans_trigger  = bch2_trans_mark_extent,               \
+       .atomic_trigger = bch2_mark_extent,                     \
 }
 
 const char *bch2_indirect_inline_data_invalid(const struct bch_fs *,