iomap: Fix inline extent handling in iomap_readpage
authorAndreas Gruenbacher <agruenba@redhat.com>
Thu, 18 Nov 2021 01:59:01 +0000 (17:59 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 22 Nov 2021 00:28:07 +0000 (16:28 -0800)
commitd8af404ffce71448f29bbc19a05e3d095baf98eb
treed6316acd671f32fe257ce499e5fd9bdb717956cd
parent136057256686de39cc3a07c2e39ef6bc43003ff6
iomap: Fix inline extent handling in iomap_readpage

Before commit 740499c78408 ("iomap: fix the iomap_readpage_actor return
value for inline data"), when hitting an IOMAP_INLINE extent,
iomap_readpage_actor would report having read the entire page.  Since
then, it only reports having read the inline data (iomap->length).

This will force iomap_readpage into another iteration, and the
filesystem will report an unaligned hole after the IOMAP_INLINE extent.
But iomap_readpage_actor (now iomap_readpage_iter) isn't prepared to
deal with unaligned extents, it will get things wrong on filesystems
with a block size smaller than the page size, and we'll eventually run
into the following warning in iomap_iter_advance:

  WARN_ON_ONCE(iter->processed > iomap_length(iter));

Fix that by changing iomap_readpage_iter to return 0 when hitting an
inline extent; this will cause iomap_iter to stop immediately.

To fix readahead as well, change iomap_readahead_iter to pass on
iomap_readpage_iter return values less than or equal to zero.

Fixes: 740499c78408 ("iomap: fix the iomap_readpage_actor return value for inline data")
Cc: stable@vger.kernel.org # v5.15+
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/iomap/buffered-io.c