Commit 1f75ba4e authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: struct trans_for_each_path_inorder_iter

reducing our usage of path->idx
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 7f9821a7
...@@ -332,12 +332,12 @@ void bch2_assert_pos_locked(struct btree_trans *trans, enum btree_id id, ...@@ -332,12 +332,12 @@ void bch2_assert_pos_locked(struct btree_trans *trans, enum btree_id id,
struct bpos pos, bool key_cache) struct bpos pos, bool key_cache)
{ {
struct btree_path *path; struct btree_path *path;
unsigned idx; struct trans_for_each_path_inorder_iter iter;
struct printbuf buf = PRINTBUF; struct printbuf buf = PRINTBUF;
btree_trans_sort_paths(trans); btree_trans_sort_paths(trans);
trans_for_each_path_inorder(trans, path, idx) { trans_for_each_path_inorder(trans, path, iter) {
int cmp = cmp_int(path->btree_id, id) ?: int cmp = cmp_int(path->btree_id, id) ?:
cmp_int(path->cached, key_cache); cmp_int(path->cached, key_cache);
...@@ -1435,13 +1435,13 @@ static noinline __cold ...@@ -1435,13 +1435,13 @@ static noinline __cold
void __bch2_trans_paths_to_text(struct printbuf *out, struct btree_trans *trans, void __bch2_trans_paths_to_text(struct printbuf *out, struct btree_trans *trans,
bool nosort) bool nosort)
{ {
struct trans_for_each_path_inorder_iter iter;
struct btree_path *path; struct btree_path *path;
unsigned idx;
if (!nosort) if (!nosort)
btree_trans_sort_paths(trans); btree_trans_sort_paths(trans);
trans_for_each_path_inorder(trans, path, idx) trans_for_each_path_inorder(trans, path, iter)
bch2_btree_path_to_text(out, path); bch2_btree_path_to_text(out, path);
} }
...@@ -1555,14 +1555,15 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans, ...@@ -1555,14 +1555,15 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
struct btree_path *path; struct btree_path *path;
bool cached = flags & BTREE_ITER_CACHED; bool cached = flags & BTREE_ITER_CACHED;
bool intent = flags & BTREE_ITER_INTENT; bool intent = flags & BTREE_ITER_INTENT;
btree_path_idx_t i, path_pos = 0; struct trans_for_each_path_inorder_iter iter;
btree_path_idx_t path_pos = 0;
bch2_trans_verify_not_in_restart(trans); bch2_trans_verify_not_in_restart(trans);
bch2_trans_verify_locks(trans); bch2_trans_verify_locks(trans);
btree_trans_sort_paths(trans); btree_trans_sort_paths(trans);
trans_for_each_path_inorder(trans, path, i) { trans_for_each_path_inorder(trans, path, iter) {
if (__btree_path_cmp(path, if (__btree_path_cmp(path,
btree_id, btree_id,
cached, cached,
...@@ -1570,7 +1571,7 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans, ...@@ -1570,7 +1571,7 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
level) > 0) level) > 0)
break; break;
path_pos = path->idx; path_pos = iter.path_idx;
} }
if (path_pos && if (path_pos &&
...@@ -1592,7 +1593,7 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans, ...@@ -1592,7 +1593,7 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
path->level = level; path->level = level;
path->locks_want = locks_want; path->locks_want = locks_want;
path->nodes_locked = 0; path->nodes_locked = 0;
for (i = 0; i < ARRAY_SIZE(path->l); i++) for (unsigned i = 0; i < ARRAY_SIZE(path->l); i++)
path->l[i].b = ERR_PTR(-BCH_ERR_no_btree_node_init); path->l[i].b = ERR_PTR(-BCH_ERR_no_btree_node_init);
#ifdef TRACK_PATH_ALLOCATED #ifdef TRACK_PATH_ALLOCATED
path->ip_allocated = ip; path->ip_allocated = ip;
...@@ -2545,12 +2546,12 @@ static void btree_trans_verify_sorted_refs(struct btree_trans *trans) ...@@ -2545,12 +2546,12 @@ static void btree_trans_verify_sorted_refs(struct btree_trans *trans)
static void btree_trans_verify_sorted(struct btree_trans *trans) static void btree_trans_verify_sorted(struct btree_trans *trans)
{ {
struct btree_path *path, *prev = NULL; struct btree_path *path, *prev = NULL;
unsigned i; struct trans_for_each_path_inorder_iter iter;
if (!bch2_debug_check_iterators) if (!bch2_debug_check_iterators)
return; return;
trans_for_each_path_inorder(trans, path, i) { trans_for_each_path_inorder(trans, path, iter) {
if (prev && btree_path_cmp(prev, path) > 0) { if (prev && btree_path_cmp(prev, path) > 0) {
__bch2_dump_trans_paths_updates(trans, true); __bch2_dump_trans_paths_updates(trans, true);
panic("trans paths out of order!\n"); panic("trans paths out of order!\n");
...@@ -3085,7 +3086,7 @@ void bch2_btree_trans_to_text(struct printbuf *out, struct btree_trans *trans) ...@@ -3085,7 +3086,7 @@ void bch2_btree_trans_to_text(struct printbuf *out, struct btree_trans *trans)
continue; continue;
prt_printf(out, " path %u %c l=%u %s:", prt_printf(out, " path %u %c l=%u %s:",
path->idx, idx,
path->cached ? 'c' : 'b', path->cached ? 'c' : 'b',
path->level, path->level,
bch2_btree_id_str(path->btree_id)); bch2_btree_id_str(path->btree_id));
......
...@@ -125,10 +125,17 @@ static inline struct btree_path *prev_btree_path(struct btree_trans *trans, stru ...@@ -125,10 +125,17 @@ static inline struct btree_path *prev_btree_path(struct btree_trans *trans, stru
: NULL; : NULL;
} }
#define trans_for_each_path_inorder(_trans, _path, _i) \ struct trans_for_each_path_inorder_iter {
for (_i = 0; \ btree_path_idx_t sorted_idx;
((_path) = (_trans)->paths + trans->sorted[_i]), (_i) < (_trans)->nr_sorted;\ btree_path_idx_t path_idx;
_i++) };
#define trans_for_each_path_inorder(_trans, _path, _iter) \
for (_iter = (struct trans_for_each_path_inorder_iter) { 0 }; \
(_iter.path_idx = trans->sorted[_iter.sorted_idx], \
_path = (_trans)->paths + _iter.path_idx, \
_iter.sorted_idx < (_trans)->nr_sorted); \
_iter.sorted_idx++)
#define trans_for_each_path_inorder_reverse(_trans, _path, _i) \ #define trans_for_each_path_inorder_reverse(_trans, _path, _i) \
for (_i = trans->nr_sorted - 1; \ for (_i = trans->nr_sorted - 1; \
......
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