]> git.baikalelectronics.ru Git - kernel.git/commit
xfs: take the ILOCK when readdir inspects directory mapping data
authorDarrick J. Wong <djwong@kernel.org>
Wed, 5 Jan 2022 01:38:36 +0000 (17:38 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 11 Jan 2022 23:11:04 +0000 (15:11 -0800)
commitfa8666335e1292f3931847dbe980aecec7c75f18
treefc7b6d9dc15c866923c23d224e79afcf75ed5a53
parentbd85337bdb31aa289c6ac55281879335aa893c35
xfs: take the ILOCK when readdir inspects directory mapping data

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: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
fs/xfs/xfs_dir2_readdir.c