[Midnightbsd-cvs] src [10022] trunk/sys/fs/pseudofs: sync pseudofs with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun May 27 18:09:14 EDT 2018


Revision: 10022
          http://svnweb.midnightbsd.org/src/?rev=10022
Author:   laffer1
Date:     2018-05-27 18:09:13 -0400 (Sun, 27 May 2018)
Log Message:
-----------
sync pseudofs with freebsd

Modified Paths:
--------------
    trunk/sys/fs/pseudofs/pseudofs.c
    trunk/sys/fs/pseudofs/pseudofs.h
    trunk/sys/fs/pseudofs/pseudofs_fileno.c
    trunk/sys/fs/pseudofs/pseudofs_internal.h
    trunk/sys/fs/pseudofs/pseudofs_vncache.c
    trunk/sys/fs/pseudofs/pseudofs_vnops.c

Modified: trunk/sys/fs/pseudofs/pseudofs.c
===================================================================
--- trunk/sys/fs/pseudofs/pseudofs.c	2018-05-27 22:08:55 UTC (rev 10021)
+++ trunk/sys/fs/pseudofs/pseudofs.c	2018-05-27 22:09:13 UTC (rev 10022)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2001 Dag-Erling Co\xEFdan Sm\xF8rgrav
+ * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/fs/pseudofs/pseudofs.c 303907 2016-08-10 12:36:54Z kib $");
 
 #include "opt_pseudofs.h"
 
@@ -52,9 +53,11 @@
 SYSCTL_NODE(_vfs, OID_AUTO, pfs, CTLFLAG_RW, 0,
     "pseudofs");
 
+#ifdef PSEUDOFS_TRACE
 int pfs_trace;
 SYSCTL_INT(_vfs_pfs, OID_AUTO, trace, CTLFLAG_RW, &pfs_trace, 0,
     "enable tracing of pseudofs vnode operations");
+#endif
 
 #if PFS_FSNAMELEN != MFSNAMELEN
 #error "PFS_FSNAMELEN is not equal to MFSNAMELEN"
@@ -308,7 +311,6 @@
 
 	MNT_ILOCK(mp);
 	mp->mnt_flag |= MNT_LOCAL;
-	mp->mnt_kern_flag |= MNTK_MPSAFE;
 	MNT_IUNLOCK(mp);
 	mp->mnt_data = pi;
 	vfs_getnewfsid(mp);
@@ -382,11 +384,9 @@
 	struct pfs_node *root;
 	int error;
 
-	mtx_assert(&Giant, MA_OWNED);
-
 	pfs_fileno_init(pi);
 
-	/* set up the root diretory */
+	/* set up the root directory */
 	root = pfs_alloc_node(pi, "/", pfstype_root);
 	pi->pi_root = root;
 	pfs_fileno_alloc(root);
