diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-03-31 05:39:48 +0200 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 23:09:29 +0200 |
commit | f13fd87a39225eae57d4ddf824a09acb1955abd1 (patch) | |
tree | 111bfbc8c9fdb1431ebcfb52bed12e71af57915a | |
parent | bcachefs: Move deletion of refcount=0 indirect extents to their triggers (diff) | |
download | linux-f13fd87a39225eae57d4ddf824a09acb1955abd1.tar.xz linux-f13fd87a39225eae57d4ddf824a09acb1955abd1.zip |
bcachefs: Run overwrite triggers before insert
For backpointers, we'll need to delete old backpointers before adding
new backpointers - otherwise we'll run into spurious duplicate
backpointer errors.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r-- | fs/bcachefs/btree_update_leaf.c | 47 | ||||
-rw-r--r-- | fs/bcachefs/trace.h | 8 |
2 files changed, 18 insertions, 37 deletions
diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c index 2640d3e38a76..f534d7e649fd 100644 --- a/fs/bcachefs/btree_update_leaf.c +++ b/fs/bcachefs/btree_update_leaf.c @@ -464,7 +464,7 @@ static int run_one_mem_trigger(struct btree_trans *trans, } static int run_one_trans_trigger(struct btree_trans *trans, struct btree_insert_entry *i, - bool overwrite) + bool overwrite) { /* * Transactional triggers create new btree_insert_entries, so we can't @@ -473,42 +473,31 @@ static int run_one_trans_trigger(struct btree_trans *trans, struct btree_insert_ */ struct bkey old_k = i->old_k; struct bkey_s_c old = { &old_k, i->old_v }; - int ret = 0; if ((i->flags & BTREE_TRIGGER_NORUN) || !(BTREE_NODE_TYPE_HAS_TRANS_TRIGGERS & (1U << i->bkey_type))) return 0; - if (!overwrite) { - if (i->insert_trigger_run) - return 0; - - BUG_ON(i->overwrite_trigger_run); - i->insert_trigger_run = true; - } else { - if (i->overwrite_trigger_run) - return 0; - - BUG_ON(!i->insert_trigger_run); - i->overwrite_trigger_run = true; - } - - if (overwrite) { - ret = bch2_trans_mark_old(trans, old, i->flags); - } else if (bch2_bkey_ops[old.k->type].trans_trigger == - bch2_bkey_ops[i->k->k.type].trans_trigger && + if (!i->insert_trigger_run && + !i->overwrite_trigger_run && + bch2_bkey_ops[old.k->type].trans_trigger == + bch2_bkey_ops[i->k->k.type].trans_trigger && ((1U << old.k->type) & BTREE_TRIGGER_WANTS_OLD_AND_NEW)) { i->overwrite_trigger_run = true; - ret = bch2_trans_mark_key(trans, old, i->k, - BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|i->flags); + i->insert_trigger_run = true; + return bch2_trans_mark_key(trans, old, i->k, + BTREE_TRIGGER_INSERT| + BTREE_TRIGGER_OVERWRITE| + i->flags) ?: 1; + } else if (overwrite && !i->overwrite_trigger_run) { + i->overwrite_trigger_run = true; + return bch2_trans_mark_old(trans, old, i->flags) ?: 1; + } else if (!overwrite && !i->insert_trigger_run) { + i->insert_trigger_run = true; + return bch2_trans_mark_new(trans, i->k, i->flags) ?: 1; } else { - ret = bch2_trans_mark_new(trans, i->k, i->flags); + return 0; } - - if (ret == -EINTR) - trace_trans_restart_mark(trans->fn, _RET_IP_, - i->btree_id, &i->path->pos); - return ret ?: 1; } static int run_btree_triggers(struct btree_trans *trans, enum btree_id btree_id, @@ -518,7 +507,7 @@ static int run_btree_triggers(struct btree_trans *trans, enum btree_id btree_id, bool trans_trigger_run; int ret, overwrite; - for (overwrite = 0; overwrite < 2; overwrite++) { + for (overwrite = 1; overwrite >= 0; --overwrite) { /* * Running triggers will append more updates to the list of updates as diff --git a/fs/bcachefs/trace.h b/fs/bcachefs/trace.h index bb938dd8cdf2..6a2626a05815 100644 --- a/fs/bcachefs/trace.h +++ b/fs/bcachefs/trace.h @@ -714,14 +714,6 @@ DEFINE_EVENT(transaction_restart_iter, trans_restart_btree_node_split, TP_ARGS(trans_fn, caller_ip, btree_id, pos) ); -DEFINE_EVENT(transaction_restart_iter, trans_restart_mark, - TP_PROTO(const char *trans_fn, - unsigned long caller_ip, - enum btree_id btree_id, - struct bpos *pos), - TP_ARGS(trans_fn, caller_ip, btree_id, pos) -); - DEFINE_EVENT(transaction_restart_iter, trans_restart_upgrade, TP_PROTO(const char *trans_fn, unsigned long caller_ip, |