]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
xfs: fix eofblocks race with file extending async dio writes
authorBrian Foster <bfoster@redhat.com>
Sat, 28 Jan 2017 07:22:57 +0000 (23:22 -0800)
committerShan Hai <shan.hai@oracle.com>
Tue, 15 Aug 2017 07:02:37 +0000 (15:02 +0800)
It's possible for post-eof blocks to end up being used for direct I/O
writes. dio write performs an upfront unwritten extent allocation, sends
the dio and then updates the inode size (if necessary) on write
completion. If a file release occurs while a file extending dio write is
in flight, it is possible to mistake the post-eof blocks for speculative
preallocation and incorrectly truncate them from the inode. This means
that the resulting dio write completion can discover a hole and allocate
new blocks rather than perform unwritten extent conversion.

This requires a strange mix of I/O and is thus not likely to reproduce
in real world workloads. It is intermittently reproduced by generic/299.
The error manifests as an assert failure due to transaction overrun
because the aforementioned write completion transaction has only
reserved enough blocks for btree operations:

  XFS: Assertion failed: tp->t_blk_res_used <= tp->t_blk_res, \
   file: fs/xfs//xfs_trans.c, line: 309

The root cause is that xfs_free_eofblocks() uses i_size to truncate
post-eof blocks from the inode, but async, file extending direct writes
do not update i_size until write completion, long after inode locks are
dropped. Therefore, xfs_free_eofblocks() effectively truncates the inode
to the incorrect size.

Update xfs_free_eofblocks() to serialize against dio similar to how
extending writes are serialized against i_size updates before post-eof
block zeroing. Specifically, wait on dio while under the iolock. This
ensures that dio write completions have updated i_size before post-eof
blocks are processed.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Orabug: 26588811

(backport upstream commit e4229d6b0bc9280f29624faf170cf76a9f1ca60e)

Signed-off-by: Shan Hai <shan.hai@oracle.com>
Reviewed-by: Jack Vogel <jack.vogel@oracle.com>
fs/xfs/xfs_bmap_util.c

index bc59bd348f6d3daa40cef227e8e7d5d4907b98cd..b8e756023b2945f2df5fca34a6415cae6a49dd06 100644 (file)
@@ -888,6 +888,9 @@ xfs_free_eofblocks(
                if (error)
                        return error;
 
+               /* wait on dio to ensure i_size has settled */
+               inode_dio_wait(VFS_I(ip));
+
                /*
                 * There are blocks after the end of file.
                 * Free them up now by truncating the file to