Skip to content

Commit 7a9d43e

Browse files
Christoph Hellwigbrauner
authored andcommitted
iomap: handle a post-direct I/O invalidate race in iomap_write_delalloc_release
When direct I/O completions invalidates the page cache it holds neither the i_rwsem nor the invalidate_lock so it can be racing with iomap_write_delalloc_release. If the search for the end of the region that contains data returns the start offset we hit such a race and just need to look for the end of the newly created hole instead. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent b1daf3f commit 7a9d43e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/iomap/buffered-io.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,15 @@ static int iomap_write_delalloc_release(struct inode *inode,
12421242
error = data_end;
12431243
goto out_unlock;
12441244
}
1245-
WARN_ON_ONCE(data_end <= start_byte);
1245+
1246+
/*
1247+
* If we race with post-direct I/O invalidation of the page cache,
1248+
* there might be no data left at start_byte.
1249+
*/
1250+
if (data_end == start_byte)
1251+
continue;
1252+
1253+
WARN_ON_ONCE(data_end < start_byte);
12461254
WARN_ON_ONCE(data_end > scan_end_byte);
12471255

12481256
error = iomap_write_delalloc_scan(inode, &punch_start_byte,

0 commit comments

Comments
 (0)