Commit 523f33ef authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: All triggers are BTREE_TRIGGER_WANTS_OLD_AND_NEW

Upcoming rebalance_work btree will require extent triggers to be
BTREE_TRIGGER_WANTS_OLD_AND_NEW - so to reduce potential confusion,
let's just make all triggers BTREE_TRIGGER_WANTS_OLD_AND_NEW.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 84809057
...@@ -119,16 +119,6 @@ enum btree_update_flags { ...@@ -119,16 +119,6 @@ enum btree_update_flags {
#define BTREE_TRIGGER_BUCKET_INVALIDATE (1U << __BTREE_TRIGGER_BUCKET_INVALIDATE) #define BTREE_TRIGGER_BUCKET_INVALIDATE (1U << __BTREE_TRIGGER_BUCKET_INVALIDATE)
#define BTREE_TRIGGER_NOATOMIC (1U << __BTREE_TRIGGER_NOATOMIC) #define BTREE_TRIGGER_NOATOMIC (1U << __BTREE_TRIGGER_NOATOMIC)
#define BTREE_TRIGGER_WANTS_OLD_AND_NEW \
((1U << KEY_TYPE_alloc)| \
(1U << KEY_TYPE_alloc_v2)| \
(1U << KEY_TYPE_alloc_v3)| \
(1U << KEY_TYPE_alloc_v4)| \
(1U << KEY_TYPE_stripe)| \
(1U << KEY_TYPE_inode)| \
(1U << KEY_TYPE_inode_v2)| \
(1U << KEY_TYPE_snapshot))
static inline int bch2_trans_mark_key(struct btree_trans *trans, static inline int bch2_trans_mark_key(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new, struct bkey_s_c old, struct bkey_i *new,
......
...@@ -382,8 +382,7 @@ static int run_one_mem_trigger(struct btree_trans *trans, ...@@ -382,8 +382,7 @@ static int run_one_mem_trigger(struct btree_trans *trans,
if (!btree_node_type_needs_gc(__btree_node_type(i->level, i->btree_id))) if (!btree_node_type_needs_gc(__btree_node_type(i->level, i->btree_id)))
return 0; return 0;
if (old_ops->atomic_trigger == new_ops->atomic_trigger && if (old_ops->atomic_trigger == new_ops->atomic_trigger) {
((1U << old.k->type) & BTREE_TRIGGER_WANTS_OLD_AND_NEW)) {
ret = bch2_mark_key(trans, i->btree_id, i->level, ret = bch2_mark_key(trans, i->btree_id, i->level,
old, bkey_i_to_s_c(new), old, bkey_i_to_s_c(new),
BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|flags); BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|flags);
...@@ -425,8 +424,7 @@ static int run_one_trans_trigger(struct btree_trans *trans, struct btree_insert_ ...@@ -425,8 +424,7 @@ static int run_one_trans_trigger(struct btree_trans *trans, struct btree_insert_
if (!i->insert_trigger_run && if (!i->insert_trigger_run &&
!i->overwrite_trigger_run && !i->overwrite_trigger_run &&
old_ops->trans_trigger == new_ops->trans_trigger && old_ops->trans_trigger == new_ops->trans_trigger) {
((1U << old.k->type) & BTREE_TRIGGER_WANTS_OLD_AND_NEW)) {
i->overwrite_trigger_run = true; i->overwrite_trigger_run = true;
i->insert_trigger_run = true; i->insert_trigger_run = true;
return bch2_trans_mark_key(trans, i->btree_id, i->level, old, i->k, return bch2_trans_mark_key(trans, i->btree_id, i->level, old, i->k,
......
...@@ -935,14 +935,12 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans, ...@@ -935,14 +935,12 @@ static int bch2_mark_stripe_ptr(struct btree_trans *trans,
return 0; return 0;
} }
int bch2_mark_extent(struct btree_trans *trans, static int __mark_extent(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c k, unsigned flags)
unsigned flags)
{ {
u64 journal_seq = trans->journal_res.seq; u64 journal_seq = trans->journal_res.seq;
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old : 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;
...@@ -1018,6 +1016,14 @@ int bch2_mark_extent(struct btree_trans *trans, ...@@ -1018,6 +1016,14 @@ int bch2_mark_extent(struct btree_trans *trans,
return 0; return 0;
} }
int bch2_mark_extent(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c new,
unsigned flags)
{
return mem_trigger_run_overwrite_then_insert(__mark_extent, trans, btree_id, level, old, new, flags);
}
int bch2_mark_stripe(struct btree_trans *trans, int bch2_mark_stripe(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c old, struct bkey_s_c new,
...@@ -1124,13 +1130,11 @@ int bch2_mark_stripe(struct btree_trans *trans, ...@@ -1124,13 +1130,11 @@ int bch2_mark_stripe(struct btree_trans *trans,
return 0; return 0;
} }
int bch2_mark_reservation(struct btree_trans *trans, static int __mark_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c k, unsigned flags)
unsigned flags)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old : new;
struct bch_fs_usage *fs_usage; struct bch_fs_usage *fs_usage;
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;
...@@ -1157,6 +1161,14 @@ int bch2_mark_reservation(struct btree_trans *trans, ...@@ -1157,6 +1161,14 @@ int bch2_mark_reservation(struct btree_trans *trans,
return 0; return 0;
} }
int bch2_mark_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c new,
unsigned flags)
{
return mem_trigger_run_overwrite_then_insert(__mark_reservation, trans, btree_id, level, old, new, flags);
}
static s64 __bch2_mark_reflink_p(struct btree_trans *trans, static s64 __bch2_mark_reflink_p(struct btree_trans *trans,
struct bkey_s_c_reflink_p p, struct bkey_s_c_reflink_p p,
u64 start, u64 end, u64 start, u64 end,
...@@ -1211,13 +1223,11 @@ static s64 __bch2_mark_reflink_p(struct btree_trans *trans, ...@@ -1211,13 +1223,11 @@ static s64 __bch2_mark_reflink_p(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_mark_reflink_p(struct btree_trans *trans, static int __mark_reflink_p(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c new, struct bkey_s_c k, unsigned flags)
unsigned flags)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct bkey_s_c k = flags & BTREE_TRIGGER_OVERWRITE ? old : 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);
struct reflink_gc *ref; struct reflink_gc *ref;
size_t l, r, m; size_t l, r, m;
...@@ -1251,6 +1261,14 @@ int bch2_mark_reflink_p(struct btree_trans *trans, ...@@ -1251,6 +1261,14 @@ int bch2_mark_reflink_p(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_mark_reflink_p(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c new,
unsigned flags)
{
return mem_trigger_run_overwrite_then_insert(__mark_reflink_p, trans, btree_id, level, old, new, flags);
}
void bch2_trans_fs_usage_revert(struct btree_trans *trans, void bch2_trans_fs_usage_revert(struct btree_trans *trans,
struct replicas_delta_list *deltas) struct replicas_delta_list *deltas)
{ {
...@@ -1452,15 +1470,11 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans, ...@@ -1452,15 +1470,11 @@ static int bch2_trans_mark_stripe_ptr(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_trans_mark_extent(struct btree_trans *trans, static int __trans_mark_extent(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new, struct bkey_s_c k, unsigned flags)
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;
...@@ -1517,6 +1531,14 @@ int bch2_trans_mark_extent(struct btree_trans *trans, ...@@ -1517,6 +1531,14 @@ int bch2_trans_mark_extent(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_trans_mark_extent(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new,
unsigned flags)
{
return trigger_run_overwrite_then_insert(__trans_mark_extent, trans, btree_id, level, old, new, flags);
}
static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans, static int bch2_trans_mark_stripe_bucket(struct btree_trans *trans,
struct bkey_s_c_stripe s, struct bkey_s_c_stripe s,
unsigned idx, bool deleting) unsigned idx, bool deleting)
...@@ -1670,15 +1692,10 @@ int bch2_trans_mark_stripe(struct btree_trans *trans, ...@@ -1670,15 +1692,10 @@ int bch2_trans_mark_stripe(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_trans_mark_reservation(struct btree_trans *trans, static int __trans_mark_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c k, unsigned flags)
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;
...@@ -1700,7 +1717,16 @@ int bch2_trans_mark_reservation(struct btree_trans *trans, ...@@ -1700,7 +1717,16 @@ int bch2_trans_mark_reservation(struct btree_trans *trans,
return 0; return 0;
} }
static int __bch2_trans_mark_reflink_p(struct btree_trans *trans, int bch2_trans_mark_reservation(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old,
struct bkey_i *new,
unsigned flags)
{
return trigger_run_overwrite_then_insert(__trans_mark_reservation, trans, btree_id, level, old, new, flags);
}
static int trans_mark_reflink_p_segment(struct btree_trans *trans,
struct bkey_s_c_reflink_p p, struct bkey_s_c_reflink_p p,
u64 *idx, unsigned flags) u64 *idx, unsigned flags)
{ {
...@@ -1767,35 +1793,38 @@ static int __bch2_trans_mark_reflink_p(struct btree_trans *trans, ...@@ -1767,35 +1793,38 @@ static int __bch2_trans_mark_reflink_p(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_trans_mark_reflink_p(struct btree_trans *trans, static int __trans_mark_reflink_p(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_s_c k, unsigned flags)
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;
if (flags & BTREE_TRIGGER_INSERT) {
struct bch_reflink_p *v = (struct bch_reflink_p *) p.v;
v->front_pad = v->back_pad = 0;
}
idx = le64_to_cpu(p.v->idx) - le32_to_cpu(p.v->front_pad); idx = le64_to_cpu(p.v->idx) - le32_to_cpu(p.v->front_pad);
end_idx = le64_to_cpu(p.v->idx) + p.k->size + end_idx = le64_to_cpu(p.v->idx) + p.k->size +
le32_to_cpu(p.v->back_pad); le32_to_cpu(p.v->back_pad);
while (idx < end_idx && !ret) while (idx < end_idx && !ret)
ret = __bch2_trans_mark_reflink_p(trans, p, &idx, flags); ret = trans_mark_reflink_p_segment(trans, p, &idx, flags);
return ret; return ret;
} }
int bch2_trans_mark_reflink_p(struct btree_trans *trans,
enum btree_id btree_id, unsigned level,
struct bkey_s_c old,
struct bkey_i *new,
unsigned flags)
{
if (flags & BTREE_TRIGGER_INSERT) {
struct bch_reflink_p *v = &bkey_i_to_reflink_p(new)->v;
v->front_pad = v->back_pad = 0;
}
return trigger_run_overwrite_then_insert(__trans_mark_reflink_p, trans, btree_id, level, old, new, flags);
}
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,
......
...@@ -339,6 +339,20 @@ int bch2_trans_mark_stripe(struct btree_trans *, enum btree_id, unsigned, struct ...@@ -339,6 +339,20 @@ int bch2_trans_mark_stripe(struct btree_trans *, enum btree_id, unsigned, struct
int bch2_trans_mark_reservation(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_i *, unsigned); int bch2_trans_mark_reservation(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_i *, unsigned);
int bch2_trans_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_i *, unsigned); int bch2_trans_mark_reflink_p(struct btree_trans *, enum btree_id, unsigned, struct bkey_s_c, struct bkey_i *, unsigned);
#define mem_trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags)\
({ \
int ret = 0; \
\
if (_old.k->type) \
ret = _fn(_trans, _btree_id, _level, _old, _flags & ~BTREE_TRIGGER_INSERT); \
if (!ret && _new.k->type) \
ret = _fn(_trans, _btree_id, _level, _new, _flags & ~BTREE_TRIGGER_OVERWRITE); \
ret; \
})
#define trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, _new, _flags) \
mem_trigger_run_overwrite_then_insert(_fn, _trans, _btree_id, _level, _old, bkey_i_to_s_c(_new), _flags)
void bch2_trans_fs_usage_revert(struct btree_trans *, struct replicas_delta_list *); void bch2_trans_fs_usage_revert(struct btree_trans *, struct replicas_delta_list *);
int bch2_trans_fs_usage_apply(struct btree_trans *, struct replicas_delta_list *); int bch2_trans_fs_usage_apply(struct btree_trans *, struct replicas_delta_list *);
......
...@@ -103,21 +103,22 @@ bool bch2_reflink_v_merge(struct bch_fs *c, struct bkey_s _l, struct bkey_s_c _r ...@@ -103,21 +103,22 @@ bool bch2_reflink_v_merge(struct bch_fs *c, struct bkey_s _l, struct bkey_s_c _r
} }
#endif #endif
static inline void check_indirect_extent_deleting(struct bkey_i *new, unsigned *flags)
{
if ((*flags & BTREE_TRIGGER_INSERT) && !*bkey_refcount(new)) {
new->k.type = KEY_TYPE_deleted;
new->k.size = 0;
set_bkey_val_u64s(&new->k, 0);;
*flags &= ~BTREE_TRIGGER_INSERT;
}
}
int bch2_trans_mark_reflink_v(struct btree_trans *trans, int bch2_trans_mark_reflink_v(struct btree_trans *trans,
enum btree_id btree_id, unsigned level, enum btree_id btree_id, unsigned level,
struct bkey_s_c old, struct bkey_i *new, struct bkey_s_c old, struct bkey_i *new,
unsigned flags) unsigned flags)
{ {
if (!(flags & BTREE_TRIGGER_OVERWRITE)) { check_indirect_extent_deleting(new, &flags);
struct bkey_i_reflink_v *r = bkey_i_to_reflink_v(new);
if (!r->v.refcount) {
r->k.type = KEY_TYPE_deleted;
r->k.size = 0;
set_bkey_val_u64s(&r->k, 0);
return 0;
}
}
return bch2_trans_mark_extent(trans, btree_id, level, old, new, flags); return bch2_trans_mark_extent(trans, btree_id, level, old, new, flags);
} }
...@@ -147,16 +148,7 @@ int bch2_trans_mark_indirect_inline_data(struct btree_trans *trans, ...@@ -147,16 +148,7 @@ int bch2_trans_mark_indirect_inline_data(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)
{ {
if (!(flags & BTREE_TRIGGER_OVERWRITE)) { check_indirect_extent_deleting(new, &flags);
struct bkey_i_indirect_inline_data *r =
bkey_i_to_indirect_inline_data(new);
if (!r->v.refcount) {
r->k.type = KEY_TYPE_deleted;
r->k.size = 0;
set_bkey_val_u64s(&r->k, 0);
}
}
return 0; return 0;
} }
......
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