Commit 880e2275 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent d13f9ee6
...@@ -65,16 +65,19 @@ void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c); ...@@ -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) { \ #define bch2_bkey_ops_alloc (struct bkey_ops) { \
.key_invalid = bch2_alloc_v1_invalid, \ .key_invalid = bch2_alloc_v1_invalid, \
.val_to_text = bch2_alloc_to_text, \ .val_to_text = bch2_alloc_to_text, \
.atomic_trigger = bch2_mark_alloc, \
} }
#define bch2_bkey_ops_alloc_v2 (struct bkey_ops) { \ #define bch2_bkey_ops_alloc_v2 (struct bkey_ops) { \
.key_invalid = bch2_alloc_v2_invalid, \ .key_invalid = bch2_alloc_v2_invalid, \
.val_to_text = bch2_alloc_to_text, \ .val_to_text = bch2_alloc_to_text, \
.atomic_trigger = bch2_mark_alloc, \
} }
#define bch2_bkey_ops_alloc_v3 (struct bkey_ops) { \ #define bch2_bkey_ops_alloc_v3 (struct bkey_ops) { \
.key_invalid = bch2_alloc_v3_invalid, \ .key_invalid = bch2_alloc_v3_invalid, \
.val_to_text = bch2_alloc_to_text, \ .val_to_text = bch2_alloc_to_text, \
.atomic_trigger = bch2_mark_alloc, \
} }
static inline bool bkey_is_alloc(const struct bkey *k) static inline bool bkey_is_alloc(const struct bkey *k)
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
struct bch_fs; struct bch_fs;
struct btree; struct btree;
struct btree_trans;
struct bkey; struct bkey;
enum btree_node_type; enum btree_node_type;
...@@ -20,6 +21,10 @@ struct bkey_ops { ...@@ -20,6 +21,10 @@ struct bkey_ops {
void (*swab)(struct bkey_s); void (*swab)(struct bkey_s);
bool (*key_normalize)(struct bch_fs *, 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); 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, void (*compat)(enum btree_id id, unsigned version,
unsigned big_endian, int write, unsigned big_endian, int write,
struct bkey_s); struct bkey_s);
...@@ -54,6 +59,28 @@ static inline bool bch2_bkey_maybe_mergable(const struct bkey *l, const struct b ...@@ -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); 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_renumber(enum btree_node_type, struct bkey_packed *, int);
void __bch2_bkey_compat(unsigned, enum btree_id, unsigned, unsigned, void __bch2_bkey_compat(unsigned, enum btree_id, unsigned, unsigned,
......
...@@ -501,7 +501,7 @@ void bch2_mark_alloc_bucket(struct bch_fs *c, struct bch_dev *ca, ...@@ -501,7 +501,7 @@ void bch2_mark_alloc_bucket(struct bch_fs *c, struct bch_dev *ca,
BUG_ON(owned_by_allocator == old.owned_by_allocator); BUG_ON(owned_by_allocator == old.owned_by_allocator);
} }
static int bch2_mark_alloc(struct btree_trans *trans, int bch2_mark_alloc(struct btree_trans *trans,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c old, struct bkey_s_c new,
unsigned flags) unsigned flags)
{ {
...@@ -933,7 +933,7 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans, ...@@ -933,7 +933,7 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans,
return 0; return 0;
} }
static int bch2_mark_extent(struct btree_trans *trans, int bch2_mark_extent(struct btree_trans *trans,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c old, struct bkey_s_c new,
unsigned flags) unsigned flags)
{ {
...@@ -1015,7 +1015,7 @@ static int bch2_mark_extent(struct btree_trans *trans, ...@@ -1015,7 +1015,7 @@ static int bch2_mark_extent(struct btree_trans *trans,
return 0; return 0;
} }
static int bch2_mark_stripe(struct btree_trans *trans, int bch2_mark_stripe(struct btree_trans *trans,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c old, struct bkey_s_c new,
unsigned flags) unsigned flags)
{ {
...@@ -1122,7 +1122,7 @@ static int bch2_mark_stripe(struct btree_trans *trans, ...@@ -1122,7 +1122,7 @@ static int bch2_mark_stripe(struct btree_trans *trans,
return 0; return 0;
} }
static int bch2_mark_inode(struct btree_trans *trans, int bch2_mark_inode(struct btree_trans *trans,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c old, struct bkey_s_c new,
unsigned flags) unsigned flags)
{ {
...@@ -1153,7 +1153,7 @@ static int bch2_mark_inode(struct btree_trans *trans, ...@@ -1153,7 +1153,7 @@ static int bch2_mark_inode(struct btree_trans *trans,
return 0; return 0;
} }
static int bch2_mark_reservation(struct btree_trans *trans, int bch2_mark_reservation(struct btree_trans *trans,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c old, struct bkey_s_c new,
unsigned flags) unsigned flags)
{ {
...@@ -1232,7 +1232,7 @@ static s64 __bch2_mark_reflink_p(struct btree_trans *trans, ...@@ -1232,7 +1232,7 @@ static s64 __bch2_mark_reflink_p(struct btree_trans *trans,
return ret; return ret;
} }
static int bch2_mark_reflink_p(struct btree_trans *trans, int bch2_mark_reflink_p(struct btree_trans *trans,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c old, struct bkey_s_c new,
unsigned flags) unsigned flags)
{ {
...@@ -1271,39 +1271,6 @@ static int bch2_mark_reflink_p(struct btree_trans *trans, ...@@ -1271,39 +1271,6 @@ static int bch2_mark_reflink_p(struct btree_trans *trans,
return ret; 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 static noinline __cold
void fs_usage_apply_warn(struct btree_trans *trans, void fs_usage_apply_warn(struct btree_trans *trans,
unsigned disk_res_sectors, unsigned disk_res_sectors,
...@@ -1518,10 +1485,14 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans, ...@@ -1518,10 +1485,14 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans,
return ret; return ret;
} }
static int bch2_trans_mark_extent(struct btree_trans *trans, int bch2_trans_mark_extent(struct btree_trans *trans,
struct bkey_s_c k, unsigned flags) struct bkey_s_c old, struct bkey_i *new,
unsigned flags)
{ {
struct bch_fs *c = trans->c; 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); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const union bch_extent_entry *entry; const union bch_extent_entry *entry;
struct extent_ptr_decoded p; struct extent_ptr_decoded p;
...@@ -1652,7 +1623,7 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans, ...@@ -1652,7 +1623,7 @@ static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans,
return ret; return ret;
} }
static int bch2_trans_mark_stripe(struct btree_trans *trans, int bch2_trans_mark_stripe(struct btree_trans *trans,
struct bkey_s_c old, struct bkey_i *new, struct bkey_s_c old, struct bkey_i *new,
unsigned flags) unsigned flags)
{ {
...@@ -1722,7 +1693,7 @@ static int bch2_trans_mark_stripe(struct btree_trans *trans, ...@@ -1722,7 +1693,7 @@ static int bch2_trans_mark_stripe(struct btree_trans *trans,
return ret; return ret;
} }
static int bch2_trans_mark_inode(struct btree_trans *trans, int bch2_trans_mark_inode(struct btree_trans *trans,
struct bkey_s_c old, struct bkey_s_c old,
struct bkey_i *new, struct bkey_i *new,
unsigned flags) unsigned flags)
...@@ -1738,9 +1709,14 @@ static int bch2_trans_mark_inode(struct btree_trans *trans, ...@@ -1738,9 +1709,14 @@ static int bch2_trans_mark_inode(struct btree_trans *trans,
return 0; return 0;
} }
static int bch2_trans_mark_reservation(struct btree_trans *trans, int bch2_trans_mark_reservation(struct btree_trans *trans,
struct bkey_s_c k, unsigned flags) 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; unsigned replicas = bkey_s_c_to_reservation(k).v->nr_replicas;
s64 sectors = (s64) k.k->size; s64 sectors = (s64) k.k->size;
struct replicas_delta_list *d; struct replicas_delta_list *d;
...@@ -1839,9 +1815,14 @@ static int __bch2_trans_mark_reflink_p(struct btree_trans *trans, ...@@ -1839,9 +1815,14 @@ static int __bch2_trans_mark_reflink_p(struct btree_trans *trans,
return ret; return ret;
} }
static int bch2_trans_mark_reflink_p(struct btree_trans *trans, int bch2_trans_mark_reflink_p(struct btree_trans *trans,
struct bkey_s_c k, unsigned flags) 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); struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
u64 idx, end_idx; u64 idx, end_idx;
int ret = 0; int ret = 0;
...@@ -1862,33 +1843,6 @@ static int bch2_trans_mark_reflink_p(struct btree_trans *trans, ...@@ -1862,33 +1843,6 @@ static int bch2_trans_mark_reflink_p(struct btree_trans *trans,
return ret; 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, static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
struct bch_dev *ca, size_t b, struct bch_dev *ca, size_t b,
enum bch_data_type type, enum bch_data_type type,
......
...@@ -229,6 +229,19 @@ void bch2_mark_metadata_bucket(struct bch_fs *, struct bch_dev *, ...@@ -229,6 +229,19 @@ void bch2_mark_metadata_bucket(struct bch_fs *, struct bch_dev *,
size_t, enum bch_data_type, unsigned, size_t, enum bch_data_type, unsigned,
struct gc_pos, 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_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, int bch2_trans_mark_key(struct btree_trans *, struct bkey_s_c,
......
...@@ -14,6 +14,8 @@ void bch2_stripe_to_text(struct printbuf *, struct bch_fs *, ...@@ -14,6 +14,8 @@ void bch2_stripe_to_text(struct printbuf *, struct bch_fs *,
.key_invalid = bch2_stripe_invalid, \ .key_invalid = bch2_stripe_invalid, \
.val_to_text = bch2_stripe_to_text, \ .val_to_text = bch2_stripe_to_text, \
.swab = bch2_ptr_swab, \ .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) static inline unsigned stripe_csums_per_device(const struct bch_stripe *s)
......
...@@ -381,6 +381,8 @@ void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned, ...@@ -381,6 +381,8 @@ void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
.key_invalid = bch2_btree_ptr_invalid, \ .key_invalid = bch2_btree_ptr_invalid, \
.val_to_text = bch2_btree_ptr_to_text, \ .val_to_text = bch2_btree_ptr_to_text, \
.swab = bch2_ptr_swab, \ .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) { \ #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, ...@@ -388,6 +390,8 @@ void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
.val_to_text = bch2_btree_ptr_v2_to_text, \ .val_to_text = bch2_btree_ptr_v2_to_text, \
.swab = bch2_ptr_swab, \ .swab = bch2_ptr_swab, \
.compat = bch2_btree_ptr_v2_compat, \ .compat = bch2_btree_ptr_v2_compat, \
.trans_trigger = bch2_trans_mark_extent, \
.atomic_trigger = bch2_mark_extent, \
} }
/* KEY_TYPE_extent: */ /* KEY_TYPE_extent: */
...@@ -402,6 +406,8 @@ bool bch2_extent_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c); ...@@ -402,6 +406,8 @@ bool bch2_extent_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
.swab = bch2_ptr_swab, \ .swab = bch2_ptr_swab, \
.key_normalize = bch2_extent_normalize, \ .key_normalize = bch2_extent_normalize, \
.key_merge = bch2_extent_merge, \ .key_merge = bch2_extent_merge, \
.trans_trigger = bch2_trans_mark_extent, \
.atomic_trigger = bch2_mark_extent, \
} }
/* KEY_TYPE_reservation: */ /* KEY_TYPE_reservation: */
...@@ -414,6 +420,8 @@ bool bch2_reservation_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c); ...@@ -414,6 +420,8 @@ bool bch2_reservation_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
.key_invalid = bch2_reservation_invalid, \ .key_invalid = bch2_reservation_invalid, \
.val_to_text = bch2_reservation_to_text, \ .val_to_text = bch2_reservation_to_text, \
.key_merge = bch2_reservation_merge, \ .key_merge = bch2_reservation_merge, \
.trans_trigger = bch2_trans_mark_reservation, \
.atomic_trigger = bch2_mark_reservation, \
} }
/* Extent checksum entries: */ /* Extent checksum entries: */
......
...@@ -13,11 +13,15 @@ void bch2_inode_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c); ...@@ -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) { \ #define bch2_bkey_ops_inode (struct bkey_ops) { \
.key_invalid = bch2_inode_invalid, \ .key_invalid = bch2_inode_invalid, \
.val_to_text = bch2_inode_to_text, \ .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) { \ #define bch2_bkey_ops_inode_v2 (struct bkey_ops) { \
.key_invalid = bch2_inode_v2_invalid, \ .key_invalid = bch2_inode_v2_invalid, \
.val_to_text = bch2_inode_to_text, \ .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) static inline bool bkey_is_inode(const struct bkey *k)
......
...@@ -11,6 +11,8 @@ bool bch2_reflink_p_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c); ...@@ -11,6 +11,8 @@ bool bch2_reflink_p_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
.key_invalid = bch2_reflink_p_invalid, \ .key_invalid = bch2_reflink_p_invalid, \
.val_to_text = bch2_reflink_p_to_text, \ .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); 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 *, ...@@ -21,6 +23,8 @@ void bch2_reflink_v_to_text(struct printbuf *, struct bch_fs *,
.key_invalid = bch2_reflink_v_invalid, \ .key_invalid = bch2_reflink_v_invalid, \
.val_to_text = bch2_reflink_v_to_text, \ .val_to_text = bch2_reflink_v_to_text, \
.swab = bch2_ptr_swab, \ .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 *, const char *bch2_indirect_inline_data_invalid(const struct bch_fs *,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment