rename Rename vget() to vcache_vget() and vcache_tryvget() respectively and move the definitions to sys/vnode_impl.h. No functional change intended. diff -r 7c51907d1871 -r 49fbe916cad9 distrib/sets/lists/comp/mi --- a/distrib/sets/lists/comp/mi Tue Dec 27 16:32:36 2016 +0100 +++ b/distrib/sets/lists/comp/mi Tue Dec 27 16:32:36 2016 +0100 @@ -11224,7 +11224,7 @@ ./usr/share/man/cat9/vfs_write_suspend.0 comp-obsolete obsolete ./usr/share/man/cat9/vfsops.0 comp-sys-catman .cat ./usr/share/man/cat9/vfssubr.0 comp-sys-catman .cat -./usr/share/man/cat9/vget.0 comp-sys-catman .cat +./usr/share/man/cat9/vget.0 comp-sys-catman obsolete ./usr/share/man/cat9/vgone.0 comp-sys-catman .cat ./usr/share/man/cat9/vgonel.0 comp-sys-catman .cat ./usr/share/man/cat9/vhold.0 comp-sys-catman .cat @@ -18398,7 +18398,7 @@ ./usr/share/man/html9/vfs_vnode_iterator_next.html comp-sys-htmlman html ./usr/share/man/html9/vfsops.html comp-sys-htmlman html ./usr/share/man/html9/vfssubr.html comp-sys-htmlman html -./usr/share/man/html9/vget.html comp-sys-htmlman html +./usr/share/man/html9/vget.html comp-sys-htmlman obsolete ./usr/share/man/html9/vgone.html comp-sys-htmlman html ./usr/share/man/html9/vgonel.html comp-sys-htmlman html ./usr/share/man/html9/vhold.html comp-sys-htmlman html @@ -25812,7 +25812,7 @@ ./usr/share/man/man9/vfs_write_suspend.9 comp-obsolete obsolete ./usr/share/man/man9/vfsops.9 comp-sys-man .man ./usr/share/man/man9/vfssubr.9 comp-sys-man .man -./usr/share/man/man9/vget.9 comp-sys-man .man +./usr/share/man/man9/vget.9 comp-sys-man obsolete ./usr/share/man/man9/vgone.9 comp-sys-man .man ./usr/share/man/man9/vgonel.9 comp-sys-man .man ./usr/share/man/man9/vhold.9 comp-sys-man .man diff -r 7c51907d1871 -r 49fbe916cad9 share/man/man9/Makefile --- a/share/man/man9/Makefile Tue Dec 27 16:32:36 2016 +0100 +++ b/share/man/man9/Makefile Tue Dec 27 16:32:36 2016 +0100 @@ -949,7 +949,6 @@ MLINKS+=vnode.9 vref.9 \ vnode.9 vrele.9 \ vnode.9 vrele_async.9 \ - vnode.9 vget.9 \ vnode.9 vput.9 \ vnode.9 vhold.9 \ vnode.9 holdrele.9 \ diff -r 7c51907d1871 -r 49fbe916cad9 share/man/man9/vnode.9 --- a/share/man/man9/vnode.9 Tue Dec 27 16:32:36 2016 +0100 +++ b/share/man/man9/vnode.9 Tue Dec 27 16:32:36 2016 +0100 @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd December 14, 2016 +.Dd December XX, 2016 .Dt VNODE 9 .Os .Sh NAME @@ -35,7 +35,6 @@ .Nm vref , .Nm vrele , .Nm vrele_async , -.Nm vget , .Nm vput , .Nm vhold , .Nm holdrele , @@ -68,8 +67,6 @@ .Fn vrele "struct vnode *vp" .Ft void .Fn vrele_async "struct vnode *vp" -.Ft int -.Fn vget "struct vnode *vp" "int lockflag" "int wait" .Ft void .Fn vput "struct vnode *vp" .Ft void @@ -152,12 +149,10 @@ have any users, and another thread in the system may be simultaneously deciding to reclaim it. Thus, to retrieve a vnode from a cache, one must use -.Fn vget , +.Fn vcache_get , not .Fn vref , -to acquire the first reference, and be prepared for -.Fn vget -to fail if another thread is reclaiming the vnode. +to acquire the first reference. .Pp The vnode has the following structure: .Bd -literal @@ -349,10 +344,8 @@ .Xr vnodeops 9 for a description of vnode operations. .Pp -When a valid vnode which is cached is used again, the user must call -.Fn vget -to increment the reference count. -When a user wants a new vnode for another file, +When a user wants a new vnode for another file or wants a valid vnode +which is cached, .Fn vcache_get or .Fn vcache_new @@ -540,60 +533,6 @@ .It Fn vrele_async "vp" Will asychronously release the vnode in different context than the caller, sometime after the call. -.It Fn vget "vp" "lockflags" "wait" -Reclaim vnode -.Fa vp -from the cache and increment its reference count. -.Pp -The vnode -.Fa vp -may be changing state: another thread may be initializing it from disk, -or revoking it with -.Xr revoke 2 , -or reclaiming it with -.Xr VOP_RECLAIM 9 . -In that case, -.Fn vget -will wait until the state has changed, if -.Fa lockflags -is -.Li 0 -and -.Fa wait -is -.Li true ; -or will return -.Er EBUSY -if -.Fa lockflags -is -.Dv LK_NOWAIT -and -.Fa wait -is -.Li false . -.Pp -(The extra argument enables the compiler to detect old code which -additionally used -.Fn vget -to lock the vnode.) -.Pp -Returns -.Bl -tag -offset abcd -width ENOENT -compact -.It Er EBUSY -if -.Fa vp -was changing state and -.Fa wait -is false. -.It Er ENOENT -if the system was reclaiming -.Fa vp -with -.Xr VOP_RECLAIM 9 . -.It Li 0 -on success. -.El .It Fn vput "vp" Legacy convenience routine for unlocking and releasing .Fa vp . @@ -603,11 +542,6 @@ .No "vrele(" Ns Fa vp Ns Li ");" .Ed .Pp -Note that this is -.Em not -an inverse of -.Fn vget . -The name appears so for hysterical raisins. New code should prefer using .Xr VOP_UNLOCK 9 and diff -r 7c51907d1871 -r 49fbe916cad9 share/man/man9/vnsubr.9 --- a/share/man/man9/vnsubr.9 Tue Dec 27 16:32:36 2016 +0100 +++ b/share/man/man9/vnsubr.9 Tue Dec 27 16:32:36 2016 +0100 @@ -146,9 +146,6 @@ .Pp .Fn vn_lock must not be called when the vnode's reference count is zero. -Instead, -.Xr vget 9 -should be used. .It Fn vn_markexec "vp" Common code to mark the vnode .Fa vp diff -r 7c51907d1871 -r 49fbe916cad9 sys/kern/vfs_cache.c --- a/sys/kern/vfs_cache.c Tue Dec 27 16:32:36 2016 +0100 +++ b/sys/kern/vfs_cache.c Tue Dec 27 16:32:36 2016 +0100 @@ -71,7 +71,7 @@ #include #include #include -#include +#include #include #include #include @@ -101,8 +101,8 @@ * is for DELETE, or NOCACHE is set (rewrite), and the * name is located in the cache, it will be dropped. * The entry is dropped also when it was not possible to lock - * the cached vnode, either because vget() failed or the generation - * number has changed while waiting for the lock. + * the cached vnode, either because vcache_tryvget() failed or + * the generation number has changed while waiting for the lock. */ /* @@ -588,9 +588,9 @@ mutex_exit(&cpup->cpu_lock); /* - * Unlocked except for the vnode interlock. Call vget(). + * Unlocked except for the vnode interlock. Call vcache_tryvget(). */ - error = vget(vp, LK_NOWAIT, false /* !wait */); + error = vcache_tryvget(vp); if (error) { KASSERT(error == EBUSY); /* @@ -669,9 +669,9 @@ mutex_exit(&cpup->cpu_lock); /* - * Unlocked except for the vnode interlock. Call vget(). + * Unlocked except for the vnode interlock. Call vcache_tryvget(). */ - error = vget(vp, LK_NOWAIT, false /* !wait */); + error = vcache_tryvget(vp); if (error) { KASSERT(error == EBUSY); /* @@ -761,7 +761,7 @@ mutex_enter(dvp->v_interlock); mutex_exit(&ncp->nc_lock); mutex_exit(namecache_lock); - error = vget(dvp, LK_NOWAIT, false /* !wait */); + error = vcache_tryvget(dvp); if (error) { KASSERT(error == EBUSY); if (bufp) diff -r 7c51907d1871 -r 49fbe916cad9 sys/kern/vfs_mount.c --- a/sys/kern/vfs_mount.c Tue Dec 27 16:32:36 2016 +0100 +++ b/sys/kern/vfs_mount.c Tue Dec 27 16:32:36 2016 +0100 @@ -402,7 +402,7 @@ TAILQ_INSERT_AFTER(&mp->mnt_vnodelist, vp, mvp, v_mntvnodes); mvp->v_usecount = 1; mutex_exit(&mntvnode_lock); - error = vget(vp, 0, true /* wait */); + error = vcache_vget(vp); KASSERT(error == 0 || error == ENOENT); } while (error != 0); @@ -553,7 +553,7 @@ if (vp != NULL) { mutex_enter(vp->v_interlock); mutex_exit(&mntvnode_lock); - error = vget(vp, 0, true /* wait */); + error = vcache_vget(vp); if (error == ENOENT) continue; else if (error == 0) diff -r 7c51907d1871 -r 49fbe916cad9 sys/kern/vfs_subr.c --- a/sys/kern/vfs_subr.c Tue Dec 27 16:32:36 2016 +0100 +++ b/sys/kern/vfs_subr.c Tue Dec 27 16:32:36 2016 +0100 @@ -736,7 +736,7 @@ /* We are locking in the wrong direction. */ if (mutex_tryenter(vp->v_interlock)) { mutex_exit(&syncer_data_lock); - if (vget(vp, LK_NOWAIT, false /* !wait */) == 0) { + if (vcache_tryvget(vp) == 0) { if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT) == 0) { synced = true; (void) VOP_FSYNC(vp, curlwp->l_cred, diff -r 7c51907d1871 -r 49fbe916cad9 sys/kern/vfs_vnode.c --- a/sys/kern/vfs_vnode.c Tue Dec 27 16:32:36 2016 +0100 +++ b/sys/kern/vfs_vnode.c Tue Dec 27 16:32:36 2016 +0100 @@ -76,7 +76,7 @@ * starts in one of the following ways: * * - Allocation, via vcache_get(9) or vcache_new(9). - * - Reclamation of inactive vnode, via vget(9). + * - Reclamation of inactive vnode, via vcache_vget(9). * * Recycle from a free list, via getnewvnode(9) -> getcleanvnode(9) * was another, traditional way. Currently, only the draining thread @@ -482,7 +482,7 @@ vdrain_retry = true; mutex_exit(&vdrain_lock); - if (vget(vp, 0, true /* wait */) == 0) { + if (vcache_vget(vp) == 0) { if (!vrecycle(vp)) vrele(vp); } @@ -578,63 +578,6 @@ } /* - * vget: get a particular vnode from the free list, increment its reference - * count and return it. - * - * => Must be called with v_interlock held. - * - * If state is VS_RECLAIMING, the vnode may be eliminated in vcache_reclaim(). - * In that case, we cannot grab the vnode, so the process is awakened when - * the transition is completed, and an error returned to indicate that the - * vnode is no longer usable. - * - * If state is VS_LOADING or VS_BLOCKED, wait until the vnode enters a - * stable state (VS_ACTIVE or VS_RECLAIMED). - */ -int -vget(vnode_t *vp, int flags, bool waitok) -{ - - KASSERT(mutex_owned(vp->v_interlock)); - KASSERT((flags & ~LK_NOWAIT) == 0); - KASSERT(waitok == ((flags & LK_NOWAIT) == 0)); - - /* - * Before adding a reference, we must remove the vnode - * from its freelist. - */ - if (vp->v_usecount == 0) { - vp->v_usecount = 1; - } else { - atomic_inc_uint(&vp->v_usecount); - } - - /* - * If the vnode is in the process of changing state we wait - * for the change to complete and take care not to return - * a clean vnode. - */ - if (! ISSET(flags, LK_NOWAIT)) - VSTATE_WAIT_STABLE(vp); - if (VSTATE_GET(vp) == VS_RECLAIMED) { - vrelel(vp, 0); - return ENOENT; - } else if (VSTATE_GET(vp) != VS_ACTIVE) { - KASSERT(ISSET(flags, LK_NOWAIT)); - vrelel(vp, 0); - return EBUSY; - } - - /* - * Ok, we got it in good shape. - */ - VSTATE_ASSERT(vp, VS_ACTIVE); - mutex_exit(vp->v_interlock); - - return 0; -} - -/* * vput: unlock and release the reference. */ void @@ -1124,6 +1067,97 @@ } /* + * Try to get an initial reference on this cached vnode. + * Returns zero on success, ENOENT if the vnode has been reclaimed and + * EBUSY if the vnode state is unstable. + * + * v_interlock locked on entry and unlocked on exit. + */ +int +vcache_tryvget(vnode_t *vp) +{ + + KASSERT(mutex_owned(vp->v_interlock)); + + /* + * Before adding a reference, we must remove the vnode + * from its freelist. + */ + if (vp->v_usecount == 0) { + vp->v_usecount = 1; + } else { + atomic_inc_uint(&vp->v_usecount); + } + + /* + * If the vnode is in the process of changing state we wait + * for the change to complete and take care not to return + * a clean vnode. + */ + if (VSTATE_GET(vp) == VS_RECLAIMED) { + vrelel(vp, 0); + return ENOENT; + } else if (VSTATE_GET(vp) != VS_ACTIVE) { + vrelel(vp, 0); + return EBUSY; + } + + /* + * Ok, we got it in good shape. + */ + VSTATE_ASSERT(vp, VS_ACTIVE); + mutex_exit(vp->v_interlock); + + return 0; +} + +/* + * Try to get an initial reference on this cached vnode. + * Returns zero on success and ENOENT if the vnode has been reclaimed. + * Will wait for the vnode state to be stable. + * + * v_interlock locked on entry and unlocked on exit. + */ +int +vcache_vget(vnode_t *vp) +{ + + KASSERT(mutex_owned(vp->v_interlock)); + + /* + * Before adding a reference, we must remove the vnode + * from its freelist. + */ + if (vp->v_usecount == 0) { + vp->v_usecount = 1; + } else { + atomic_inc_uint(&vp->v_usecount); + } + + /* + * If the vnode is in the process of changing state we wait + * for the change to complete and take care not to return + * a clean vnode. + */ + VSTATE_WAIT_STABLE(vp); + if (VSTATE_GET(vp) == VS_RECLAIMED) { + vrelel(vp, 0); + return ENOENT; + } else if (VSTATE_GET(vp) != VS_ACTIVE) { + vrelel(vp, 0); + return EBUSY; + } + + /* + * Ok, we got it in good shape. + */ + VSTATE_ASSERT(vp, VS_ACTIVE); + mutex_exit(vp->v_interlock); + + return 0; +} + +/* * Get a vnode / fs node pair by key and return it referenced through vpp. */ int @@ -1167,7 +1201,7 @@ vp = VIMPL_TO_VNODE(node); mutex_enter(vp->v_interlock); mutex_exit(&vcache.lock); - error = vget(vp, 0, true /* wait */); + error = vcache_vget(vp); if (error == ENOENT) goto again; if (error == 0) @@ -1282,7 +1316,7 @@ ovp = VIMPL_TO_VNODE(old_node); mutex_enter(ovp->v_interlock); mutex_exit(&vcache.lock); - error = vget(ovp, 0, true /* wait */); + error = vcache_vget(ovp); KASSERT(error == ENOENT); mutex_enter(&vcache.lock); } diff -r 7c51907d1871 -r 49fbe916cad9 sys/miscfs/specfs/spec_vnops.c --- a/sys/miscfs/specfs/spec_vnops.c Tue Dec 27 16:32:36 2016 +0100 +++ b/sys/miscfs/specfs/spec_vnops.c Tue Dec 27 16:32:36 2016 +0100 @@ -68,7 +68,7 @@ #include #include #include -#include +#include #include #include #include @@ -310,7 +310,7 @@ mutex_enter(vp->v_interlock); } mutex_exit(&device_lock); - error = vget(vp, 0, true /* wait */); + error = vcache_vget(vp); if (error != 0) return error; *vpp = vp; @@ -345,7 +345,7 @@ } mutex_enter(vq->v_interlock); mutex_exit(&device_lock); - error = vget(vq, 0, true /* wait */); + error = vcache_vget(vq); if (error != 0) return error; *vpp = vq; diff -r 7c51907d1871 -r 49fbe916cad9 sys/sys/vnode.h --- a/sys/sys/vnode.h Tue Dec 27 16:32:36 2016 +0100 +++ b/sys/sys/vnode.h Tue Dec 27 16:32:36 2016 +0100 @@ -518,7 +518,6 @@ int vfinddev(dev_t, enum vtype, struct vnode **); int vflush(struct mount *, struct vnode *, int); int vflushbuf(struct vnode *, int); -int vget(struct vnode *, int, bool); void vgone(struct vnode *); int vinvalbuf(struct vnode *, int, kauth_cred_t, struct lwp *, bool, int); void vprint(const char *, struct vnode *); diff -r 7c51907d1871 -r 49fbe916cad9 sys/sys/vnode_impl.h --- a/sys/sys/vnode_impl.h Tue Dec 27 16:32:36 2016 +0100 +++ b/sys/sys/vnode_impl.h Tue Dec 27 16:32:36 2016 +0100 @@ -71,6 +71,8 @@ vnalloc_marker(struct mount *); void vnfree_marker(vnode_t *); bool vnis_marker(vnode_t *); +int vcache_vget(vnode_t *); +int vcache_tryvget(vnode_t *); int vfs_drainvnodes(void); #endif /* !_SYS_VNODE_IMPL_H_ */