Btrfs: fix locking issue in btrfs_find_next_key
authorYan Zheng <zheng.yan@oracle.com>
Wed, 22 Jul 2009 13:59:00 +0000 (09:59 -0400)
committerChris Mason <chris.mason@oracle.com>
Wed, 22 Jul 2009 13:59:00 +0000 (09:59 -0400)
commit33c66f430bfa3a033e70470e4c93f967156b696d
tree5af7edc4564aa3f32033b364495828eb32b690a7
parente457afec60fdbd86b963d36f4a8a9285088c6043
Btrfs: fix locking issue in btrfs_find_next_key

When walking up the tree, btrfs_find_next_key assumes the upper level tree
block is properly locked. This isn't always true even path->keep_locks is 1.
This is because btrfs_find_next_key may advance path->slots[] several times
instead of only once.

When 'path->slots[level] >= btrfs_header_nritems(path->nodes[level])' is found,
we can't guarantee the original value of 'path->slots[level]' is
'btrfs_header_nritems(path->nodes[level]) - 1'. If it's not, the tree block at
'level + 1' isn't locked.

This patch fixes the issue by explicitly checking the locking state,
re-searching the tree if it's not locked.

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/ctree.c
fs/btrfs/relocation.c