• Yan Zheng's avatar
    Btrfs: fix locking issue in btrfs_find_next_key · 33c66f43
    Yan Zheng authored
    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: default avatarYan Zheng <zheng.yan@oracle.com>
    Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    33c66f43
relocation.c 87.3 KB