]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
sendfile: Use the pager size to determine the file extent when possible
authorMark Johnston <markj@FreeBSD.org>
Thu, 25 Feb 2021 15:04:44 +0000 (10:04 -0500)
committerMark Johnston <markj@FreeBSD.org>
Thu, 4 Mar 2021 13:19:51 +0000 (08:19 -0500)
commit095558ac894977906fbbdf74c34b6d13fea7c8ed
treea5ee353c80baa78d8f75c939d283bdf427e70bb8
parentae608d4ee7202cc34603e620bc551547e772c4d2
sendfile: Use the pager size to determine the file extent when possible

Previously sendfile would issue a VOP_GETATTR and use the returned size,
i.e., the file size.  When paging in file data, sendfile_swapin() will
use the pager to determine whether it needs to zero-fill, most often
because of a hole in a sparse file.  An attempt to page in beyond the
end of a file is treated this way, and occurs when the requested page is
past the end of the pager.  In other words, both the file size and pager
size were used interchangeably.

With ZFS, updates to the pager and file sizes are not synchronized by
the exclusive vnode lock, at least partially due to its use of
MNTK_SHARED_WRITES.  In particular, the pager size is updated after the
file size, so in the presence of a writer concurrently extending the
file, sendfile could incorrectly instantiate "holes" in the page cache
pages backing the file, which manifests as data corruption when reading
the file back from the page cache.  The on-disk copy is unaffected.

Fix this by consistently using the pager size when available.

Reported by: dumbbell
Reviewed by: chs, kib
Tested by: dumbbell, pho
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D28811

(cherry picked from commit faa998f6ff69573fe82765c77c7268ee89ac945e)
sys/kern/kern_sendfile.c