Lines Matching refs:path

97 static inline bool btree_path_pos_before_node(struct btree_path *path,  in btree_path_pos_before_node()  argument
100 return bpos_lt(path->pos, b->data->min_key); in btree_path_pos_before_node()
103 static inline bool btree_path_pos_after_node(struct btree_path *path, in btree_path_pos_after_node() argument
106 return bpos_gt(path->pos, b->key.k.p); in btree_path_pos_after_node()
109 static inline bool btree_path_pos_in_node(struct btree_path *path, in btree_path_pos_in_node() argument
112 return path->btree_id == b->c.btree_id && in btree_path_pos_in_node()
113 !btree_path_pos_before_node(path, b) && in btree_path_pos_in_node()
114 !btree_path_pos_after_node(path, b); in btree_path_pos_in_node()
122 struct btree_path *path) in bch2_btree_path_verify_cached() argument
125 bool locked = btree_node_locked(path, 0); in bch2_btree_path_verify_cached()
127 if (!bch2_btree_node_relock(trans, path, 0)) in bch2_btree_path_verify_cached()
130 ck = (void *) path->l[0].b; in bch2_btree_path_verify_cached()
131 BUG_ON(ck->key.btree_id != path->btree_id || in bch2_btree_path_verify_cached()
132 !bkey_eq(ck->key.pos, path->pos)); in bch2_btree_path_verify_cached()
135 btree_node_unlock(trans, path, 0); in bch2_btree_path_verify_cached()
139 struct btree_path *path, unsigned level) in bch2_btree_path_verify_level() argument
153 l = &path->l[level]; in bch2_btree_path_verify_level()
155 locked = btree_node_locked(path, level); in bch2_btree_path_verify_level()
157 if (path->cached) { in bch2_btree_path_verify_level()
159 bch2_btree_path_verify_cached(trans, path); in bch2_btree_path_verify_level()
163 if (!btree_path_node(path, level)) in bch2_btree_path_verify_level()
166 if (!bch2_btree_node_relock_notrace(trans, path, level)) in bch2_btree_path_verify_level()
169 BUG_ON(!btree_path_pos_in_node(path, l->b)); in bch2_btree_path_verify_level()
181 if (p && bkey_iter_pos_cmp(l->b, p, &path->pos) >= 0) { in bch2_btree_path_verify_level()
186 if (k && bkey_iter_pos_cmp(l->b, k, &path->pos) < 0) { in bch2_btree_path_verify_level()
192 btree_node_unlock(trans, path, level); in bch2_btree_path_verify_level()
195 bch2_bpos_to_text(&buf1, path->pos); in bch2_btree_path_verify_level()
221 struct btree_path *path) in bch2_btree_path_verify() argument
225 for (unsigned i = 0; i < (!path->cached ? BTREE_MAX_DEPTH : 1); i++) { in bch2_btree_path_verify()
226 if (!path->l[i].b) { in bch2_btree_path_verify()
227 BUG_ON(!path->cached && in bch2_btree_path_verify()
228 bch2_btree_id_root(c, path->btree_id)->b->c.level > i); in bch2_btree_path_verify()
232 bch2_btree_path_verify_level(trans, path, i); in bch2_btree_path_verify()
235 bch2_btree_path_verify_locks(path); in bch2_btree_path_verify()
240 struct btree_path *path; in bch2_trans_verify_paths() local
243 trans_for_each_path(trans, path, iter) in bch2_trans_verify_paths()
244 bch2_btree_path_verify(trans, path); in bch2_trans_verify_paths()
332 struct btree_path *path; in bch2_assert_pos_locked() local
338 trans_for_each_path_inorder(trans, path, iter) { in bch2_assert_pos_locked()
339 if (path->btree_id != id || in bch2_assert_pos_locked()
340 !btree_node_locked(path, 0) || in bch2_assert_pos_locked()
341 !path->should_be_locked) in bch2_assert_pos_locked()
344 if (!path->cached) { in bch2_assert_pos_locked()
345 if (bkey_ge(pos, path->l[0].b->data->min_key) && in bch2_assert_pos_locked()
346 bkey_le(pos, path->l[0].b->key.k.p)) in bch2_assert_pos_locked()
349 if (bkey_eq(pos, path->pos)) in bch2_assert_pos_locked()
363 struct btree_path *path, unsigned l) {} in bch2_btree_path_verify_level() argument
365 struct btree_path *path) {} in bch2_btree_path_verify() argument
391 static void __bch2_btree_path_fix_key_modified(struct btree_path *path, in __bch2_btree_path_fix_key_modified() argument
395 struct btree_path_level *l = &path->l[b->c.level]; in __bch2_btree_path_fix_key_modified()
400 if (bkey_iter_pos_cmp(l->b, where, &path->pos) < 0) in __bch2_btree_path_fix_key_modified()
408 struct btree_path *path; in bch2_btree_path_fix_key_modified() local
411 trans_for_each_path_with_node(trans, b, path, i) { in bch2_btree_path_fix_key_modified()
412 __bch2_btree_path_fix_key_modified(path, b, where); in bch2_btree_path_fix_key_modified()
413 bch2_btree_path_verify_level(trans, path, b->c.level); in bch2_btree_path_fix_key_modified()
417 static void __bch2_btree_node_iter_fix(struct btree_path *path, in __bch2_btree_node_iter_fix() argument
441 bkey_iter_pos_cmp(b, where, &path->pos) >= 0) { in __bch2_btree_node_iter_fix()
456 bkey_iter_pos_cmp(b, where, &path->pos) >= 0) { in __bch2_btree_node_iter_fix()
509 struct btree_path *path, in bch2_btree_node_iter_fix() argument
520 if (node_iter != &path->l[b->c.level].iter) { in bch2_btree_node_iter_fix()
521 __bch2_btree_node_iter_fix(path, b, node_iter, t, in bch2_btree_node_iter_fix()
564 struct btree_path *path, in btree_path_level_peek() argument
571 path->pos = k.k ? k.k->p : l->b->key.k.p; in btree_path_level_peek()
573 bch2_btree_path_verify_level(trans, path, l - path->l); in btree_path_level_peek()
578 struct btree_path *path, in btree_path_level_prev() argument
585 path->pos = k.k ? k.k->p : l->b->data->min_key; in btree_path_level_prev()
587 bch2_btree_path_verify_level(trans, path, l - path->l); in btree_path_level_prev()
591 static inline bool btree_path_advance_to_pos(struct btree_path *path, in btree_path_advance_to_pos() argument
599 bkey_iter_pos_cmp(l->b, k, &path->pos) < 0) { in btree_path_advance_to_pos()
610 static inline void __btree_path_level_init(struct btree_path *path, in __btree_path_level_init() argument
613 struct btree_path_level *l = &path->l[level]; in __btree_path_level_init()
615 bch2_btree_node_iter_init(&l->iter, l->b, &path->pos); in __btree_path_level_init()
626 struct btree_path *path, in bch2_btree_path_level_init() argument
629 BUG_ON(path->cached); in bch2_btree_path_level_init()
631 EBUG_ON(!btree_path_pos_in_node(path, b)); in bch2_btree_path_level_init()
633 path->l[b->c.level].lock_seq = six_lock_seq(&b->c.lock); in bch2_btree_path_level_init()
634 path->l[b->c.level].b = b; in bch2_btree_path_level_init()
635 __btree_path_level_init(path, b->c.level); in bch2_btree_path_level_init()
650 i->old_v = bch2_btree_path_peek_slot(trans->paths + i->path, &i->old_k).v; in bch2_trans_revalidate_updates_in_node()
670 struct btree_path *path, in bch2_trans_node_add() argument
675 BUG_ON(!btree_path_pos_in_node(path, b)); in bch2_trans_node_add()
677 while ((prev = prev_btree_path(trans, path)) && in bch2_trans_node_add()
679 path = prev; in bch2_trans_node_add()
682 path && btree_path_pos_in_node(path, b); in bch2_trans_node_add()
683 path = next_btree_path(trans, path)) in bch2_trans_node_add()
684 if (path->uptodate == BTREE_ITER_UPTODATE && !path->cached) { in bch2_trans_node_add()
686 btree_lock_want(path, b->c.level); in bch2_trans_node_add()
689 btree_node_unlock(trans, path, b->c.level); in bch2_trans_node_add()
691 mark_btree_node_locked(trans, path, b->c.level, t); in bch2_trans_node_add()
694 bch2_btree_path_level_init(trans, path, b); in bch2_trans_node_add()
706 struct btree_path *path; in bch2_trans_node_reinit_iter() local
709 trans_for_each_path_with_node(trans, b, path, i) in bch2_trans_node_reinit_iter()
710 __btree_path_level_init(path, b->c.level); in bch2_trans_node_reinit_iter()
718 struct btree_path *path, in btree_path_lock_root() argument
723 struct btree *b, **rootp = &bch2_btree_id_root(c, path->btree_id)->b; in btree_path_lock_root()
728 EBUG_ON(path->nodes_locked); in btree_path_lock_root()
732 path->level = READ_ONCE(b->c.level); in btree_path_lock_root()
734 if (unlikely(path->level < depth_want)) { in btree_path_lock_root()
741 path->level = depth_want; in btree_path_lock_root()
742 for (i = path->level; i < BTREE_MAX_DEPTH; i++) in btree_path_lock_root()
743 path->l[i].b = NULL; in btree_path_lock_root()
747 lock_type = __btree_lock_want(path, path->level); in btree_path_lock_root()
748 ret = btree_node_lock(trans, path, &b->c, in btree_path_lock_root()
749 path->level, lock_type, trace_ip); in btree_path_lock_root()
759 b->c.level == path->level && in btree_path_lock_root()
761 for (i = 0; i < path->level; i++) in btree_path_lock_root()
762 path->l[i].b = ERR_PTR(-BCH_ERR_no_btree_node_lock_root); in btree_path_lock_root()
763 path->l[path->level].b = b; in btree_path_lock_root()
764 for (i = path->level + 1; i < BTREE_MAX_DEPTH; i++) in btree_path_lock_root()
765 path->l[i].b = NULL; in btree_path_lock_root()
767 mark_btree_node_locked(trans, path, path->level, in btree_path_lock_root()
769 bch2_btree_path_level_init(trans, path, b); in btree_path_lock_root()
778 static int btree_path_prefetch(struct btree_trans *trans, struct btree_path *path) in btree_path_prefetch() argument
781 struct btree_path_level *l = path_l(path); in btree_path_prefetch()
786 ? (path->level > 1 ? 0 : 2) in btree_path_prefetch()
787 : (path->level > 1 ? 1 : 16); in btree_path_prefetch()
788 bool was_locked = btree_node_locked(path, path->level); in btree_path_prefetch()
794 if (!bch2_btree_node_relock(trans, path, path->level)) in btree_path_prefetch()
803 ret = bch2_btree_node_prefetch(trans, path, tmp.k, path->btree_id, in btree_path_prefetch()
804 path->level - 1); in btree_path_prefetch()
808 btree_node_unlock(trans, path, path->level); in btree_path_prefetch()
814 static int btree_path_prefetch_j(struct btree_trans *trans, struct btree_path *path, in btree_path_prefetch_j() argument
821 ? (path->level > 1 ? 0 : 2) in btree_path_prefetch_j()
822 : (path->level > 1 ? 1 : 16); in btree_path_prefetch_j()
823 bool was_locked = btree_node_locked(path, path->level); in btree_path_prefetch_j()
829 if (!bch2_btree_node_relock(trans, path, path->level)) in btree_path_prefetch_j()
838 ret = bch2_btree_node_prefetch(trans, path, tmp.k, path->btree_id, in btree_path_prefetch_j()
839 path->level - 1); in btree_path_prefetch_j()
843 btree_node_unlock(trans, path, path->level); in btree_path_prefetch_j()
850 struct btree_path *path, in btree_node_mem_ptr_set() argument
853 struct btree_path_level *l = &path->l[plevel]; in btree_node_mem_ptr_set()
854 bool locked = btree_node_locked(path, plevel); in btree_node_mem_ptr_set()
858 if (!bch2_btree_node_relock(trans, path, plevel)) in btree_node_mem_ptr_set()
868 btree_node_unlock(trans, path, plevel); in btree_node_mem_ptr_set()
872 struct btree_path *path, in btree_node_iter_and_journal_peek() argument
877 struct btree_path_level *l = path_l(path); in btree_node_iter_and_journal_peek()
882 __bch2_btree_and_journal_iter_init_node_iter(trans, &jiter, l->b, l->iter, path->pos); in btree_node_iter_and_journal_peek()
889 bch2_bpos_to_text(&buf, path->pos); in btree_node_iter_and_journal_peek()
902 ret = btree_path_prefetch_j(trans, path, &jiter); in btree_node_iter_and_journal_peek()
910 struct btree_path *path, in btree_path_down() argument
915 struct btree_path_level *l = path_l(path); in btree_path_down()
917 unsigned level = path->level - 1; in btree_path_down()
918 enum six_lock_type lock_type = __btree_lock_want(path, level); in btree_path_down()
922 EBUG_ON(!btree_node_locked(path, path->level)); in btree_path_down()
927 ret = btree_node_iter_and_journal_peek(trans, path, flags, &tmp); in btree_path_down()
936 bch2_bpos_to_text(&buf, path->pos); in btree_path_down()
950 ret = btree_path_prefetch(trans, path); in btree_path_down()
956 b = bch2_btree_node_get(trans, path, tmp.k, level, lock_type, trace_ip); in btree_path_down()
964 btree_node_mem_ptr_set(trans, path, level + 1, b); in btree_path_down()
966 if (btree_node_read_locked(path, level + 1)) in btree_path_down()
967 btree_node_unlock(trans, path, level + 1); in btree_path_down()
969 mark_btree_node_locked(trans, path, level, in btree_path_down()
971 path->level = level; in btree_path_down()
972 bch2_btree_path_level_init(trans, path, b); in btree_path_down()
974 bch2_btree_path_verify_locks(path); in btree_path_down()
983 struct btree_path *path; in bch2_btree_path_traverse_all() local
996 trans_for_each_path(trans, path, i) in bch2_btree_path_traverse_all()
997 path->should_be_locked = false; in bch2_btree_path_traverse_all()
1055 static inline bool btree_path_check_pos_in_node(struct btree_path *path, in btree_path_check_pos_in_node() argument
1058 if (check_pos < 0 && btree_path_pos_before_node(path, path->l[l].b)) in btree_path_check_pos_in_node()
1060 if (check_pos > 0 && btree_path_pos_after_node(path, path->l[l].b)) in btree_path_check_pos_in_node()
1066 struct btree_path *path, in btree_path_good_node() argument
1069 return is_btree_node(path, l) && in btree_path_good_node()
1070 bch2_btree_node_relock(trans, path, l) && in btree_path_good_node()
1071 btree_path_check_pos_in_node(path, l, check_pos); in btree_path_good_node()
1075 struct btree_path *path, in btree_path_set_level_down() argument
1080 path->level = new_level; in btree_path_set_level_down()
1082 for (l = path->level + 1; l < BTREE_MAX_DEPTH; l++) in btree_path_set_level_down()
1083 if (btree_lock_want(path, l) == BTREE_NODE_UNLOCKED) in btree_path_set_level_down()
1084 btree_node_unlock(trans, path, l); in btree_path_set_level_down()
1086 btree_path_set_dirty(path, BTREE_ITER_NEED_TRAVERSE); in btree_path_set_level_down()
1087 bch2_btree_path_verify(trans, path); in btree_path_set_level_down()
1091 struct btree_path *path, in __btree_path_up_until_good_node() argument
1094 unsigned i, l = path->level; in __btree_path_up_until_good_node()
1096 while (btree_path_node(path, l) && in __btree_path_up_until_good_node()
1097 !btree_path_good_node(trans, path, l, check_pos)) in __btree_path_up_until_good_node()
1098 __btree_path_set_level_up(trans, path, l++); in __btree_path_up_until_good_node()
1102 i < path->locks_want && btree_path_node(path, i); in __btree_path_up_until_good_node()
1104 if (!bch2_btree_node_relock(trans, path, i)) { in __btree_path_up_until_good_node()
1106 __btree_path_set_level_up(trans, path, l++); in __btree_path_up_until_good_node()
1114 struct btree_path *path, in btree_path_up_until_good_node() argument
1117 return likely(btree_node_locked(path, path->level) && in btree_path_up_until_good_node()
1118 btree_path_check_pos_in_node(path, path->level, check_pos)) in btree_path_up_until_good_node()
1119 ? path->level in btree_path_up_until_good_node()
1120 : __btree_path_up_until_good_node(trans, path, check_pos); in btree_path_up_until_good_node()
1137 struct btree_path *path = &trans->paths[path_idx]; in bch2_btree_path_traverse_one() local
1138 unsigned depth_want = path->level; in bch2_btree_path_traverse_one()
1147 trace_btree_path_traverse_start(trans, path); in bch2_btree_path_traverse_one()
1153 if (path->should_be_locked) { in bch2_btree_path_traverse_one()
1154 ret = bch2_btree_path_relock(trans, path, trace_ip); in bch2_btree_path_traverse_one()
1158 if (path->cached) { in bch2_btree_path_traverse_one()
1159 ret = bch2_btree_path_traverse_cached(trans, path, flags); in bch2_btree_path_traverse_one()
1163 path = &trans->paths[path_idx]; in bch2_btree_path_traverse_one()
1165 if (unlikely(path->level >= BTREE_MAX_DEPTH)) in bch2_btree_path_traverse_one()
1168 path->level = btree_path_up_until_good_node(trans, path, 0); in bch2_btree_path_traverse_one()
1169 unsigned max_level = path->level; in bch2_btree_path_traverse_one()
1171 EBUG_ON(btree_path_node(path, path->level) && in bch2_btree_path_traverse_one()
1172 !btree_node_locked(path, path->level)); in bch2_btree_path_traverse_one()
1180 while (path->level > depth_want) { in bch2_btree_path_traverse_one()
1181 ret = btree_path_node(path, path->level) in bch2_btree_path_traverse_one()
1182 ? btree_path_down(trans, path, flags, trace_ip) in bch2_btree_path_traverse_one()
1183 : btree_path_lock_root(trans, path, depth_want, trace_ip); in bch2_btree_path_traverse_one()
1194 __bch2_btree_path_unlock(trans, path); in bch2_btree_path_traverse_one()
1195 path->level = depth_want; in bch2_btree_path_traverse_one()
1196 path->l[path->level].b = ERR_PTR(ret); in bch2_btree_path_traverse_one()
1201 if (unlikely(max_level > path->level)) { in bch2_btree_path_traverse_one()
1205 trans_for_each_path_with_node(trans, path_l(path)->b, linked, iter) in bch2_btree_path_traverse_one()
1206 for (unsigned j = path->level + 1; j < max_level; j++) in bch2_btree_path_traverse_one()
1207 linked->l[j] = path->l[j]; in bch2_btree_path_traverse_one()
1211 path->uptodate = BTREE_ITER_UPTODATE; in bch2_btree_path_traverse_one()
1212 trace_btree_path_traverse_end(trans, path); in bch2_btree_path_traverse_one()
1218 bch2_btree_path_verify(trans, path); in bch2_btree_path_traverse_one()
1253 btree_path_idx_t path, bool intent, unsigned long ip) in __bch2_btree_path_make_mut() argument
1255 struct btree_path *old = trans->paths + path; in __bch2_btree_path_make_mut()
1256 __btree_path_put(trans, trans->paths + path, intent); in __bch2_btree_path_make_mut()
1257 path = btree_path_clone(trans, path, intent, ip); in __bch2_btree_path_make_mut()
1258 trace_btree_path_clone(trans, old, trans->paths + path); in __bch2_btree_path_make_mut()
1259 trans->paths[path].preserve = false; in __bch2_btree_path_make_mut()
1260 return path; in __bch2_btree_path_make_mut()
1277 struct btree_path *path = trans->paths + path_idx; in __bch2_btree_path_set_pos() local
1278 path->pos = new_pos; in __bch2_btree_path_set_pos()
1281 if (unlikely(path->cached)) { in __bch2_btree_path_set_pos()
1282 btree_node_unlock(trans, path, 0); in __bch2_btree_path_set_pos()
1283 path->l[0].b = ERR_PTR(-BCH_ERR_no_btree_node_up); in __bch2_btree_path_set_pos()
1284 btree_path_set_dirty(path, BTREE_ITER_NEED_TRAVERSE); in __bch2_btree_path_set_pos()
1288 unsigned level = btree_path_up_until_good_node(trans, path, cmp); in __bch2_btree_path_set_pos()
1290 if (btree_path_node(path, level)) { in __bch2_btree_path_set_pos()
1291 struct btree_path_level *l = &path->l[level]; in __bch2_btree_path_set_pos()
1293 BUG_ON(!btree_node_locked(path, level)); in __bch2_btree_path_set_pos()
1301 !btree_path_advance_to_pos(path, l, 8)) in __bch2_btree_path_set_pos()
1302 bch2_btree_node_iter_init(&l->iter, l->b, &path->pos); in __bch2_btree_path_set_pos()
1312 if (unlikely(level != path->level)) { in __bch2_btree_path_set_pos()
1313 btree_path_set_dirty(path, BTREE_ITER_NEED_TRAVERSE); in __bch2_btree_path_set_pos()
1314 __bch2_btree_path_unlock(trans, path); in __bch2_btree_path_set_pos()
1317 bch2_btree_path_verify(trans, path); in __bch2_btree_path_set_pos()
1323 static struct btree_path *have_path_at_pos(struct btree_trans *trans, struct btree_path *path) in have_path_at_pos() argument
1327 sib = prev_btree_path(trans, path); in have_path_at_pos()
1328 if (sib && !btree_path_cmp(sib, path)) in have_path_at_pos()
1331 sib = next_btree_path(trans, path); in have_path_at_pos()
1332 if (sib && !btree_path_cmp(sib, path)) in have_path_at_pos()
1338 static struct btree_path *have_node_at_pos(struct btree_trans *trans, struct btree_path *path) in have_node_at_pos() argument
1342 sib = prev_btree_path(trans, path); in have_node_at_pos()
1343 if (sib && sib->level == path->level && path_l(sib)->b == path_l(path)->b) in have_node_at_pos()
1346 sib = next_btree_path(trans, path); in have_node_at_pos()
1347 if (sib && sib->level == path->level && path_l(sib)->b == path_l(path)->b) in have_node_at_pos()
1353 static inline void __bch2_path_free(struct btree_trans *trans, btree_path_idx_t path) in __bch2_path_free() argument
1355 __bch2_btree_path_unlock(trans, trans->paths + path); in __bch2_path_free()
1356 btree_path_list_remove(trans, trans->paths + path); in __bch2_path_free()
1357 __clear_bit(path, trans->paths_allocated); in __bch2_path_free()
1360 static bool bch2_btree_path_can_relock(struct btree_trans *trans, struct btree_path *path) in bch2_btree_path_can_relock() argument
1362 unsigned l = path->level; in bch2_btree_path_can_relock()
1365 if (!btree_path_node(path, l)) in bch2_btree_path_can_relock()
1368 if (!is_btree_node(path, l)) in bch2_btree_path_can_relock()
1371 if (path->l[l].lock_seq != path->l[l].b->c.lock.seq) in bch2_btree_path_can_relock()
1375 } while (l < path->locks_want); in bch2_btree_path_can_relock()
1382 struct btree_path *path = trans->paths + path_idx, *dup; in bch2_path_put() local
1384 if (!__btree_path_put(trans, path, intent)) in bch2_path_put()
1387 dup = path->preserve in bch2_path_put()
1388 ? have_path_at_pos(trans, path) in bch2_path_put()
1389 : have_node_at_pos(trans, path); in bch2_path_put()
1393 if (!dup && !(!path->preserve && !is_btree_node(path, path->level))) in bch2_path_put()
1396 if (path->should_be_locked && !trans->restarted) { in bch2_path_put()
1407 dup->preserve |= path->preserve; in bch2_path_put()
1408 dup->should_be_locked |= path->should_be_locked; in bch2_path_put()
1414 static void bch2_path_put_nokeep(struct btree_trans *trans, btree_path_idx_t path, in bch2_path_put_nokeep() argument
1417 if (!__btree_path_put(trans, trans->paths + path, intent)) in bch2_path_put_nokeep()
1420 __bch2_path_free(trans, path); in bch2_path_put_nokeep()
1487 struct btree_path *path = trans->paths + path_idx; in bch2_btree_path_to_text_short() local
1490 path_idx, path->ref, path->intent_ref, in bch2_btree_path_to_text_short()
1491 path->preserve ? 'P' : ' ', in bch2_btree_path_to_text_short()
1492 path->should_be_locked ? 'S' : ' ', in bch2_btree_path_to_text_short()
1493 path->cached ? 'C' : 'B', in bch2_btree_path_to_text_short()
1494 bch2_btree_id_str(path->btree_id), in bch2_btree_path_to_text_short()
1495 path->level); in bch2_btree_path_to_text_short()
1496 bch2_bpos_to_text(out, path->pos); in bch2_btree_path_to_text_short()
1498 if (!path->cached && btree_node_locked(path, path->level)) { in bch2_btree_path_to_text_short()
1500 struct btree *b = path_l(path)->b; in bch2_btree_path_to_text_short()
1507 prt_printf(out, " %pS", (void *) path->ip_allocated); in bch2_btree_path_to_text_short()
1531 struct btree_path *path = trans->paths + path_idx; in bch2_btree_path_to_text() local
1533 prt_printf(out, " uptodate %u locks_want %u", path->uptodate, path->locks_want); in bch2_btree_path_to_text()
1539 btree_node_locked_str(btree_node_locked_type(path, l)), in bch2_btree_path_to_text()
1540 path->l[l].lock_seq); in bch2_btree_path_to_text()
1542 int ret = PTR_ERR_OR_ZERO(path->l[l].b); in bch2_btree_path_to_text()
1546 prt_printf(out, "%px", path->l[l].b); in bch2_btree_path_to_text()
1699 struct btree_path *path = &trans->paths[idx]; in btree_path_alloc() local
1700 path->ref = 0; in btree_path_alloc()
1701 path->intent_ref = 0; in btree_path_alloc()
1702 path->nodes_locked = 0; in btree_path_alloc()
1714 struct btree_path *path; in bch2_path_get() local
1726 trans_for_each_path_inorder(trans, path, iter) { in bch2_path_get()
1727 if (__btree_path_cmp(path, in bch2_path_get()
1745 path = trans->paths + path_idx; in bch2_path_get()
1748 path = trans->paths + path_idx; in bch2_path_get()
1750 __btree_path_get(trans, path, intent); in bch2_path_get()
1751 path->pos = pos; in bch2_path_get()
1752 path->btree_id = btree_id; in bch2_path_get()
1753 path->cached = cached; in bch2_path_get()
1754 path->uptodate = BTREE_ITER_NEED_TRAVERSE; in bch2_path_get()
1755 path->should_be_locked = false; in bch2_path_get()
1756 path->level = level; in bch2_path_get()
1757 path->locks_want = locks_want; in bch2_path_get()
1758 path->nodes_locked = 0; in bch2_path_get()
1759 for (unsigned i = 0; i < ARRAY_SIZE(path->l); i++) in bch2_path_get()
1760 path->l[i].b = ERR_PTR(-BCH_ERR_no_btree_node_init); in bch2_path_get()
1762 path->ip_allocated = ip; in bch2_path_get()
1766 trace_btree_path_alloc(trans, path); in bch2_path_get()
1770 path->preserve = true; in bch2_path_get()
1772 if (path->intent_ref) in bch2_path_get()
1784 if (locks_want > path->locks_want) in bch2_path_get()
1785 bch2_btree_path_upgrade_noupgrade_sibs(trans, path, locks_want, NULL); in bch2_path_get()
1800 struct btree_path *path = trans->paths + path_idx; in bch2_path_get_unlocked_mut() local
1801 bch2_btree_path_downgrade(trans, path); in bch2_path_get_unlocked_mut()
1802 __bch2_btree_path_unlock(trans, path); in bch2_path_get_unlocked_mut()
1806 struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *path, struct bkey *u) in bch2_btree_path_peek_slot() argument
1809 struct btree_path_level *l = path_l(path); in bch2_btree_path_peek_slot()
1816 EBUG_ON(path->uptodate != BTREE_ITER_UPTODATE); in bch2_btree_path_peek_slot()
1817 EBUG_ON(!btree_node_locked(path, path->level)); in bch2_btree_path_peek_slot()
1819 if (!path->cached) { in bch2_btree_path_peek_slot()
1823 EBUG_ON(k.k && bkey_deleted(k.k) && bpos_eq(k.k->p, path->pos)); in bch2_btree_path_peek_slot()
1825 if (!k.k || !bpos_eq(path->pos, k.k->p)) in bch2_btree_path_peek_slot()
1828 struct bkey_cached *ck = (void *) path->l[0].b; in bch2_btree_path_peek_slot()
1832 EBUG_ON(path->btree_id != ck->key.btree_id || in bch2_btree_path_peek_slot()
1833 !bkey_eq(path->pos, ck->key.pos)); in bch2_btree_path_peek_slot()
1842 u->p = path->pos; in bch2_btree_path_peek_slot()
1851 if (!iter->path || trans->restarted) in bch2_set_btree_iter_dontneed()
1854 struct btree_path *path = btree_iter_path(trans, iter); in bch2_set_btree_iter_dontneed() local
1855 path->preserve = false; in bch2_set_btree_iter_dontneed()
1856 if (path->ref == 1) in bch2_set_btree_iter_dontneed()
1857 path->should_be_locked = false; in bch2_set_btree_iter_dontneed()
1864 return bch2_btree_path_traverse(iter->trans, iter->path, iter->flags); in __bch2_btree_iter_traverse()
1875 iter->path = bch2_btree_path_set_pos(trans, iter->path, in bch2_btree_iter_traverse()
1880 ret = bch2_btree_path_traverse(iter->trans, iter->path, iter->flags); in bch2_btree_iter_traverse()
1884 struct btree_path *path = btree_iter_path(trans, iter); in bch2_btree_iter_traverse() local
1885 if (btree_path_node(path, path->level)) in bch2_btree_iter_traverse()
1886 btree_path_set_should_be_locked(trans, path); in bch2_btree_iter_traverse()
1898 EBUG_ON(trans->paths[iter->path].cached); in bch2_btree_iter_peek_node()
1901 ret = bch2_btree_path_traverse(trans, iter->path, iter->flags); in bch2_btree_iter_peek_node()
1905 struct btree_path *path = btree_iter_path(trans, iter); in bch2_btree_iter_peek_node() local
1906 b = btree_path_node(path, path->level); in bch2_btree_iter_peek_node()
1915 iter->path = bch2_btree_path_set_pos(trans, iter->path, b->key.k.p, in bch2_btree_iter_peek_node()
1947 EBUG_ON(trans->paths[iter->path].cached); in bch2_btree_iter_next_node()
1951 ret = bch2_btree_path_traverse(trans, iter->path, iter->flags); in bch2_btree_iter_next_node()
1956 struct btree_path *path = btree_iter_path(trans, iter); in bch2_btree_iter_next_node() local
1959 if (!btree_path_node(path, path->level)) in bch2_btree_iter_next_node()
1963 if (!btree_path_node(path, path->level + 1)) { in bch2_btree_iter_next_node()
1964 btree_path_set_level_up(trans, path); in bch2_btree_iter_next_node()
1968 if (!bch2_btree_node_relock(trans, path, path->level + 1)) { in bch2_btree_iter_next_node()
1969 __bch2_btree_path_unlock(trans, path); in bch2_btree_iter_next_node()
1970 path->l[path->level].b = ERR_PTR(-BCH_ERR_no_btree_node_relock); in bch2_btree_iter_next_node()
1971 path->l[path->level + 1].b = ERR_PTR(-BCH_ERR_no_btree_node_relock); in bch2_btree_iter_next_node()
1972 btree_path_set_dirty(path, BTREE_ITER_NEED_TRAVERSE); in bch2_btree_iter_next_node()
1973 trace_and_count(trans->c, trans_restart_relock_next_node, trans, _THIS_IP_, path); in bch2_btree_iter_next_node()
1978 b = btree_path_node(path, path->level + 1); in bch2_btree_iter_next_node()
1981 __btree_path_set_level_up(trans, path, path->level++); in bch2_btree_iter_next_node()
1983 if (btree_lock_want(path, path->level + 1) == BTREE_NODE_UNLOCKED) in bch2_btree_iter_next_node()
1984 btree_node_unlock(trans, path, path->level + 1); in bch2_btree_iter_next_node()
1990 iter->path = bch2_btree_path_set_pos(trans, iter->path, in bch2_btree_iter_next_node()
1995 path = btree_iter_path(trans, iter); in bch2_btree_iter_next_node()
1996 btree_path_set_level_down(trans, path, iter->min_depth); in bch2_btree_iter_next_node()
1998 ret = bch2_btree_path_traverse(trans, iter->path, iter->flags); in bch2_btree_iter_next_node()
2002 path = btree_iter_path(trans, iter); in bch2_btree_iter_next_node()
2003 b = path->l[path->level].b; in bch2_btree_iter_next_node()
2009 iter->path = bch2_btree_path_set_pos(trans, iter->path, b->key.k.p, in bch2_btree_iter_next_node()
2072 struct btree_path *path = btree_iter_path(trans, iter); in bch2_btree_trans_peek_updates() local
2073 struct bpos end = path_l(path)->b->key.k.p; in bch2_btree_trans_peek_updates()
2078 bpos_ge(i->k->k.p, path->pos) && in bch2_btree_trans_peek_updates()
2102 struct btree_path *path = btree_iter_path(trans, iter); in bch2_btree_journal_peek() local
2105 path->level, in bch2_btree_journal_peek()
2106 path->pos, in bch2_btree_journal_peek()
2115 struct btree_path *path = btree_iter_path(trans, iter); in btree_trans_peek_slot_journal() local
2116 struct bkey_i *k = bch2_btree_journal_peek(trans, iter, path->pos); in btree_trans_peek_slot_journal()
2131 struct btree_path *path = btree_iter_path(trans, iter); in btree_trans_peek_journal() local
2134 k.k ? k.k->p : path_l(path)->b->key.k.p); in btree_trans_peek_journal()
2206 iter->path = bch2_btree_path_set_pos(trans, iter->path, search_key, in __bch2_btree_iter_peek()
2210 ret = bch2_btree_path_traverse(trans, iter->path, iter->flags); in __bch2_btree_iter_peek()
2218 struct btree_path *path = btree_iter_path(trans, iter); in __bch2_btree_iter_peek() local
2219 l = path_l(path); in __bch2_btree_iter_peek()
2228 btree_path_set_should_be_locked(trans, path); in __bch2_btree_iter_peek()
2355 __btree_path_get(trans, trans->paths + iter->path, iter->flags & BTREE_ITER_intent); in bch2_btree_iter_peek_upto()
2356 iter->update_path = iter->path; in bch2_btree_iter_peek_upto()
2407 iter->path = bch2_btree_path_set_pos(trans, iter->path, k.k->p, in bch2_btree_iter_peek_upto()
2485 iter->path = bch2_btree_path_set_pos(trans, iter->path, search_key, in bch2_btree_iter_peek_prev()
2489 ret = bch2_btree_path_traverse(trans, iter->path, iter->flags); in bch2_btree_iter_peek_prev()
2497 struct btree_path *path = btree_iter_path(trans, iter); in bch2_btree_iter_peek_prev() local
2499 k = btree_path_level_peek(trans, path, &path->l[0], &iter->k); in bch2_btree_iter_peek_prev()
2504 k = btree_path_level_prev(trans, path, &path->l[0], &iter->k); in bch2_btree_iter_peek_prev()
2521 bch2_path_put_nokeep(trans, iter->path, in bch2_btree_iter_peek_prev()
2523 iter->path = saved_path; in bch2_btree_iter_peek_prev()
2536 saved_path = btree_path_clone(trans, iter->path, in bch2_btree_iter_peek_prev()
2539 path = btree_iter_path(trans, iter); in bch2_btree_iter_peek_prev()
2540 trace_btree_path_save_pos(trans, path, trans->paths + saved_path); in bch2_btree_iter_peek_prev()
2557 btree_path_set_should_be_locked(trans, path); in bch2_btree_iter_peek_prev()
2559 } else if (likely(!bpos_eq(path->l[0].b->data->min_key, POS_MIN))) { in bch2_btree_iter_peek_prev()
2561 search_key = bpos_predecessor(path->l[0].b->data->min_key); in bch2_btree_iter_peek_prev()
2625 iter->path = bch2_btree_path_set_pos(trans, iter->path, search_key, in bch2_btree_iter_peek_slot()
2629 ret = bch2_btree_path_traverse(trans, iter->path, iter->flags); in bch2_btree_iter_peek_slot()
2658 k = bch2_btree_path_peek_slot(trans->paths + iter->path, &iter->k); in bch2_btree_iter_peek_slot()
2760 struct btree_path *path; in btree_trans_verify_sorted_refs() local
2765 trans_for_each_path(trans, path, i) { in btree_trans_verify_sorted_refs()
2766 BUG_ON(path->sorted_idx >= trans->nr_sorted); in btree_trans_verify_sorted_refs()
2767 BUG_ON(trans->sorted[path->sorted_idx] != i); in btree_trans_verify_sorted_refs()
2780 struct btree_path *path, *prev = NULL; in btree_trans_verify_sorted() local
2786 trans_for_each_path_inorder(trans, path, iter) { in btree_trans_verify_sorted()
2787 if (prev && btree_path_cmp(prev, path) > 0) { in btree_trans_verify_sorted()
2791 prev = path; in btree_trans_verify_sorted()
2841 struct btree_path *path) in btree_path_list_remove() argument
2843 EBUG_ON(path->sorted_idx >= trans->nr_sorted); in btree_path_list_remove()
2846 memmove_u64s_down_small(trans->sorted + path->sorted_idx, in btree_path_list_remove()
2847 trans->sorted + path->sorted_idx + 1, in btree_path_list_remove()
2848 DIV_ROUND_UP(trans->nr_sorted - path->sorted_idx, in btree_path_list_remove()
2851 array_remove_item(trans->sorted, trans->nr_sorted, path->sorted_idx); in btree_path_list_remove()
2853 for (unsigned i = path->sorted_idx; i < trans->nr_sorted; i++) in btree_path_list_remove()
2861 struct btree_path *path = trans->paths + path_idx; in btree_path_list_add() local
2863 path->sorted_idx = pos ? trans->paths[pos].sorted_idx + 1 : trans->nr_sorted; in btree_path_list_add()
2866 memmove_u64s_up_small(trans->sorted + path->sorted_idx + 1, in btree_path_list_add()
2867 trans->sorted + path->sorted_idx, in btree_path_list_add()
2868 DIV_ROUND_UP(trans->nr_sorted - path->sorted_idx, in btree_path_list_add()
2871 trans->sorted[path->sorted_idx] = path_idx; in btree_path_list_add()
2873 array_insert_item(trans->sorted, trans->nr_sorted, path->sorted_idx, path_idx); in btree_path_list_add()
2876 for (unsigned i = path->sorted_idx; i < trans->nr_sorted; i++) in btree_path_list_add()
2887 if (iter->path) in bch2_trans_iter_exit()
2888 bch2_path_put(trans, iter->path, in bch2_trans_iter_exit()
2893 iter->path = 0; in bch2_trans_iter_exit()
2927 struct btree_path *path = btree_iter_path(trans, iter); in bch2_trans_node_iter_init() local
2928 BUG_ON(path->locks_want < min(locks_want, BTREE_MAX_DEPTH)); in bch2_trans_node_iter_init()
2929 BUG_ON(path->level != depth); in bch2_trans_node_iter_init()
2941 if (src->path) in bch2_trans_copy_iter()
2942 __btree_path_get(trans, trans->paths + src->path, src->flags & BTREE_ITER_intent); in bch2_trans_copy_iter()
3037 struct btree_path *path; in bch2_trans_srcu_unlock() local
3040 trans_for_each_path(trans, path, i) in bch2_trans_srcu_unlock()
3041 if (path->cached && !btree_node_locked(path, 0)) in bch2_trans_srcu_unlock()
3042 path->l[0].b = ERR_PTR(-BCH_ERR_no_btree_node_srcu_reset); in bch2_trans_srcu_unlock()
3071 struct btree_path *path; in bch2_trans_begin() local
3081 trans_for_each_path(trans, path, i) { in bch2_trans_begin()
3082 path->should_be_locked = false; in bch2_trans_begin()
3089 if (!trans->restarted && path->btree_id != BTREE_ID_subvolumes) in bch2_trans_begin()
3090 path->preserve = false; in bch2_trans_begin()
3097 if (!path->ref && !path->preserve) in bch2_trans_begin()
3100 path->preserve = false; in bch2_trans_begin()
3241 struct btree_path *path; in check_btree_paths_leaked() local
3244 trans_for_each_path(trans, path, i) in check_btree_paths_leaked()
3245 if (path->ref) in check_btree_paths_leaked()
3250 trans_for_each_path(trans, path, i) in check_btree_paths_leaked()
3251 if (path->ref) in check_btree_paths_leaked()
3253 bch2_btree_id_str(path->btree_id), in check_btree_paths_leaked()
3254 (void *) path->ip_allocated); in check_btree_paths_leaked()
3268 __btree_path_put(trans, trans->paths + i->path, true); in bch2_trans_put()
3377 struct btree_path *path = paths + idx; in bch2_btree_trans_to_text() local
3378 if (!path->nodes_locked) in bch2_btree_trans_to_text()
3383 path->cached ? 'c' : 'b', in bch2_btree_trans_to_text()
3384 path->level, in bch2_btree_trans_to_text()
3385 bch2_btree_id_str(path->btree_id)); in bch2_btree_trans_to_text()
3386 bch2_bpos_to_text(out, path->pos); in bch2_btree_trans_to_text()
3390 if (btree_node_locked(path, l) && in bch2_btree_trans_to_text()
3391 !IS_ERR_OR_NULL(b = (void *) READ_ONCE(path->l[l].b))) { in bch2_btree_trans_to_text()
3393 lock_types[btree_node_locked_type(path, l)], l); in bch2_btree_trans_to_text()