Skip to content

Commit f5ceb1b

Browse files
riteshharjanibrauner
authored andcommitted
iomap: Fix iomap_adjust_read_range for plen calculation
If the extent spans the block that contains i_size, we need to handle both halves separately so that we properly zero data in the page cache for blocks that are entirely outside of i_size. But this is needed only when i_size is within the current folio under processing. "orig_pos + length > isize" can be true for all folios if the mapped extent length is greater than the folio size. That is making plen to break for every folio instead of only the last folio. So use orig_plen for checking if "orig_pos + orig_plen > isize". Signed-off-by: Ritesh Harjani (IBM) <[email protected]> Link: https://lore.kernel.org/r/a32e5f9a4fcfdb99077300c4020ed7ae61d6e0f9.1715067055.git.ritesh.list@gmail.com Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Jan Kara <[email protected]> cc: Ojaswin Mujoo <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 0841ea4 commit f5ceb1b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/iomap/buffered-io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
241241
unsigned block_size = (1 << block_bits);
242242
size_t poff = offset_in_folio(folio, *pos);
243243
size_t plen = min_t(loff_t, folio_size(folio) - poff, length);
244+
size_t orig_plen = plen;
244245
unsigned first = poff >> block_bits;
245246
unsigned last = (poff + plen - 1) >> block_bits;
246247

@@ -277,7 +278,7 @@ static void iomap_adjust_read_range(struct inode *inode, struct folio *folio,
277278
* handle both halves separately so that we properly zero data in the
278279
* page cache for blocks that are entirely outside of i_size.
279280
*/
280-
if (orig_pos <= isize && orig_pos + length > isize) {
281+
if (orig_pos <= isize && orig_pos + orig_plen > isize) {
281282
unsigned end = offset_in_folio(folio, isize - 1) >> block_bits;
282283

283284
if (first <= end && last > end)

0 commit comments

Comments
 (0)