Skip to content

Commit aa6ee4a

Browse files
Brian Fosterdjwong
authored andcommitted
xfs: eof trim writeback mapping as soon as it is cached
The cached writeback mapping is EOF trimmed to try and avoid races between post-eof block management and writeback that result in sending cached data to a stale location. The cached mapping is currently trimmed on the validation check, which leaves a race window between the time the mapping is cached and when it is trimmed against the current inode size. For example, if a new mapping is cached by delalloc conversion on a blocksize == page size fs, we could cycle various locks, perform memory allocations, etc. in the writeback codepath before the associated mapping is eventually trimmed to i_size. This leaves enough time for a post-eof truncate and file append before the cached mapping is trimmed. The former event essentially invalidates a range of the cached mapping and the latter bumps the inode size such the trim on the next writepage event won't trim all of the invalid blocks. fstest generic/464 reproduces this scenario occasionally and causes a lost writeback and stale delalloc blocks warning on inode inactivation. To work around this problem, trim the cached writeback mapping as soon as it is cached in addition to on subsequent validation checks. This is a minor tweak to tighten the race window as much as possible until a proper invalidation mechanism is available. Fixes: 40214d1 ("xfs: trim writepage mapping to within eof") Cc: <stable@vger.kernel.org> # v4.14+ Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Allison Henderson <allison.henderson@oracle.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>
1 parent 8834f56 commit aa6ee4a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/xfs/xfs_aops.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ xfs_map_blocks(
449449
}
450450

451451
wpc->imap = imap;
452+
xfs_trim_extent_eof(&wpc->imap, ip);
452453
trace_xfs_map_blocks_found(ip, offset, count, wpc->io_type, &imap);
453454
return 0;
454455
allocate_blocks:
@@ -459,6 +460,7 @@ xfs_map_blocks(
459460
ASSERT(whichfork == XFS_COW_FORK || cow_fsb == NULLFILEOFF ||
460461
imap.br_startoff + imap.br_blockcount <= cow_fsb);
461462
wpc->imap = imap;
463+
xfs_trim_extent_eof(&wpc->imap, ip);
462464
trace_xfs_map_blocks_alloc(ip, offset, count, wpc->io_type, &imap);
463465
return 0;
464466
}

0 commit comments

Comments
 (0)