svn commit: r213730 - head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs

Andriy Gapon avg at FreeBSD.org
Tue Oct 12 17:04:22 UTC 2010


Author: avg
Date: Tue Oct 12 17:04:21 2010
New Revision: 213730
URL: http://svn.freebsd.org/changeset/base/213730

Log:
  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 at free.de>,
  		Jeremy Chadwick <freebsd at jdc.parodius.com>
  Tested by:	Kai Gallasch <gallasch at free.de>,
  		Jeremy Chadwick <freebsd at jdc.parodius.com>
  Reviewed by:	kib
  MFC after:	3 days
  To-Do:		apply the same treatment to tmpfs + sendfile

Modified:
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Tue Oct 12 16:52:13 2010	(r213729)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c	Tue Oct 12 17:04:21 2010	(r213730)
@@ -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;


More information about the svn-src-all mailing list