Commit 96d3a0af authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Trigger code uses stashed copy of old key

Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 3598c56e
...@@ -412,28 +412,26 @@ static int run_one_mem_trigger(struct btree_trans *trans, ...@@ -412,28 +412,26 @@ static int run_one_mem_trigger(struct btree_trans *trans,
struct btree_insert_entry *i, struct btree_insert_entry *i,
unsigned flags) unsigned flags)
{ {
struct bkey _deleted = KEY(0, 0, 0); struct bkey_s_c old = { &i->old_k, i->old_v };
struct bkey_s_c deleted = (struct bkey_s_c) { &_deleted, NULL };
struct bkey_s_c old;
struct bkey unpacked;
struct bkey_i *new = i->k; struct bkey_i *new = i->k;
int ret; int ret;
_deleted.p = i->path->pos;
if (unlikely(flags & BTREE_TRIGGER_NORUN)) if (unlikely(flags & BTREE_TRIGGER_NORUN))
return 0; return 0;
if (!btree_node_type_needs_gc(i->path->btree_id)) if (!btree_node_type_needs_gc(i->btree_id))
return 0; return 0;
old = bch2_btree_path_peek_slot(i->path, &unpacked);
if (old.k->type == new->k.type && if (old.k->type == new->k.type &&
((1U << old.k->type) & BTREE_TRIGGER_WANTS_OLD_AND_NEW)) { ((1U << old.k->type) & BTREE_TRIGGER_WANTS_OLD_AND_NEW)) {
ret = bch2_mark_key(trans, old, bkey_i_to_s_c(new), ret = bch2_mark_key(trans, old, bkey_i_to_s_c(new),
BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|flags); BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE|flags);
} else { } else {
struct bkey _deleted = KEY(0, 0, 0);
struct bkey_s_c deleted = (struct bkey_s_c) { &_deleted, NULL };
_deleted.p = i->path->pos;
ret = bch2_mark_key(trans, deleted, bkey_i_to_s_c(new), ret = bch2_mark_key(trans, deleted, bkey_i_to_s_c(new),
BTREE_TRIGGER_INSERT|flags) ?: BTREE_TRIGGER_INSERT|flags) ?:
bch2_mark_key(trans, old, deleted, bch2_mark_key(trans, old, deleted,
...@@ -443,12 +441,16 @@ static int run_one_mem_trigger(struct btree_trans *trans, ...@@ -443,12 +441,16 @@ static int run_one_mem_trigger(struct btree_trans *trans,
return ret; return ret;
} }
static int run_one_trans_trigger(struct btree_trans *trans, static int run_one_trans_trigger(struct btree_trans *trans, struct btree_insert_entry *i,
struct btree_insert_entry *i, bool overwrite)
bool overwrite)
{ {
struct bkey_s_c old; /*
struct bkey unpacked; * Transactional triggers create new btree_insert_entries, so we can't
* pass them a pointer to a btree_insert_entry, that memory is going to
* move:
*/
struct bkey old_k = i->old_k;
struct bkey_s_c old = { &old_k, i->old_v };
int ret = 0; int ret = 0;
if ((i->flags & BTREE_TRIGGER_NORUN) || if ((i->flags & BTREE_TRIGGER_NORUN) ||
...@@ -469,8 +471,6 @@ static int run_one_trans_trigger(struct btree_trans *trans, ...@@ -469,8 +471,6 @@ static int run_one_trans_trigger(struct btree_trans *trans,
i->overwrite_trigger_run = true; i->overwrite_trigger_run = true;
} }
old = bch2_btree_path_peek_slot(i->path, &unpacked);
if (overwrite) { if (overwrite) {
ret = bch2_trans_mark_old(trans, old, i->flags); ret = bch2_trans_mark_old(trans, old, i->flags);
} else if (old.k->type == i->k->k.type && } else if (old.k->type == i->k->k.type &&
......
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