• Darrick J. Wong's avatar
    xfs: take the ILOCK when readdir inspects directory mapping data · 65552b02
    Darrick J. Wong authored
    I was poking around in the directory code while diagnosing online fsck
    bugs, and noticed that xfs_readdir doesn't actually take the directory
    ILOCK when it calls xfs_dir2_isblock.  xfs_dir_open most probably loaded
    the data fork mappings and the VFS took i_rwsem (aka IOLOCK_SHARED) so
    we're protected against writer threads, but we really need to follow the
    locking model like we do in other places.
    
    To avoid unnecessarily cycling the ILOCK for fairly small directories,
    change the block/leaf _getdents functions to consume the ILOCK hold that
    the parent readdir function took to decide on a _getdents implementation.
    
    It is ok to cycle the ILOCK in readdir because the VFS takes the IOLOCK
    in the appropriate mode during lookups and writes, and we don't want to
    be holding the ILOCK when we copy directory entries to userspace in case
    there's a page fault.  We really only need it to protect against data
    fork lookups, like we do for other files.
    Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
    65552b02
xfs_dir2_readdir.c 13.7 KB