zfs + sendfile: do not produce partially valid pages for vnode's tail

Since r212650 and before this change sendfile(2) could produce
a partially valid page for a trailing portion of a ZFS vnode.
vm_fault() always wants to see a fully valid page even if it's the last
page that partially extends beyond vnode's end.  Otherwise it calls
vop_getpages() to bring in the page.  In the case of ZFS this means
that the data is read from the page into the same page and this breaks
checks in ZFS mappedread() - a thread that set VPO_BUSY on the page in
vm_fault() will get blocked forever waiting for it to be cleared.

Many thanks to Kai and Jeremy for reproducing the issue and providing
important debugging information and help.

Reported by:	Kai Gallasch <gallasch@free.de>,
		Jeremy Chadwick <freebsd@jdc.parodius.com>
Tested by:	Kai Gallasch <gallasch@free.de>,
		Jeremy Chadwick <freebsd@jdc.parodius.com>
Reviewed by:	kib
MFC after:	3 days
To-Do:		apply the same treatment to tmpfs + sendfile
This commit is contained in:
avg 2010-10-12 17:04:21 +00:00
parent 465ea6bc32
commit 3bb689aafa

View File

@ -489,6 +489,8 @@ again:
* but it pessimize performance of sendfile/UFS, that's
* why I handle this special case in ZFS code.
*/
KASSERT(off == 0,
("unexpected offset in mappedread for sendfile"));
if ((m->oflags & VPO_BUSY) != 0) {
/*
* Reference the page before unlocking and
@ -509,14 +511,15 @@ again:
}
if (error == 0) {
va = zfs_map_page(m, &sf);
error = dmu_read(os, zp->z_id, start + off,
bytes, (void *)(va + off),
error = dmu_read(os, zp->z_id, start, bytes, va,
DMU_READ_PREFETCH);
if (bytes != PAGE_SIZE)
bzero(va + bytes, PAGE_SIZE - bytes);
zfs_unmap_page(sf);
}
VM_OBJECT_LOCK(obj);
if (error == 0)
vm_page_set_valid(m, off, bytes);
m->valid = VM_PAGE_BITS_ALL;
vm_page_wakeup(m);
if (error == 0) {
uio->uio_resid -= bytes;