btrfs: cleanup the locking in btrfs_next_old_leaf

We are carrying around this next_rw_lock from when we would do spinning
vs blocking read locks.  Now that we have the rwsem locking we can
simply use the read lock flag unconditionally and the read lock helpers.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2020-11-06 16:27:29 -05:00 committed by David Sterba
parent b2598edf8b
commit ffeb03cfe2

View File

@ -5272,7 +5272,6 @@ int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
struct btrfs_key key;
u32 nritems;
int ret;
int next_rw_lock = 0;
nritems = btrfs_header_nritems(path->nodes[0]);
if (nritems == 0)
@ -5282,7 +5281,6 @@ int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
again:
level = 1;
next = NULL;
next_rw_lock = 0;
btrfs_release_path(path);
path->keep_locks = 1;
@ -5346,12 +5344,11 @@ again:
}
if (next) {
btrfs_tree_unlock_rw(next, next_rw_lock);
btrfs_tree_read_unlock(next);
free_extent_buffer(next);
}
next = c;
next_rw_lock = path->locks[level];
ret = read_block_for_search(root, path, &next, level,
slot, &key);
if (ret == -EAGAIN)
@ -5382,7 +5379,6 @@ again:
BTRFS_NESTING_RIGHT,
path->recurse);
}
next_rw_lock = BTRFS_READ_LOCK;
}
break;
}
@ -5391,13 +5387,13 @@ again:
level--;
c = path->nodes[level];
if (path->locks[level])
btrfs_tree_unlock_rw(c, path->locks[level]);
btrfs_tree_read_unlock(c);
free_extent_buffer(c);
path->nodes[level] = next;
path->slots[level] = 0;
if (!path->skip_locking)
path->locks[level] = next_rw_lock;
path->locks[level] = BTRFS_READ_LOCK;
if (!level)
break;
@ -5411,11 +5407,9 @@ again:
goto done;
}
if (!path->skip_locking) {
if (!path->skip_locking)
__btrfs_tree_read_lock(next, BTRFS_NESTING_RIGHT,
path->recurse);
next_rw_lock = BTRFS_READ_LOCK;
}
}
ret = 0;
done: