• Filipe Manana's avatar
    btrfs: avoid blocking nowait dio when locking file range · 59094403
    Filipe Manana authored
    If we are doing a NOWAIT direct IO read/write, we can block when locking
    the file range at btrfs_dio_iomap_begin(), as it's possible the range (or
    a part of it) is already locked by another task (mmap writes, another
    direct IO read/write racing with us, fiemap, etc). We are also waiting for
    completion of any ordered extent we find in the range, which also can
    block us for a significant amount of time.
    
    There's also the incorrect fallback to buffered IO (returning -ENOTBLK)
    when we are dealing with a NOWAIT request and we can't proceed. In this
    case we should be returning -EAGAIN, as falling back to buffered IO can
    result in blocking for many different reasons, so that the caller can
    delegate a retry to a context where blocking is more acceptable.
    
    Fix these cases by:
    
    1) Doing a try lock on the file range and failing with -EAGAIN if we
       can not lock right away;
    
    2) Fail with -EAGAIN if we find an ordered extent;
    
    3) Return -EAGAIN instead of -ENOTBLK when we need to fallback to
       buffered IO and we have a NOWAIT request.
    
    This will also allow us to avoid a duplicated check that verifies if we
    are able to do a NOCOW write for NOWAIT direct IO writes, done in the
    next patch.
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    59094403
inode.c 322 KB