bcachefs: Fix spurious transaction restarts

The check for whether locking a btree node would deadlock was wrong - we
have to check that interior nodes are locked before descendents, but
this check was wrong when consider cached vs. non cached iterators.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet
2020-10-28 14:18:18 -04:00
committed by Kent Overstreet
parent a301dc38ef
commit dcf141b9e1
2 changed files with 6 additions and 0 deletions

View File

@@ -244,6 +244,7 @@ bool __bch2_btree_node_lock(struct btree *b, struct bpos pos,
* we're about to lock, it must have the ancestors locked too:
*/
if (linked->btree_id == iter->btree_id &&
btree_iter_is_cached(linked) == btree_iter_is_cached(iter) &&
level > __fls(linked->nodes_locked)) {
if (!(trans->nounlock)) {
linked->locks_want =

View File

@@ -283,6 +283,11 @@ btree_iter_type(const struct btree_iter *iter)
return iter->flags & BTREE_ITER_TYPE;
}
static inline bool btree_iter_is_cached(const struct btree_iter *iter)
{
return btree_iter_type(iter) == BTREE_ITER_CACHED;
}
static inline struct btree_iter_level *iter_l(struct btree_iter *iter)
{
return iter->l + iter->level;