]> 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 14:09:36 +0000 (09:09 -0500)
commit065b9549d35676dcd7af45ca3ebd05e9ca082cbe
tree02a443fb11d0e3dee1d5271f09b1d0757352f7ba
parentb8ffda0a37e126623069bce49e8096dbdb4bfde3
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.

Approved by: re (gjb)
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)
(cherry picked from commit 095558ac894977906fbbdf74c34b6d13fea7c8ed)
sys/kern/kern_sendfile.c