Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Jul 2019 18:03:30 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r350144 - in projects/fuse2: sys/kern tests/sys/fs/fusefs
Message-ID:  <201907191803.x6JI3UZc059042@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Fri Jul 19 18:03:30 2019
New Revision: 350144
URL: https://svnweb.freebsd.org/changeset/base/350144

Log:
  sendfile: don't panic when VOP_GETPAGES_ASYNC returns an error
  
  PR:		236466
  Sponsored by:	The FreeBSD Foundation

Modified:
  projects/fuse2/sys/kern/kern_sendfile.c
  projects/fuse2/tests/sys/fs/fusefs/read.cc

Modified: projects/fuse2/sys/kern/kern_sendfile.c
==============================================================================
--- projects/fuse2/sys/kern/kern_sendfile.c	Fri Jul 19 17:52:23 2019	(r350143)
+++ projects/fuse2/sys/kern/kern_sendfile.c	Fri Jul 19 18:03:30 2019	(r350144)
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/mbuf.h>
 #include <sys/protosw.h>
 #include <sys/rwlock.h>
+#include <sys/sdt.h>
 #include <sys/sf_buf.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
@@ -63,6 +64,8 @@ __FBSDID("$FreeBSD$");
 #define	EXT_FLAG_SYNC		EXT_FLAG_VENDOR1
 #define	EXT_FLAG_NOCACHE	EXT_FLAG_VENDOR2
 
+SDT_PROVIDER_DECLARE(vfs);
+
 /*
  * Structure describing a single sendfile(2) I/O, which may consist of
  * several underlying pager I/Os.
@@ -312,17 +315,18 @@ sendfile_iodone(void *arg, vm_page_t *pg, int count, i
 	free(sfio, M_TEMP);
 }
 
+SDT_PROBE_DEFINE1(vfs, sendfile, swapin, pager_error, "int");
 /*
  * Iterate through pages vector and request paging for non-valid pages.
  */
 static int
-sendfile_swapin(vm_object_t obj, struct sf_io *sfio, off_t off, off_t len,
-    int npages, int rhpages, int flags)
+sendfile_swapin(vm_object_t obj, struct sf_io *sfio, int *nios, off_t off,
+    off_t len, int npages, int rhpages, int flags)
 {
 	vm_page_t *pa = sfio->pa;
-	int grabbed, nios;
+	int grabbed;
 
-	nios = 0;
+	*nios = 0;
 	flags = (flags & SF_NODISKIO) ? VM_ALLOC_NOWAIT : 0;
 
 	/*
@@ -341,7 +345,7 @@ sendfile_swapin(vm_object_t obj, struct sf_io *sfio, o
 	}
 
 	for (int i = 0; i < npages;) {
-		int j, a, count, rv __unused;
+		int j, a, count, rv;
 
 		/* Skip valid pages. */
 		if (vm_page_is_valid(pa[i], vmoff(i, off) & PAGE_MASK,
@@ -404,6 +408,16 @@ sendfile_swapin(vm_object_t obj, struct sf_io *sfio, o
 		rv = vm_pager_get_pages_async(obj, pa + i, count, NULL,
 		    i + count == npages ? &rhpages : NULL,
 		    &sendfile_iodone, sfio);
+		if (rv != VM_PAGER_OK) {
+			SDT_PROBE1(vfs, sendfile, swapin, pager_error, rv);
+			for (j = 0; j < count; j++) {
+				vm_page_lock(*(pa + i + j));
+				vm_page_unwire(*(pa + i + j), PQ_INACTIVE);
+				vm_page_unlock(*(pa + i + j));
+			}
+			VM_OBJECT_WUNLOCK(obj);
+			return EIO;
+		}
 		KASSERT(rv == VM_PAGER_OK, ("%s: pager fail obj %p page %p",
 		    __func__, obj, pa[i]));
 
@@ -425,15 +439,15 @@ sendfile_swapin(vm_object_t obj, struct sf_io *sfio, o
 
 			}
 		i += count;
-		nios++;
+		(*nios)++;
 	}
 
 	VM_OBJECT_WUNLOCK(obj);
 
-	if (nios == 0 && npages != 0)
+	if (*nios == 0 && npages != 0)
 		SFSTAT_INC(sf_noiocnt);
 
-	return (nios);
+	return (0);
 }
 
 static int
@@ -743,8 +757,14 @@ retry_space:
 		sfio->so = so;
 		sfio->error = 0;
 
-		nios = sendfile_swapin(obj, sfio, off, space, npages, rhpages,
-		    flags);
+		error = sendfile_swapin(obj, sfio, &nios, off, space, npages,
+		    rhpages, flags);
+		if (error) {
+			free(sfio, M_TEMP);
+			if (vp != NULL)
+				VOP_UNLOCK(vp, 0);
+			goto done;
+		}
 
 		/*
 		 * Loop and construct maximum sized mbuf chain to be bulk

Modified: projects/fuse2/tests/sys/fs/fusefs/read.cc
==============================================================================
--- projects/fuse2/tests/sys/fs/fusefs/read.cc	Fri Jul 19 17:52:23 2019	(r350143)
+++ projects/fuse2/tests/sys/fs/fusefs/read.cc	Fri Jul 19 18:03:30 2019	(r350144)
@@ -832,7 +832,7 @@ TEST_F(Read, sendfile)
 
 /* sendfile should fail gracefully if fuse declines the read */
 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236466 */
-TEST_F(Read, DISABLED_sendfile_eio)
+TEST_F(Read, sendfile_eio)
 {
 	const char FULLPATH[] = "mountpoint/some_file.txt";
 	const char RELPATH[] = "some_file.txt";



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201907191803.x6JI3UZc059042>