diff --git a/sys/kern/kern_sendfile.c b/sys/kern/kern_sendfile.c index 61edffa893e..6e7259b0bc9 100644 --- a/sys/kern/kern_sendfile.c +++ b/sys/kern/kern_sendfile.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -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, int error) 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, off_t off, off_t len, } 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, off_t off, off_t len, 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, off_t off, off_t len, } 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 diff --git a/tests/sys/fs/fusefs/read.cc b/tests/sys/fs/fusefs/read.cc index cd82c0656eb..ff1d6d41c31 100644 --- a/tests/sys/fs/fusefs/read.cc +++ b/tests/sys/fs/fusefs/read.cc @@ -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";