xfs: update i_size after unwritten conversion in dio completion
Since commit d531d91d69
("xfs: always use unwritten extents for
direct I/O writes"), we start allocating unwritten extents for all
direct writes to allow appending aio in XFS.
But for dio writes that could extend file size we update the in-core
inode size first, then convert the unwritten extents to real
allocations at dio completion time in xfs_dio_write_end_io(). Thus a
racing direct read could see the new i_size and find the unwritten
extents first and read zeros instead of actual data, if the direct
writer also takes a shared iolock.
Fix it by updating the in-core inode size after the unwritten extent
conversion. To do this, introduce a new boolean argument to
xfs_iomap_write_unwritten() to tell if we want to update in-core
i_size or not.
Suggested-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:

committed by
Darrick J. Wong

parent
546e7be824
commit
ee70daaba8
@@ -829,7 +829,8 @@ int
|
||||
xfs_iomap_write_unwritten(
|
||||
xfs_inode_t *ip,
|
||||
xfs_off_t offset,
|
||||
xfs_off_t count)
|
||||
xfs_off_t count,
|
||||
bool update_isize)
|
||||
{
|
||||
xfs_mount_t *mp = ip->i_mount;
|
||||
xfs_fileoff_t offset_fsb;
|
||||
@@ -840,6 +841,7 @@ xfs_iomap_write_unwritten(
|
||||
xfs_trans_t *tp;
|
||||
xfs_bmbt_irec_t imap;
|
||||
struct xfs_defer_ops dfops;
|
||||
struct inode *inode = VFS_I(ip);
|
||||
xfs_fsize_t i_size;
|
||||
uint resblks;
|
||||
int error;
|
||||
@@ -899,7 +901,8 @@ xfs_iomap_write_unwritten(
|
||||
i_size = XFS_FSB_TO_B(mp, offset_fsb + count_fsb);
|
||||
if (i_size > offset + count)
|
||||
i_size = offset + count;
|
||||
|
||||
if (update_isize && i_size > i_size_read(inode))
|
||||
i_size_write(inode, i_size);
|
||||
i_size = xfs_new_eof(ip, i_size);
|
||||
if (i_size) {
|
||||
ip->i_d.di_size = i_size;
|
||||
|
Reference in New Issue
Block a user