@@ -413,8 +413,6 @@
 {
 	int error;
 
-	mtx_assert(&Giant, MA_OWNED);
-
 	pfs_destroy(pi->pi_root);
 	pi->pi_root = NULL;
 	pfs_fileno_uninit(pi);

Modified: trunk/sys/fs/pseudofs/pseudofs.h
===================================================================
--- trunk/sys/fs/pseudofs/pseudofs.h	2018-05-27 22:08:55 UTC (rev 10021)
+++ trunk/sys/fs/pseudofs/pseudofs.h	2018-05-27 22:09:13 UTC (rev 10022)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2001 Dag-Erling Co\xEFdan Sm\xF8rgrav
+ * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,7 +26,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- *      $MidnightBSD$
+ *      $FreeBSD: stable/10/sys/fs/pseudofs/pseudofs.h 303907 2016-08-10 12:36:54Z kib $
  */
 
 #ifndef _PSEUDOFS_H_INCLUDED
@@ -189,9 +190,9 @@
 /*
  * pfs_info: describes a pseudofs instance
  *
- * The pi_mutex is only used to avoid using the global subr_unit lock for
- * unrhdr.  The rest of struct pfs_info is only modified while Giant is
- * held (during vfs_init() and vfs_uninit()).
+ * The pi_mutex is only used to avoid using the global subr_unit lock
+ * for unrhdr.  The rest of struct pfs_info is only modified during
+ * vfs_init() and vfs_uninit() of the consumer filesystem.
  */
 struct pfs_info {
 	char			 pi_name[PFS_FSNAMELEN];
@@ -198,7 +199,7 @@
 	pfs_init_t		 pi_init;
 	pfs_init_t		 pi_uninit;
 
-	/* members below this line are initialized at run time*/
+	/* members below this line are initialized at run time */
 	struct pfs_node		*pi_root;
 	struct mtx		 pi_mutex;
 	struct unrhdr		*pi_unrhdr;
@@ -285,17 +286,17 @@
 _##name##_mount(struct mount *mp) {					\
         if (jflag && !prison_allow(curthread->td_ucred, jflag))		\
                 return (EPERM);						\
-	return pfs_mount(&name##_info, mp);				\
+	return (pfs_mount(&name##_info, mp));				\
 }									\
 									\
 static int								\
 _##name##_init(struct vfsconf *vfc) {					\
-	return pfs_init(&name##_info, vfc);				\
+	return (pfs_init(&name##_info, vfc));				\
 }									\
 									\
 static int								\
 _##name##_uninit(struct vfsconf *vfc) {					\
-	return pfs_uninit(&name##_info, vfc);				\
+	return (pfs_uninit(&name##_info, vfc));				\
 }									\
 									\
 static struct vfsops name##_vfsops = {					\

Modified: trunk/sys/fs/pseudofs/pseudofs_fileno.c
===================================================================
--- trunk/sys/fs/pseudofs/pseudofs_fileno.c	2018-05-27 22:08:55 UTC (rev 10021)
+++ trunk/sys/fs/pseudofs/pseudofs_fileno.c	2018-05-27 22:09:13 UTC (rev 10022)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2001 Dag-Erling Co\xEFdan Sm\xF8rgrav
+ * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/fs/pseudofs/pseudofs_fileno.c 303907 2016-08-10 12:36:54Z kib $");
 
 #include "opt_pseudofs.h"
 
@@ -52,7 +53,6 @@
 pfs_fileno_init(struct pfs_info *pi)
 {
 
-	mtx_assert(&Giant, MA_OWNED);
 	mtx_init(&pi->pi_mutex, "pfs_fileno", NULL, MTX_DEF);
 	pi->pi_unrhdr = new_unrhdr(3, INT_MAX / NO_PID, &pi->pi_mutex);
 }
@@ -64,7 +64,6 @@
 pfs_fileno_uninit(struct pfs_info *pi)
 {
 
-	mtx_assert(&Giant, MA_OWNED);
 	delete_unrhdr(pi->pi_unrhdr);
 	pi->pi_unrhdr = NULL;
 	mtx_destroy(&pi->pi_mutex);

Modified: trunk/sys/fs/pseudofs/pseudofs_internal.h
===================================================================
--- trunk/sys/fs/pseudofs/pseudofs_internal.h	2018-05-27 22:08:55 UTC (rev 10021)
+++ trunk/sys/fs/pseudofs/pseudofs_internal.h	2018-05-27 22:09:13 UTC (rev 10022)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2001 Dag-Erling Co\xEFdan Sm\xF8rgrav
+ * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,7 +26,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- *      $MidnightBSD$
+ *      $FreeBSD: stable/10/sys/fs/pseudofs/pseudofs_internal.h 230132 2012-01-15 13:23:18Z uqs $
  */
 
 #ifndef _PSEUDOFS_INTERNAL_H_INCLUDED

Modified: trunk/sys/fs/pseudofs/pseudofs_vncache.c
===================================================================
--- trunk/sys/fs/pseudofs/pseudofs_vncache.c	2018-05-27 22:08:55 UTC (rev 10021)
+++ trunk/sys/fs/pseudofs/pseudofs_vncache.c	2018-05-27 22:09:13 UTC (rev 10022)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2001 Dag-Erling Co\xEFdan Sm\xF8rgrav
+ * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/fs/pseudofs/pseudofs_vncache.c 312286 2017-01-16 12:17:35Z kib $");
 
 #include "opt_pseudofs.h"
 
@@ -51,6 +52,7 @@
 static struct pfs_vdata *pfs_vncache;
 static eventhandler_tag pfs_exit_tag;
 static void pfs_exit(void *arg, struct proc *p);
+static void pfs_purge_locked(struct pfs_node *pn, bool force);
 
 static SYSCTL_NODE(_vfs_pfs, OID_AUTO, vncache, CTLFLAG_RW, 0,
     "pseudofs vnode cache");
@@ -84,7 +86,6 @@
 pfs_vncache_load(void)
 {
 
-	mtx_assert(&Giant, MA_OWNED);
 	mtx_init(&pfs_vncache_mutex, "pfs_vncache", NULL, MTX_DEF);
 	pfs_exit_tag = EVENTHANDLER_REGISTER(process_exit, pfs_exit, NULL,
 	    EVENTHANDLER_PRI_ANY);
@@ -97,8 +98,10 @@
 pfs_vncache_unload(void)
 {
 
-	mtx_assert(&Giant, MA_OWNED);
 	EVENTHANDLER_DEREGISTER(process_exit, pfs_exit_tag);
+	mtx_lock(&pfs_vncache_mutex);
+	pfs_purge_locked(NULL, true);
+	mtx_unlock(&pfs_vncache_mutex);
 	KASSERT(pfs_vncache_entries == 0,
 	    ("%d vncache entries remaining", pfs_vncache_entries));
 	mtx_destroy(&pfs_vncache_mutex);
@@ -274,7 +277,7 @@
  * used to implement the cache.
  */
 static void
-pfs_purge_locked(struct pfs_node *pn)
+pfs_purge_locked(struct pfs_node *pn, bool force)
 {
 	struct pfs_vdata *pvd;
 	struct vnode *vnp;
@@ -282,7 +285,8 @@
 	mtx_assert(&pfs_vncache_mutex, MA_OWNED);
 	pvd = pfs_vncache;
 	while (pvd != NULL) {
-		if (pvd->pvd_dead || (pn != NULL && pvd->pvd_pn == pn)) {
+		if (force || pvd->pvd_dead ||
+		    (pn != NULL && pvd->pvd_pn == pn)) {
 			vnp = pvd->pvd_vnode;
 			vhold(vnp);
 			mtx_unlock(&pfs_vncache_mutex);
@@ -303,7 +307,7 @@
 {
 
 	mtx_lock(&pfs_vncache_mutex);
-	pfs_purge_locked(pn);
+	pfs_purge_locked(pn, false);
 	mtx_unlock(&pfs_vncache_mutex);
 }
 
@@ -323,6 +327,6 @@
 		if (pvd->pvd_pid == p->p_pid)
 			dead = pvd->pvd_dead = 1;
 	if (dead)
-		pfs_purge_locked(NULL);
+		pfs_purge_locked(NULL, false);
 	mtx_unlock(&pfs_vncache_mutex);
 }

Modified: trunk/sys/fs/pseudofs/pseudofs_vnops.c
===================================================================
--- trunk/sys/fs/pseudofs/pseudofs_vnops.c	2018-05-27 22:08:55 UTC (rev 10021)
+++ trunk/sys/fs/pseudofs/pseudofs_vnops.c	2018-05-27 22:09:13 UTC (rev 10022)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2001 Dag-Erling Co\xEFdan Sm\xF8rgrav
+ * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/fs/pseudofs/pseudofs_vnops.c 297267 2016-03-25 08:26:37Z kib $");
 
 #include "opt_pseudofs.h"
 
@@ -104,7 +105,8 @@
 }
 
 static int
-pfs_visible(struct thread *td, struct pfs_node *pn, pid_t pid, struct proc **p)
+pfs_visible(struct thread *td, struct pfs_node *pn, pid_t pid,
+    bool allproc_locked, struct proc **p)
 {
 	struct proc *proc;
 
@@ -115,7 +117,8 @@
 		*p = NULL;
 	if (pid == NO_PID)
 		PFS_RETURN (1);
-	if ((proc = pfind(pid)) == NULL)
+	proc = allproc_locked ? pfind_locked(pid) : pfind(pid);
+	if (proc == NULL)
 		PFS_RETURN (0);
 	if (pfs_visible_proc(td, pn, proc)) {
 		if (p)
@@ -202,7 +205,7 @@
 	PFS_TRACE(("%s", pn->pn_name));
 	pfs_assert_not_owned(pn);
 
-	if (!pfs_visible(curthread, pn, pvd->pvd_pid, &proc))
+	if (!pfs_visible(curthread, pn, pvd->pvd_pid, false, &proc))
 		PFS_RETURN (ENOENT);
 
 	vap->va_type = vn->v_type;
@@ -293,7 +296,7 @@
 	 * This is necessary because process' privileges may
 	 * have changed since the open() call.
 	 */
-	if (!pfs_visible(curthread, pn, pvd->pvd_pid, &proc)) {
+	if (!pfs_visible(curthread, pn, pvd->pvd_pid, false, &proc)) {
 		VOP_UNLOCK(vn, 0);
 		PFS_RETURN (EIO);
 	}
@@ -326,7 +329,7 @@
 	 * This is necessary because either process' privileges may
 	 * have changed since the open() call.
 	 */
-	if (!pfs_visible(curthread, pn, pvd->pvd_pid, &proc))
+	if (!pfs_visible(curthread, pn, pvd->pvd_pid, false, &proc))
 		PFS_RETURN (EIO);
 
 	if (pn->pn_getextattr == NULL)
@@ -462,7 +465,7 @@
 		PFS_RETURN (ENOENT);
 
 	/* check that parent directory is visible... */
-	if (!pfs_visible(curthread, pd, pvd->pvd_pid, NULL))
+	if (!pfs_visible(curthread, pd, pvd->pvd_pid, false, NULL))
 		PFS_RETURN (ENOENT);
 
 	/* self */
@@ -546,7 +549,7 @@
  got_pnode:
 	pfs_assert_not_owned(pd);
 	pfs_assert_not_owned(pn);
-	visible = pfs_visible(curthread, pn, pid, NULL);
+	visible = pfs_visible(curthread, pn, pid, false, NULL);
 	if (!visible) {
 		error = ENOENT;
 		goto failed;
@@ -616,8 +619,7 @@
 	struct proc *proc;
 	struct sbuf *sb = NULL;
 	int error, locked;
-	off_t offset;
-	ssize_t buflen, resid;
+	off_t buflen;
 
 	PFS_TRACE(("%s", pn->pn_name));
 	pfs_assert_not_owned(pn);
@@ -636,7 +638,7 @@
 	 * This is necessary because either process' privileges may
 	 * have changed since the open() call.
 	 */
-	if (!pfs_visible(curthread, pn, pvd->pvd_pid, &proc))
+	if (!pfs_visible(curthread, pn, pvd->pvd_pid, false, &proc))
 		PFS_RETURN (EIO);
 	if (proc != NULL) {
 		_PHOLD(proc);
@@ -654,14 +656,12 @@
 		goto ret;
 	}
 
-	/* beaucoup sanity checks so we don't ask for bogus allocation */
-	if (uio->uio_offset < 0 || uio->uio_resid < 0 ||
-	    (offset = uio->uio_offset) != uio->uio_offset ||
-	    (resid = uio->uio_resid) != uio->uio_resid ||
-	    (buflen = offset + resid) < offset || buflen >= INT_MAX) {
+	if (uio->uio_resid < 0 || uio->uio_offset < 0 ||
+	    uio->uio_resid > OFF_MAX - uio->uio_offset) {
 		error = EINVAL;
 		goto ret;
 	}
+	buflen = uio->uio_offset + uio->uio_resid;
 	if (buflen > MAXPHYS)
 		buflen = MAXPHYS;
 
@@ -794,7 +794,7 @@
 	pfs_lock(pd);
 
         /* check if the directory is visible to the caller */
-        if (!pfs_visible(curthread, pd, pid, &proc)) {
+        if (!pfs_visible(curthread, pd, pid, true, &proc)) {
 		sx_sunlock(&allproc_lock);
 		pfs_unlock(pd);
                 PFS_RETURN (ENOENT);
@@ -998,7 +998,7 @@
 	 * This is necessary because either process' privileges may
 	 * have changed since the open() call.
 	 */
-	if (!pfs_visible(curthread, pn, pvd->pvd_pid, &proc))
+	if (!pfs_visible(curthread, pn, pvd->pvd_pid, false, &proc))
 		PFS_RETURN (EIO);
 	if (proc != NULL) {
 		_PHOLD(proc);



More information about the Midnightbsd-cvs mailing list