summaryrefslogtreecommitdiff
path: root/libbcachefs/btree_iter.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbcachefs/btree_iter.c')
-rw-r--r--libbcachefs/btree_iter.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/libbcachefs/btree_iter.c b/libbcachefs/btree_iter.c
index e0cd6c5..0d280e6 100644
--- a/libbcachefs/btree_iter.c
+++ b/libbcachefs/btree_iter.c
@@ -662,6 +662,32 @@ void bch2_btree_path_level_init(struct btree_trans *trans,
/* Btree path: fixups after btree node updates: */
+static void bch2_trans_revalidate_updates_in_node(struct btree_trans *trans, struct btree *b)
+{
+ struct bch_fs *c = trans->c;
+ struct btree_insert_entry *i;
+
+ trans_for_each_update(trans, i)
+ if (!i->cached &&
+ i->level == b->c.level &&
+ i->btree_id == b->c.btree_id &&
+ bpos_cmp(i->k->k.p, b->data->min_key) >= 0 &&
+ bpos_cmp(i->k->k.p, b->data->max_key) <= 0) {
+ i->old_v = bch2_btree_path_peek_slot(i->path, &i->old_k).v;
+
+ if (unlikely(trans->journal_replay_not_finished)) {
+ struct bkey_i *j_k =
+ bch2_journal_keys_peek_slot(c, i->btree_id, i->level,
+ i->k->k.p);
+
+ if (j_k) {
+ i->old_k = j_k->k;
+ i->old_v = &j_k->v;
+ }
+ }
+ }
+}
+
/*
* A btree node is being replaced - update the iterator to point to the new
* node:
@@ -685,6 +711,8 @@ void bch2_trans_node_add(struct btree_trans *trans, struct btree *b)
bch2_btree_path_level_init(trans, path, b);
}
+
+ bch2_trans_revalidate_updates_in_node(trans, b);
}
/*
@@ -697,6 +725,8 @@ void bch2_trans_node_reinit_iter(struct btree_trans *trans, struct btree *b)
trans_for_each_path_with_node(trans, b, path)
__btree_path_level_init(path, b->c.level);
+
+ bch2_trans_revalidate_updates_in_node(trans, b);
}
/* Btree path: traverse, set_pos: */
@@ -2598,14 +2628,9 @@ static inline void btree_path_list_remove(struct btree_trans *trans,
unsigned i;
EBUG_ON(path->sorted_idx >= trans->nr_sorted);
-#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
- trans->nr_sorted--;
- memmove_u64s_down_small(trans->sorted + path->sorted_idx,
- trans->sorted + path->sorted_idx + 1,
- DIV_ROUND_UP(trans->nr_sorted - path->sorted_idx, 8));
-#else
+
array_remove_item(trans->sorted, trans->nr_sorted, path->sorted_idx);
-#endif
+
for (i = path->sorted_idx; i < trans->nr_sorted; i++)
trans->paths[trans->sorted[i]].sorted_idx = i;
@@ -2629,15 +2654,7 @@ static inline void btree_path_list_add(struct btree_trans *trans,
trans->traverse_all_idx >= path->sorted_idx)
trans->traverse_all_idx++;
-#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
- memmove_u64s_up_small(trans->sorted + path->sorted_idx + 1,
- trans->sorted + path->sorted_idx,
- DIV_ROUND_UP(trans->nr_sorted - path->sorted_idx, 8));
- trans->nr_sorted++;
- trans->sorted[path->sorted_idx] = path->idx;
-#else
array_insert_item(trans->sorted, trans->nr_sorted, path->sorted_idx, path->idx);
-#endif
for (i = path->sorted_idx; i < trans->nr_sorted; i++)
trans->paths[trans->sorted[i]].sorted_idx = i;