xfs: fix reflink source file racing with directio writes
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 15 Aug 2019 00:38:09 +0000 (17:38 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Mon, 19 Aug 2019 01:53:25 +0000 (18:53 -0700)
commit5d888b481e6abc726b36c86f0bf13af1583bb336
tree902c57ac0fe14c9693ab36bd943de335eb23fc6d
parentedc58dd0123b552453a74369bd0c8d890b497b4b
xfs: fix reflink source file racing with directio writes

While trawling through the dedupe file comparison code trying to fix
page deadlocking problems, Dave Chinner noticed that the reflink code
only takes shared IOLOCK/MMAPLOCKs on the source file.  Because
page_mkwrite and directio writes do not take the EXCL versions of those
locks, this means that reflink can race with writer processes.

For pure remapping this can lead to undefined behavior and file
corruption; for dedupe this means that we cannot be sure that the
contents are identical when we decide to go ahead with the remapping.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_reflink.c