Module Name: src Committed By: hannken Date: Wed Jan 11 09:07:58 UTC 2017
Modified Files: src/share/man/man9: vnode.9 src/sys/kern: vfs_mount.c vfs_subr.c src/sys/sys: mount.h vnode.h vnode_impl.h src/usr.sbin/pstat: pstat.c Log Message: Move vnode member v_mntvnodes as vi_mntvnodes to vnode_impl.h. Add an ugly hack so pstat.c may still traverse the list. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/share/man/man9/vnode.9 cvs rdiff -u -r1.43 -r1.44 src/sys/kern/vfs_mount.c cvs rdiff -u -r1.455 -r1.456 src/sys/kern/vfs_subr.c cvs rdiff -u -r1.219 -r1.220 src/sys/sys/mount.h cvs rdiff -u -r1.270 -r1.271 src/sys/sys/vnode.h cvs rdiff -u -r1.9 -r1.10 src/sys/sys/vnode_impl.h cvs rdiff -u -r1.125 -r1.126 src/usr.sbin/pstat/pstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man9/vnode.9 diff -u src/share/man/man9/vnode.9:1.76 src/share/man/man9/vnode.9:1.77 --- src/share/man/man9/vnode.9:1.76 Wed Jan 11 09:06:57 2017 +++ src/share/man/man9/vnode.9 Wed Jan 11 09:07:57 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: vnode.9,v 1.76 2017/01/11 09:06:57 hannken Exp $ +.\" $NetBSD: vnode.9,v 1.77 2017/01/11 09:07:57 hannken Exp $ .\" .\" Copyright (c) 2001, 2005, 2006 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -169,7 +169,6 @@ struct vnode { int v_holdcnt; /* page & buffer refs */ struct mount *v_mount; /* ptr to vfs we are in */ int (**v_op)(void *); /* vnode operations vector */ - TAILQ_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */ struct buflists v_cleanblkhd; /* clean blocklist head */ struct buflists v_dirtyblkhd; /* dirty blocklist head */ union { Index: src/sys/kern/vfs_mount.c diff -u src/sys/kern/vfs_mount.c:1.43 src/sys/kern/vfs_mount.c:1.44 --- src/sys/kern/vfs_mount.c:1.43 Mon Jan 2 10:33:28 2017 +++ src/sys/kern/vfs_mount.c Wed Jan 11 09:07:57 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_mount.c,v 1.43 2017/01/02 10:33:28 hannken Exp $ */ +/* $NetBSD: vfs_mount.c,v 1.44 2017/01/11 09:07:57 hannken Exp $ */ /*- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.43 2017/01/02 10:33:28 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.44 2017/01/11 09:07:57 hannken Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -99,6 +99,8 @@ vnode_t * rootvnode; /* Mounted filesystem list. */ struct mntlist mountlist; kmutex_t mountlist_lock; +int vnode_offset_next_by_mount /* XXX: ugly hack for pstat.c */ + = offsetof(vnode_impl_t, vi_mntvnodes.tqe_next); kmutex_t mntvnode_lock; kmutex_t vfs_list_lock; @@ -336,33 +338,36 @@ vfs_unbusy(struct mount *mp, bool keepre } struct vnode_iterator { - struct vnode vi_vnode; + vnode_impl_t vi_vnode; }; void -vfs_vnode_iterator_init(struct mount *mp, struct vnode_iterator **vip) +vfs_vnode_iterator_init(struct mount *mp, struct vnode_iterator **vnip) { - struct vnode *vp; + vnode_t *vp; + vnode_impl_t *vip; vp = vnalloc_marker(mp); + vip = VNODE_TO_VIMPL(vp); mutex_enter(&mntvnode_lock); - TAILQ_INSERT_HEAD(&mp->mnt_vnodelist, vp, v_mntvnodes); + TAILQ_INSERT_HEAD(&mp->mnt_vnodelist, vip, vi_mntvnodes); vp->v_usecount = 1; mutex_exit(&mntvnode_lock); - *vip = (struct vnode_iterator *)vp; + *vnip = (struct vnode_iterator *)vip; } void -vfs_vnode_iterator_destroy(struct vnode_iterator *vi) +vfs_vnode_iterator_destroy(struct vnode_iterator *vni) { - struct vnode *mvp = &vi->vi_vnode; + vnode_impl_t *mvip = &vni->vi_vnode; + vnode_t *mvp = VIMPL_TO_VNODE(mvip); mutex_enter(&mntvnode_lock); KASSERT(vnis_marker(mvp)); if (mvp->v_usecount != 0) { - TAILQ_REMOVE(&mvp->v_mount->mnt_vnodelist, mvp, v_mntvnodes); + TAILQ_REMOVE(&mvp->v_mount->mnt_vnodelist, mvip, vi_mntvnodes); mvp->v_usecount = 0; } mutex_exit(&mntvnode_lock); @@ -370,22 +375,24 @@ vfs_vnode_iterator_destroy(struct vnode_ } struct vnode * -vfs_vnode_iterator_next(struct vnode_iterator *vi, +vfs_vnode_iterator_next(struct vnode_iterator *vni, bool (*f)(void *, struct vnode *), void *cl) { - struct vnode *mvp = &vi->vi_vnode; - struct mount *mp = mvp->v_mount; - struct vnode *vp; + vnode_impl_t *mvip = &vni->vi_vnode; + struct mount *mp = VIMPL_TO_VNODE(mvip)->v_mount; + vnode_t *vp; + vnode_impl_t *vip; int error; - KASSERT(vnis_marker(mvp)); + KASSERT(vnis_marker(VIMPL_TO_VNODE(mvip))); do { mutex_enter(&mntvnode_lock); - vp = TAILQ_NEXT(mvp, v_mntvnodes); - TAILQ_REMOVE(&mp->mnt_vnodelist, mvp, v_mntvnodes); - mvp->v_usecount = 0; + vip = TAILQ_NEXT(mvip, vi_mntvnodes); + TAILQ_REMOVE(&mp->mnt_vnodelist, mvip, vi_mntvnodes); + VIMPL_TO_VNODE(mvip)->v_usecount = 0; again: + vp = VIMPL_TO_VNODE(vip); if (vp == NULL) { mutex_exit(&mntvnode_lock); return NULL; @@ -395,12 +402,12 @@ again: vdead_check(vp, VDEAD_NOWAIT) || (f && !(*f)(cl, vp))) { mutex_exit(vp->v_interlock); - vp = TAILQ_NEXT(vp, v_mntvnodes); + vip = TAILQ_NEXT(vip, vi_mntvnodes); goto again; } - TAILQ_INSERT_AFTER(&mp->mnt_vnodelist, vp, mvp, v_mntvnodes); - mvp->v_usecount = 1; + TAILQ_INSERT_AFTER(&mp->mnt_vnodelist, vip, mvip, vi_mntvnodes); + VIMPL_TO_VNODE(mvip)->v_usecount = 1; mutex_exit(&mntvnode_lock); error = vcache_vget(vp); KASSERT(error == 0 || error == ENOENT); @@ -415,6 +422,7 @@ again: void vfs_insmntque(vnode_t *vp, struct mount *mp) { + vnode_impl_t *vip = VNODE_TO_VIMPL(vp); struct mount *omp; KASSERT(mp == NULL || (mp->mnt_iflag & IMNT_UNMOUNT) == 0 || @@ -425,14 +433,14 @@ vfs_insmntque(vnode_t *vp, struct mount * Delete from old mount point vnode list, if on one. */ if ((omp = vp->v_mount) != NULL) - TAILQ_REMOVE(&vp->v_mount->mnt_vnodelist, vp, v_mntvnodes); + TAILQ_REMOVE(&vp->v_mount->mnt_vnodelist, vip, vi_mntvnodes); /* * Insert into list of vnodes for the new mount point, if * available. The caller must take a reference on the mount * structure and donate to the vnode. */ if ((vp->v_mount = mp) != NULL) - TAILQ_INSERT_TAIL(&mp->mnt_vnodelist, vp, v_mntvnodes); + TAILQ_INSERT_TAIL(&mp->mnt_vnodelist, vip, vi_mntvnodes); mutex_exit(&mntvnode_lock); if (omp != NULL) { @@ -505,6 +513,7 @@ int vflush(struct mount *mp, vnode_t *skipvp, int flags) { vnode_t *vp; + vnode_impl_t *vip; struct vnode_iterator *marker; int error, busy = 0, when = 0; struct vflush_ctx ctx; @@ -543,14 +552,16 @@ vflush(struct mount *mp, vnode_t *skipvp /* Wait for all vnodes to be reclaimed. */ for (;;) { mutex_enter(&mntvnode_lock); - TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) { + TAILQ_FOREACH(vip, &mp->mnt_vnodelist, vi_mntvnodes) { + vp = VIMPL_TO_VNODE(vip); if (vp == skipvp) continue; if ((flags & SKIPSYSTEM) && (vp->v_vflag & VV_SYSTEM)) continue; break; } - if (vp != NULL) { + if (vip != NULL) { + KASSERT(vp == VIMPL_TO_VNODE(vip)); mutex_enter(vp->v_interlock); mutex_exit(&mntvnode_lock); error = vcache_vget(vp); Index: src/sys/kern/vfs_subr.c diff -u src/sys/kern/vfs_subr.c:1.455 src/sys/kern/vfs_subr.c:1.456 --- src/sys/kern/vfs_subr.c:1.455 Wed Jan 11 09:06:57 2017 +++ src/sys/kern/vfs_subr.c Wed Jan 11 09:07:57 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_subr.c,v 1.455 2017/01/11 09:06:57 hannken Exp $ */ +/* $NetBSD: vfs_subr.c,v 1.456 2017/01/11 09:07:57 hannken Exp $ */ /*- * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.455 2017/01/11 09:06:57 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.456 2017/01/11 09:07:57 hannken Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -1594,9 +1594,11 @@ vfs_mount_print(struct mount *mp, int fu { int cnt = 0; - struct vnode *vp; + vnode_t *vp; + vnode_impl_t *vip; (*pr)("locked vnodes ="); - TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) { + TAILQ_FOREACH(vip, &mp->mnt_vnodelist, vi_mntvnodes) { + vp = VIMPL_TO_VNODE(vip); if (VOP_ISLOCKED(vp)) { if ((++cnt % 6) == 0) { (*pr)(" %p,\n\t", vp); @@ -1610,10 +1612,12 @@ vfs_mount_print(struct mount *mp, int fu if (full) { int cnt = 0; - struct vnode *vp; + vnode_t *vp; + vnode_impl_t *vip; (*pr)("all vnodes ="); - TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) { - if (!TAILQ_NEXT(vp, v_mntvnodes)) { + TAILQ_FOREACH(vip, &mp->mnt_vnodelist, vi_mntvnodes) { + vp = VIMPL_TO_VNODE(vip); + if (!TAILQ_NEXT(vip, vi_mntvnodes)) { (*pr)(" %p", vp); } else if ((++cnt % 6) == 0) { (*pr)(" %p,\n\t", vp); @@ -1621,7 +1625,7 @@ vfs_mount_print(struct mount *mp, int fu (*pr)(" %p,", vp); } } - (*pr)("\n", vp); + (*pr)("\n"); } } @@ -1634,7 +1638,8 @@ void printlockedvnodes(void) { struct mount *mp, *nmp; - struct vnode *vp; + vnode_t *vp; + vnode_impl_t *vip; printf("Locked vnodes\n"); mutex_enter(&mountlist_lock); @@ -1642,7 +1647,8 @@ printlockedvnodes(void) if (vfs_busy(mp, &nmp)) { continue; } - TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) { + TAILQ_FOREACH(vip, &mp->mnt_vnodelist, vi_mntvnodes) { + vp = VIMPL_TO_VNODE(vip); if (VOP_ISLOCKED(vp)) vprint(NULL, vp); } Index: src/sys/sys/mount.h diff -u src/sys/sys/mount.h:1.219 src/sys/sys/mount.h:1.220 --- src/sys/sys/mount.h:1.219 Thu Jul 7 06:55:44 2016 +++ src/sys/sys/mount.h Wed Jan 11 09:07:57 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: mount.h,v 1.219 2016/07/07 06:55:44 msaitoh Exp $ */ +/* $NetBSD: mount.h,v 1.220 2017/01/11 09:07:57 hannken Exp $ */ /* * Copyright (c) 1989, 1991, 1993 @@ -100,6 +100,7 @@ #ifndef _STANDALONE struct vnode; +struct vnode_impl; struct vattr; /* @@ -109,7 +110,7 @@ struct vattr; */ struct mount { TAILQ_ENTRY(mount) mnt_list; /* mount list */ - TAILQ_HEAD(, vnode) mnt_vnodelist; /* list of vnodes this mount */ + TAILQ_HEAD(, vnode_impl) mnt_vnodelist; /* list of vnodes this mount */ struct vfsops *mnt_op; /* operations on fs */ struct vnode *mnt_vnodecovered; /* vnode we mounted on */ int mnt_synclist_slot; /* synclist slot index */ Index: src/sys/sys/vnode.h diff -u src/sys/sys/vnode.h:1.270 src/sys/sys/vnode.h:1.271 --- src/sys/sys/vnode.h:1.270 Wed Jan 11 09:06:57 2017 +++ src/sys/sys/vnode.h Wed Jan 11 09:07:57 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vnode.h,v 1.270 2017/01/11 09:06:57 hannken Exp $ */ +/* $NetBSD: vnode.h,v 1.271 2017/01/11 09:07:57 hannken Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -126,7 +126,6 @@ LIST_HEAD(buflists, buf); * : stable, reference to the vnode is required * f vnode_free_list_lock, or vrele_lock for vrele_list * i v_interlock - * m mntvnode_lock * u locked by underlying filesystem * v vnode lock * x v_interlock + bufcache_lock to modify, either to inspect @@ -147,7 +146,6 @@ struct vnode { int v_holdcnt; /* i: page & buffer refs */ struct mount *v_mount; /* v: ptr to vfs we are in */ int (**v_op)(void *); /* :: vnode operations vector */ - TAILQ_ENTRY(vnode) v_mntvnodes; /* m: vnodes for mount point */ struct buflists v_cleanblkhd; /* x: clean blocklist head */ struct buflists v_dirtyblkhd; /* x: dirty blocklist head */ union { Index: src/sys/sys/vnode_impl.h diff -u src/sys/sys/vnode_impl.h:1.9 src/sys/sys/vnode_impl.h:1.10 --- src/sys/sys/vnode_impl.h:1.9 Wed Jan 11 09:06:57 2017 +++ src/sys/sys/vnode_impl.h Wed Jan 11 09:07:58 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vnode_impl.h,v 1.9 2017/01/11 09:06:57 hannken Exp $ */ +/* $NetBSD: vnode_impl.h,v 1.10 2017/01/11 09:07:58 hannken Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -61,6 +61,7 @@ struct vcache_key { * c vcache_lock * d vdrain_lock * i v_interlock + * m mntvnode_lock * n namecache_lock * s syncer_data_lock */ @@ -73,6 +74,7 @@ struct vnode_impl { LIST_HEAD(, namecache) vi_nclist; /* n: namecaches (parent) */ int vi_synclist_slot; /* s: synclist slot index */ TAILQ_ENTRY(vnode_impl) vi_synclist; /* s: vnodes with dirty bufs */ + TAILQ_ENTRY(vnode_impl) vi_mntvnodes; /* m: vnodes for mount point */ SLIST_ENTRY(vnode_impl) vi_hash; /* c: vnode cache list */ struct vcache_key vi_key; /* c: vnode cache key */ }; Index: src/usr.sbin/pstat/pstat.c diff -u src/usr.sbin/pstat/pstat.c:1.125 src/usr.sbin/pstat/pstat.c:1.126 --- src/usr.sbin/pstat/pstat.c:1.125 Mon Apr 20 19:36:56 2015 +++ src/usr.sbin/pstat/pstat.c Wed Jan 11 09:07:58 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: pstat.c,v 1.125 2015/04/20 19:36:56 riastradh Exp $ */ +/* $NetBSD: pstat.c,v 1.126 2017/01/11 09:07:58 hannken Exp $ */ /*- * Copyright (c) 1980, 1991, 1993, 1994 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #if 0 static char sccsid[] = "@(#)pstat.c 8.16 (Berkeley) 5/9/95"; #else -__RCSID("$NetBSD: pstat.c,v 1.125 2015/04/20 19:36:56 riastradh Exp $"); +__RCSID("$NetBSD: pstat.c,v 1.126 2017/01/11 09:07:58 hannken Exp $"); #endif #endif /* not lint */ @@ -89,13 +89,15 @@ struct nlist nl[] = { { "_mountlist", 0, 0, 0, 0 }, /* address of head of mount list. */ #define V_NUMV 1 { "_numvnodes", 0, 0, 0, 0 }, -#define FNL_NFILE 2 +#define V_NEXT_OFFSET 2 + { "_vnode_offset_next_by_mount", 0, 0, 0, 0 }, +#define FNL_NFILE 3 { "_nfiles", 0, 0, 0, 0 }, -#define FNL_MAXFILE 3 +#define FNL_MAXFILE 4 { "_maxfiles", 0, 0, 0, 0 }, -#define TTY_NTTY 4 +#define TTY_NTTY 5 { "_tty_count", 0, 0, 0, 0 }, -#define TTY_TTYLIST 5 +#define TTY_TTYLIST 6 { "_ttylist", 0, 0, 0, 0 }, #define NLMANDATORY TTY_TTYLIST /* names up to here are mandatory */ { "", 0, 0, 0, 0 } @@ -747,17 +749,20 @@ kinfo_vnodes(int *avnodes) struct mount *mp, mount; struct vnode *vp, vnode; char *beg, *bp, *ep; - int numvnodes; + int numvnodes, next_offset; KGET(V_NUMV, numvnodes); if ((bp = malloc((numvnodes + 20) * (VPTRSZ + VNODESZ))) == NULL) err(1, "malloc"); beg = bp; ep = bp + (numvnodes + 20) * (VPTRSZ + VNODESZ); + KGET(V_NEXT_OFFSET, next_offset); KGET(V_MOUNTLIST, mlist); - TAILQ_FOREACH(mp, &mlist, mnt_list) { + mp = TAILQ_FIRST(&mlist); + while (mp != NULL) { KGET2(mp, &mount, sizeof(mount), "mount entry"); - TAILQ_FOREACH(vp, &mount.mnt_vnodelist, v_mntvnodes) { + vp = (struct vnode *)TAILQ_FIRST(&mount.mnt_vnodelist); + while (vp != NULL) { KGET2(vp, &vnode, sizeof(vnode), "vnode"); if (bp + VPTRSZ + VNODESZ > ep) /* XXX - should realloc */ @@ -766,7 +771,9 @@ kinfo_vnodes(int *avnodes) bp += VPTRSZ; memmove(bp, &vnode, VNODESZ); bp += VNODESZ; + KGET2((char *)vp + next_offset, &vp, sizeof(vp), "nvp"); } + mp = TAILQ_NEXT(&mount, mnt_list); } *avnodes = (bp - beg) / (VPTRSZ + VNODESZ); return (beg);