• Chris Mason's avatar
    btrfs: fix lockups from btrfs_clear_path_blocking · 03813493
    Chris Mason authored
    commit f82c458a upstream.
    
    The fair reader/writer locks mean that btrfs_clear_path_blocking needs
    to strictly follow lock ordering rules even when we already have
    blocking locks on a given path.
    
    Before we can clear a blocking lock on the path, we need to make sure
    all of the locks have been converted to blocking.  This will remove lock
    inversions against anyone spinning in write_lock() against the buffers
    we're trying to get read locks on.  These inversions didn't exist before
    the fair read/writer locks, but now we need to be more careful.
    
    We papered over this deadlock in the past by changing
    btrfs_try_read_lock() to be a true trylock against both the spinlock and
    the blocking lock.  This was slower, and not sufficient to fix all the
    deadlocks.  This patch adds a btrfs_tree_read_lock_atomic(), which
    basically means get the spinlock but trylock on the blocking lock.
    Signed-off-by: default avatarChris Mason <clm@fb.com>
    Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
    Reported-by: default avatarPatrick Schmid <schmid@phys.ethz.ch>
    Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
    03813493
ctree.c 152 KB