Module Name:    src
Committed By:   hannken
Date:           Mon Mar 17 09:28:37 UTC 2014

Modified Files:
        src/sys/kern: vfs_subr.c

Log Message:
Change sysctl_kern_vnode() to use vfs_vnode_iterator.


To generate a diff of this commit:
cvs rdiff -u -r1.442 -r1.443 src/sys/kern/vfs_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_subr.c
diff -u src/sys/kern/vfs_subr.c:1.442 src/sys/kern/vfs_subr.c:1.443
--- src/sys/kern/vfs_subr.c:1.442	Thu Feb 27 13:00:06 2014
+++ src/sys/kern/vfs_subr.c	Mon Mar 17 09:28:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_subr.c,v 1.442 2014/02/27 13:00:06 hannken Exp $	*/
+/*	$NetBSD: vfs_subr.c,v 1.443 2014/03/17 09:28:37 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.442 2014/02/27 13:00:06 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.443 2014/03/17 09:28:37 hannken Exp $");
 
 #include "opt_ddb.h"
 #include "opt_compat_netbsd.h"
@@ -611,7 +611,8 @@ sysctl_kern_vnode(SYSCTLFN_ARGS)
 	char *where = oldp;
 	size_t *sizep = oldlenp;
 	struct mount *mp, *nmp;
-	vnode_t *vp, *mvp, vbuf;
+	vnode_t *vp, vbuf;
+	struct vnode_iterator *marker;
 	char *bp = where;
 	char *ewhere;
 	int error;
@@ -635,47 +636,29 @@ sysctl_kern_vnode(SYSCTLFN_ARGS)
 		if (vfs_busy(mp, &nmp)) {
 			continue;
 		}
-		/* Allocate a marker vnode. */
-		mvp = vnalloc(mp);
-		/* Should never fail for mp != NULL */
-		KASSERT(mvp != NULL);
-		mutex_enter(&mntvnode_lock);
-		for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp;
-		    vp = vunmark(mvp)) {
-			vmark(mvp, vp);
-			/*
-			 * Check that the vp is still associated with
-			 * this filesystem.  RACE: could have been
-			 * recycled onto the same filesystem.
-			 */
-			if (vp->v_mount != mp || vismarker(vp))
-				continue;
+		vfs_vnode_iterator_init(mp, &marker);
+		while (vfs_vnode_iterator_next(marker, &vp)) {
 			if (bp + VPTRSZ + VNODESZ > ewhere) {
-				(void)vunmark(mvp);
-				mutex_exit(&mntvnode_lock);
-				vnfree(mvp);
+				vrele(vp);
+				vfs_vnode_iterator_destroy(marker);
 				vfs_unbusy(mp, false, NULL);
 				sysctl_relock();
 				*sizep = bp - where;
 				return (ENOMEM);
 			}
 			memcpy(&vbuf, vp, VNODESZ);
-			mutex_exit(&mntvnode_lock);
 			if ((error = copyout(&vp, bp, VPTRSZ)) ||
 			    (error = copyout(&vbuf, bp + VPTRSZ, VNODESZ))) {
-			   	mutex_enter(&mntvnode_lock);
-				(void)vunmark(mvp);
-				mutex_exit(&mntvnode_lock);
-				vnfree(mvp);
+				vrele(vp);
+				vfs_vnode_iterator_destroy(marker);
 				vfs_unbusy(mp, false, NULL);
 				sysctl_relock();
 				return (error);
 			}
+			vrele(vp);
 			bp += VPTRSZ + VNODESZ;
-			mutex_enter(&mntvnode_lock);
 		}
-		mutex_exit(&mntvnode_lock);
-		vnfree(mvp);
+		vfs_vnode_iterator_destroy(marker);
 		vfs_unbusy(mp, false, &nmp);
 	}
 	mutex_exit(&mountlist_lock);

Reply via email to