From 8ee0134e03b541f3723d92586f1385ab50e42ac2 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 7 Sep 2021 20:23:30 -0400 Subject: [PATCH] bcachefs: Consolidate intent lock code in btree_path_up_until_good_node We need to take all needed intent locks when relocking an iterator: bch2_btree_path_traverse() had a special cased, faster version of this, but it really should be in up_until_good_node() so that set_pos() can use it too. Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_iter.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index d2ee6e9aa3701..fbe1a1170df6f 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -1352,10 +1352,7 @@ static inline unsigned btree_path_up_until_good_node(struct btree_trans *trans, struct btree_path *path, int check_pos) { - unsigned l = path->level; - - if (!path->nodes_locked) - btree_path_get_locks(trans, path, false, _THIS_IP_); + unsigned i, l = path->level; while (btree_path_node(path, l) && !btree_path_good_node(trans, path, l, check_pos)) { @@ -1364,6 +1361,17 @@ static inline unsigned btree_path_up_until_good_node(struct btree_trans *trans, l++; } + /* If we need intent locks, take them too: */ + for (i = l + 1; + i < path->locks_want && btree_path_node(path, i); + i++) + if (!bch2_btree_node_relock(trans, path, i)) + while (l <= i) { + btree_node_unlock(path, l); + path->l[l].b = BTREE_ITER_NO_NODE_UP; + l++; + } + return l; } @@ -1381,7 +1389,7 @@ static int btree_path_traverse_one(struct btree_trans *trans, unsigned flags, unsigned long trace_ip) { - unsigned l, depth_want = path->level; + unsigned depth_want = path->level; int ret = 0; /* @@ -1403,17 +1411,6 @@ static int btree_path_traverse_one(struct btree_trans *trans, path->level = btree_path_up_until_good_node(trans, path, 0); - /* If we need intent locks, take them too: */ - for (l = path->level + 1; - l < path->locks_want && btree_path_node(path, l); - l++) - if (!bch2_btree_node_relock(trans, path, l)) - while (path->level <= l) { - btree_node_unlock(path, path->level); - path->l[path->level].b = BTREE_ITER_NO_NODE_UP; - path->level++; - } - /* * Note: path->nodes[path->level] may be temporarily NULL here - that * would indicate to other code that we got to the end of the btree, -- 2.30.2