Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jan 2017 20:14:19 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r311815 - head/sys/fs/pseudofs
Message-ID:  <201701092014.v09KEJIK067071@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Mon Jan  9 20:14:18 2017
New Revision: 311815
URL: https://svnweb.freebsd.org/changeset/base/311815

Log:
  Forcibly remove the cached items from pseudofs vncache on module unload.
  
  If some process' nodes were accessed using procfs and the process
  cannot exit properly at the time modunload event is reported to the
  pseudofs-backed filesystem, the assertion in pfs_vncache_unload() is
  triggered.  Assertion is correct, the cache should be cleaned.
  
  Approved by:	des (pseudofs maintainer)
  Reported and tested by:	pho
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/sys/fs/pseudofs/pseudofs_vncache.c

Modified: head/sys/fs/pseudofs/pseudofs_vncache.c
==============================================================================
--- head/sys/fs/pseudofs/pseudofs_vncache.c	Mon Jan  9 20:14:02 2017	(r311814)
+++ head/sys/fs/pseudofs/pseudofs_vncache.c	Mon Jan  9 20:14:18 2017	(r311815)
@@ -51,6 +51,7 @@ static struct mtx pfs_vncache_mutex;
 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");
@@ -97,6 +98,9 @@ pfs_vncache_unload(void)
 {
 
 	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);
@@ -272,7 +276,7 @@ pfs_vncache_free(struct vnode *vp)
  * 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;
@@ -280,7 +284,8 @@ pfs_purge_locked(struct pfs_node *pn)
 	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);
@@ -301,7 +306,7 @@ pfs_purge(struct pfs_node *pn)
 {
 
 	mtx_lock(&pfs_vncache_mutex);
-	pfs_purge_locked(pn);
+	pfs_purge_locked(pn, false);
 	mtx_unlock(&pfs_vncache_mutex);
 }
 
@@ -321,6 +326,6 @@ pfs_exit(void *arg, struct proc *p)
 		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);
 }



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