2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Copyright (c) 1989, 1993, 1995
35 * The Regents of the University of California. All rights reserved.
37 * This code is derived from software contributed to Berkeley by
38 * Poul-Henning Kamp of the FreeBSD Project.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * @(#)vfs_cache.c 8.5 (Berkeley) 3/22/95
69 * $FreeBSD: src/sys/kern/vfs_cache.c,v 1.42.2.6 2001/10/05 20:07:03 dillon Exp $
70 * $DragonFly: src/sys/kern/vfs_cache.c,v 1.32 2004/10/04 09:20:40 dillon Exp $
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/kernel.h>
76 #include <sys/sysctl.h>
77 #include <sys/mount.h>
78 #include <sys/vnode.h>
79 #include <sys/malloc.h>
80 #include <sys/sysproto.h>
82 #include <sys/namei.h>
83 #include <sys/nlookup.h>
84 #include <sys/filedesc.h>
85 #include <sys/fnv_hash.h>
86 #include <sys/globaldata.h>
87 #include <sys/kern_syscall.h>
91 * Random lookups in the cache are accomplished with a hash table using
92 * a hash key of (nc_src_vp, name).
94 * Negative entries may exist and correspond to structures where nc_vp
95 * is NULL. In a negative entry, NCF_WHITEOUT will be set if the entry
96 * corresponds to a whited-out directory entry (verses simply not finding the
99 * Upon reaching the last segment of a path, if the reference is for DELETE,
100 * or NOCACHE is set (rewrite), and the name is located in the cache, it
105 * Structures associated with name cacheing.
107 #define NCHHASH(hash) (&nchashtbl[(hash) & nchash])
110 MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries");
112 static LIST_HEAD(nchashhead, namecache) *nchashtbl; /* Hash Table */
113 static struct namecache_list ncneglist; /* instead of vnode */
115 static u_long nchash; /* size of hash table */
116 SYSCTL_ULONG(_debug, OID_AUTO, nchash, CTLFLAG_RD, &nchash, 0, "");
118 static u_long ncnegfactor = 16; /* ratio of negative entries */
119 SYSCTL_ULONG(_debug, OID_AUTO, ncnegfactor, CTLFLAG_RW, &ncnegfactor, 0, "");
121 static u_long numneg; /* number of cache entries allocated */
122 SYSCTL_ULONG(_debug, OID_AUTO, numneg, CTLFLAG_RD, &numneg, 0, "");
124 static u_long numcache; /* number of cache entries allocated */
125 SYSCTL_ULONG(_debug, OID_AUTO, numcache, CTLFLAG_RD, &numcache, 0, "");
127 static u_long numunres; /* number of unresolved entries */
128 SYSCTL_ULONG(_debug, OID_AUTO, numunres, CTLFLAG_RD, &numunres, 0, "");
130 SYSCTL_INT(_debug, OID_AUTO, vnsize, CTLFLAG_RD, 0, sizeof(struct vnode), "");
131 SYSCTL_INT(_debug, OID_AUTO, ncsize, CTLFLAG_RD, 0, sizeof(struct namecache), "");
133 static int cache_resolve_mp(struct namecache *ncp);
136 * The new name cache statistics
138 SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW, 0, "Name cache statistics");
139 #define STATNODE(mode, name, var) \
140 SYSCTL_ULONG(_vfs_cache, OID_AUTO, name, mode, var, 0, "");
141 STATNODE(CTLFLAG_RD, numneg, &numneg);
142 STATNODE(CTLFLAG_RD, numcache, &numcache);
143 static u_long numcalls; STATNODE(CTLFLAG_RD, numcalls, &numcalls);
144 static u_long dothits; STATNODE(CTLFLAG_RD, dothits, &dothits);
145 static u_long dotdothits; STATNODE(CTLFLAG_RD, dotdothits, &dotdothits);
146 static u_long numchecks; STATNODE(CTLFLAG_RD, numchecks, &numchecks);
147 static u_long nummiss; STATNODE(CTLFLAG_RD, nummiss, &nummiss);
148 static u_long nummisszap; STATNODE(CTLFLAG_RD, nummisszap, &nummisszap);
149 static u_long numposzaps; STATNODE(CTLFLAG_RD, numposzaps, &numposzaps);
150 static u_long numposhits; STATNODE(CTLFLAG_RD, numposhits, &numposhits);
151 static u_long numnegzaps; STATNODE(CTLFLAG_RD, numnegzaps, &numnegzaps);
152 static u_long numneghits; STATNODE(CTLFLAG_RD, numneghits, &numneghits);
154 struct nchstats nchstats[SMP_MAXCPU];
156 * Export VFS cache effectiveness statistics to user-land.
158 * The statistics are left for aggregation to user-land so
159 * neat things can be achieved, like observing per-CPU cache
163 sysctl_nchstats(SYSCTL_HANDLER_ARGS)
165 struct globaldata *gd;
169 for (i = 0; i < ncpus; ++i) {
170 gd = globaldata_find(i);
171 if ((error = SYSCTL_OUT(req, (void *)&(*gd->gd_nchstats),
172 sizeof(struct nchstats))))
178 SYSCTL_PROC(_vfs_cache, OID_AUTO, nchstats, CTLTYPE_OPAQUE|CTLFLAG_RD,
179 0, 0, sysctl_nchstats, "S,nchstats", "VFS cache effectiveness statistics");
181 static void cache_zap(struct namecache *ncp);
184 * cache_hold() and cache_drop() prevent the premature deletion of a
185 * namecache entry but do not prevent operations (such as zapping) on
186 * that namecache entry.
190 _cache_hold(struct namecache *ncp)
197 * When dropping an entry
201 _cache_drop(struct namecache *ncp)
203 KKASSERT(ncp->nc_refs > 0);
204 if (ncp->nc_refs == 1 &&
205 (ncp->nc_flag & NCF_UNRESOLVED) &&
206 TAILQ_EMPTY(&ncp->nc_list)
215 * Link a new namecache entry to its parent. Be careful to avoid races
216 * if vhold() blocks in the future.
218 * If we are creating a child under an oldapi parent we must mark the
219 * child as being an oldapi entry as well.
222 cache_link_parent(struct namecache *ncp, struct namecache *par)
224 KKASSERT(ncp->nc_parent == NULL);
225 ncp->nc_parent = par;
226 if (TAILQ_EMPTY(&par->nc_list)) {
227 TAILQ_INSERT_HEAD(&par->nc_list, ncp, nc_entry);
229 * Any vp associated with an ncp which has children must
230 * be held to prevent it from being recycled.
235 TAILQ_INSERT_HEAD(&par->nc_list, ncp, nc_entry);
240 * Remove the parent association from a namecache structure.
243 cache_unlink_parent(struct namecache *ncp)
245 struct namecache *par;
247 if ((par = ncp->nc_parent) != NULL) {
248 ncp->nc_parent = NULL;
249 par = cache_hold(par);
250 TAILQ_REMOVE(&par->nc_list, ncp, nc_entry);
251 if (par->nc_vp && TAILQ_EMPTY(&par->nc_list))
258 * Allocate a new namecache structure.
260 static struct namecache *
263 struct namecache *ncp;
265 ncp = malloc(sizeof(*ncp), M_VFSCACHE, M_WAITOK|M_ZERO);
266 ncp->nc_flag = NCF_UNRESOLVED;
267 ncp->nc_error = ENOTCONN; /* needs to be resolved */
269 TAILQ_INIT(&ncp->nc_list);
275 cache_free(struct namecache *ncp)
277 KKASSERT(ncp->nc_refs == 1 && ncp->nc_exlocks == 1);
279 free(ncp->nc_name, M_VFSCACHE);
280 free(ncp, M_VFSCACHE);
284 * Ref and deref a namecache structure.
287 cache_hold(struct namecache *ncp)
289 return(_cache_hold(ncp));
293 cache_drop(struct namecache *ncp)
299 * Namespace locking. The caller must already hold a reference to the
300 * namecache structure in order to lock/unlock it. This function prevents
301 * the namespace from being created or destroyed by accessors other then
304 * Note that holding a locked namecache structure prevents other threads
305 * from making namespace changes (e.g. deleting or creating), prevents
306 * vnode association state changes by other threads, and prevents the
307 * namecache entry from being resolved or unresolved by other threads.
309 * The lock owner has full authority to associate/disassociate vnodes
310 * and resolve/unresolve the locked ncp.
312 * In particular, if a vnode is associated with a locked cache entry
313 * that vnode will *NOT* be recycled. We accomplish this by vhold()ing the
314 * vnode. XXX we should find a more efficient way to prevent the vnode
315 * from being recycled, but remember that any given vnode may have multiple
316 * namecache associations (think hardlinks).
319 cache_lock(struct namecache *ncp)
324 KKASSERT(ncp->nc_refs != 0);
329 if (ncp->nc_exlocks == 0) {
333 * The vp associated with a locked ncp must be held
334 * to prevent it from being recycled (which would
335 * cause the ncp to become unresolved).
337 * XXX loop on race for later MPSAFE work.
343 if (ncp->nc_locktd == td) {
347 ncp->nc_flag |= NCF_LOCKREQ;
348 if (tsleep(ncp, 0, "clock", hz) == EWOULDBLOCK) {
351 printf("[diagnostic] cache_lock: blocked on %*.*s\n",
352 ncp->nc_nlen, ncp->nc_nlen,
359 printf("[diagnostic] cache_lock: unblocked %*.*s\n",
360 ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
365 cache_unlock(struct namecache *ncp)
367 thread_t td = curthread;
369 KKASSERT(ncp->nc_refs > 0);
370 KKASSERT(ncp->nc_exlocks > 0);
371 KKASSERT(ncp->nc_locktd == td);
372 if (--ncp->nc_exlocks == 0) {
375 ncp->nc_locktd = NULL;
376 if (ncp->nc_flag & NCF_LOCKREQ) {
377 ncp->nc_flag &= ~NCF_LOCKREQ;
384 * ref-and-lock, unlock-and-deref functions.
387 cache_get(struct namecache *ncp)
395 cache_put(struct namecache *ncp)
402 * Resolve an unresolved ncp by associating a vnode with it. If the
403 * vnode is NULL, a negative cache entry is created.
405 * The ncp should be locked on entry and will remain locked on return.
409 cache_setvp(struct namecache *ncp, struct vnode *vp)
411 KKASSERT(ncp->nc_flag & NCF_UNRESOLVED);
415 * Any vp associated with an ncp which has children must
416 * be held. Any vp associated with a locked ncp must be held.
418 if (!TAILQ_EMPTY(&ncp->nc_list))
420 TAILQ_INSERT_HEAD(&vp->v_namecache, ncp, nc_vnode);
425 * Set auxillary flags
429 ncp->nc_flag |= NCF_ISDIR;
432 ncp->nc_flag |= NCF_ISSYMLINK;
433 /* XXX cache the contents of the symlink */
441 TAILQ_INSERT_TAIL(&ncneglist, ncp, nc_vnode);
443 ncp->nc_error = ENOENT;
445 ncp->nc_flag &= ~NCF_UNRESOLVED;
449 * Disassociate the vnode or negative-cache association and mark a
450 * namecache entry as unresolved again. Note that the ncp is still
451 * left in the hash table and still linked to its parent.
453 * The ncp should be locked on entry and will remain locked on return.
455 * This routine is normally never called on a directory containing children.
456 * However, NFS often does just that in its rename() code as a cop-out to
457 * avoid complex namespace operations. This disconnects a directory vnode
458 * from its namecache and can cause the OLDAPI and NEWAPI to get out of
462 cache_setunresolved(struct namecache *ncp)
466 struct namecache *kid;
467 struct namecache *nextkid;
470 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0) {
471 ncp->nc_flag |= NCF_UNRESOLVED;
472 ncp->nc_flag &= ~(NCF_WHITEOUT|NCF_ISDIR|NCF_ISSYMLINK);
473 ncp->nc_error = ENOTCONN;
475 if ((vp = ncp->nc_vp) != NULL) {
477 ncp->nc_vp = NULL; /* safety */
478 TAILQ_REMOVE(&vp->v_namecache, ncp, nc_vnode);
481 * Any vp associated with an ncp with children is
482 * held by that ncp. Any vp associated with a locked
483 * ncp is held by that ncp. These conditions must be
484 * undone when the vp is cleared out from the ncp.
486 if (!TAILQ_EMPTY(&ncp->nc_list))
491 TAILQ_REMOVE(&ncneglist, ncp, nc_vnode);
496 if (TAILQ_FIRST(&ncp->nc_list)) {
497 db_print_backtrace();
498 printf("[diagnostic] cache_setunresolved() called on directory with children: %p %*.*s\n", ncp, ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
504 * OLDAPI COMPAT CODE, XXX can be removed when the old api is
507 * Remove any negative hits from the list of children. With
508 * the parent gone there is no namecache<->vnode linkage for
509 * the OLDAPI code to traverse, so the OLDAPI code would not
510 * be able to find the negative cache entry to invalidate it
511 * in cache_enter() if a new file is created. This case
512 * only occurs because NFS calls cache_purge() on the
513 * target directory in nfs_rename().
515 * This is different from what cache_purge() does.
517 if ((nextkid = TAILQ_FIRST(&ncp->nc_list)) != NULL)
519 while ((kid = nextkid) != NULL) {
520 if ((nextkid = TAILQ_NEXT(kid, nc_entry)) != NULL)
522 if ((kid->nc_flag & NCF_UNRESOLVED) == 0 &&
525 cache_setunresolved(kid);
534 * vget the vnode associated with the namecache entry. Resolve the namecache
535 * entry if necessary and deal with namecache/vp races. The passed ncp must
536 * be referenced and may be locked. The ncp's ref/locking state is not
537 * effected by this call.
539 * lk_type may be LK_SHARED, LK_EXCLUSIVE. A ref'd, possibly locked
540 * (depending on the passed lk_type) will be returned in *vpp with an error
541 * of 0, or NULL will be returned in *vpp with a non-0 error code. The
542 * most typical error is ENOENT, meaning that the ncp represents a negative
543 * cache hit and there is no vnode to retrieve, but other errors can occur
546 * The main race we have to deal with are namecache zaps. The ncp itself
547 * will not disappear since it is referenced, and it turns out that the
548 * validity of the vp pointer can be checked simply by rechecking the
549 * contents of ncp->nc_vp.
552 cache_vget(struct namecache *ncp, struct ucred *cred,
553 int lk_type, struct vnode **vpp)
560 if (ncp->nc_flag & NCF_UNRESOLVED) {
562 error = cache_resolve(ncp, cred);
567 if (error == 0 && (vp = ncp->nc_vp) != NULL) {
568 error = vget(vp, NULL, lk_type, curthread);
570 if (vp != ncp->nc_vp) /* handle cache_zap race */
573 } else if (vp != ncp->nc_vp) { /* handle cache_zap race */
578 if (error == 0 && vp == NULL)
585 cache_vref(struct namecache *ncp, struct ucred *cred, struct vnode **vpp)
592 if (ncp->nc_flag & NCF_UNRESOLVED) {
594 error = cache_resolve(ncp, cred);
599 if (error == 0 && (vp = ncp->nc_vp) != NULL) {
601 if (vp != ncp->nc_vp) { /* handle cache_zap race */
606 if (error == 0 && vp == NULL)
613 * Try to destroy a namecache entry. The entry is disassociated from its
614 * vnode or ncneglist and reverted to an UNRESOLVED state.
616 * Then, if there are no additional references to the ncp and we can
617 * successfully delete the children, the entry is also removed from the
618 * namecache hashlist / topology.
620 * References or undeletable children will prevent the entry from being
621 * removed from the topology. The entry may be revalidated (typically
622 * by cache_enter()) at a later time. Children remain because:
624 * + we have tried to delete a node rather then a leaf in the topology.
625 * + the presence of negative entries (we try to scrap these).
626 * + an entry or child has a non-zero ref count and cannot be scrapped.
628 * This function must be called with the ncp held and will drop the ref
629 * count during zapping.
632 cache_zap(struct namecache *ncp)
634 struct namecache *par;
637 * Disassociate the vnode or negative cache ref and set NCF_UNRESOLVED.
639 cache_setunresolved(ncp);
642 * Try to scrap the entry and possibly tail-recurse on its parent.
643 * We only scrap unref'd (other then our ref) unresolved entries,
644 * we do not scrap 'live' entries.
646 while (ncp->nc_flag & NCF_UNRESOLVED) {
648 * Someone other then us has a ref, stop.
650 if (ncp->nc_refs > 1)
654 * We have children, stop.
656 if (!TAILQ_EMPTY(&ncp->nc_list))
659 if (ncp->nc_flag & NCF_HASHED) {
660 ncp->nc_flag &= ~NCF_HASHED;
661 LIST_REMOVE(ncp, nc_hash);
665 * Unlink from its parent and free, then loop on the
666 * parent. XXX temp hack, in stage-3 parent is never NULL
668 if ((par = ncp->nc_parent) != NULL) {
669 par = cache_hold(par);
670 TAILQ_REMOVE(&par->nc_list, ncp, nc_entry);
671 if (par->nc_vp && TAILQ_EMPTY(&par->nc_list))
673 /* keep ref on par */
676 ncp->nc_refs = -1; /* safety */
677 ncp->nc_parent = NULL; /* safety */
679 free(ncp->nc_name, M_VFSCACHE);
680 free(ncp, M_VFSCACHE);
681 if ((ncp = par) == NULL)
689 * NEW NAMECACHE LOOKUP API
691 * Lookup an entry in the cache. A locked, referenced, non-NULL
692 * entry is *always* returned, even if the supplied component is illegal.
693 * The returned namecache entry should be returned to the system with
694 * cache_put() or cache_unlock() + cache_drop().
696 * namecache locks are recursive but care must be taken to avoid lock order
699 * Nobody else will be able to manipulate the associated namespace (e.g.
700 * create, delete, rename, rename-target) until the caller unlocks the
703 * The returned entry will be in one of three states: positive hit (non-null
704 * vnode), negative hit (null vnode), or unresolved (NCF_UNRESOLVED is set).
705 * Unresolved entries must be resolved through the filesystem to associate the
706 * vnode and/or determine whether a positive or negative hit has occured.
708 * It is not necessary to lock a directory in order to lock namespace under
709 * that directory. In fact, it is explicitly not allowed to do that. A
710 * directory is typically only locked when being created, renamed, or
713 * The directory (par) may be unresolved, in which case any returned child
714 * will likely also be marked unresolved. Likely but not guarenteed. Since
715 * the filesystem VOP_NEWLOOKUP() requires a resolved directory vnode the
716 * caller is responsible for resolving the namecache chain top-down. This API
717 * specifically allows whole chains to be created in an unresolved state.
720 cache_nlookup(struct namecache *par, struct nlcomponent *nlc)
722 struct namecache *ncp;
723 struct namecache *new_ncp;
724 struct nchashhead *nchpp;
732 * Try to locate an existing entry
734 hash = fnv_32_buf(nlc->nlc_nameptr, nlc->nlc_namelen, FNV1_32_INIT);
735 hash = fnv_32_buf(&par, sizeof(par), hash);
738 LIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) {
742 * Zap entries that have timed out.
744 if (ncp->nc_timeout &&
745 (int)(ncp->nc_timeout - ticks) < 0
747 cache_zap(cache_hold(ncp));
752 * Break out if we find a matching entry. Note that
753 * UNRESOLVED entries may match.
755 if (ncp->nc_parent == par &&
756 ncp->nc_nlen == nlc->nlc_namelen &&
757 bcmp(ncp->nc_name, nlc->nlc_nameptr, ncp->nc_nlen) == 0
767 * We failed to locate an entry, create a new entry and add it to
768 * the cache. We have to relookup after possibly blocking in
771 if (new_ncp == NULL) {
772 new_ncp = cache_alloc();
773 new_ncp->nc_name = malloc(nlc->nlc_namelen,
774 M_VFSCACHE, M_WAITOK);
781 * Initialize as a new UNRESOLVED entry, lock (non-blocking),
782 * and link to the parent.
784 ncp->nc_nlen = nlc->nlc_namelen;
785 bcopy(nlc->nlc_nameptr, ncp->nc_name, nlc->nlc_namelen);
786 nchpp = NCHHASH(hash);
787 LIST_INSERT_HEAD(nchpp, ncp, nc_hash);
788 ncp->nc_flag |= NCF_HASHED;
789 cache_link_parent(ncp, par);
795 * Resolve an unresolved namecache entry, generally by looking it up.
796 * The passed ncp must be locked.
798 * Theoretically since a vnode cannot be recycled while held, and since
799 * the nc_parent chain holds its vnode as long as children exist, the
800 * direct parent of the cache entry we are trying to resolve should
801 * have a valid vnode. If not then generate an error that we can
802 * determine is related to a resolver bug.
805 cache_resolve(struct namecache *ncp, struct ucred *cred)
807 struct namecache *par;
810 * Mount points need special handling because the parent does not
811 * belong to the same filesystem as the ncp.
813 if (ncp->nc_flag & NCF_MOUNTPT) {
814 return (cache_resolve_mp(ncp));
818 * We expect an unbroken chain of ncps to at least the mount point,
819 * and even all the way to root (but this code doesn't have to go
820 * past the mount point).
822 if (ncp->nc_parent == NULL) {
823 printf("EXDEV case 1 %*.*s\n",
824 ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
825 ncp->nc_error = EXDEV;
826 return(ncp->nc_error);
830 * The vp's of the parent directories in the chain are held via vhold()
831 * due to the existance of the child, and should not disappear.
832 * However, there are cases where they can disappear:
834 * - due to filesystem I/O errors.
835 * - due to NFS being stupid about tracking the namespace and
836 * destroys the namespace for entire directories quite often.
837 * - due to forced unmounts.
839 * When this occurs we have to track the chain backwards and resolve
840 * it, looping until the resolver catches up to the current node. We
841 * could recurse here but we might run ourselves out of kernel stack
842 * so we do it in a more painful manner. This situation really should
843 * not occur all that often, or if it does not have to go back too
844 * many nodes to resolve the ncp.
846 while (ncp->nc_parent->nc_vp == NULL) {
847 par = ncp->nc_parent;
848 while (par->nc_parent && par->nc_parent->nc_vp == NULL)
849 par = par->nc_parent;
850 if (par->nc_parent == NULL) {
851 printf("EXDEV case 2 %*.*s\n",
852 par->nc_nlen, par->nc_nlen, par->nc_name);
855 printf("[diagnostic] cache_resolve: had to recurse on %*.*s\n",
856 par->nc_nlen, par->nc_nlen, par->nc_name);
858 * The leaf prevents the parent from going away, but a
859 * separate ref is still required to lock it. Use cache_get()
860 * instead of cache_lock().
863 if (par->nc_flag & NCF_MOUNTPT) {
864 cache_resolve_mp(par);
867 vop_resolve(par->nc_parent->nc_vp->v_ops, par, cred);
871 printf("EXDEV case 3 %*.*s error %d\n",
872 par->nc_nlen, par->nc_nlen, par->nc_name,
874 return(par->nc_error);
877 if (ncp->nc_flag & NCF_MOUNTPT) {
878 cache_resolve_mp(ncp);
881 vop_resolve(ncp->nc_parent->nc_vp->v_ops, ncp, cred);
883 return(ncp->nc_error);
887 * Resolve the ncp associated with a mount point. Such ncp's almost always
888 * remain resolved and this routine is rarely called. NFS MPs tends to force
889 * re-resolution more often due to its mac-truck-smash-the-namecache
890 * method of tracking namespace changes.
892 * The passed ncp must be locked.
895 cache_resolve_mp(struct namecache *ncp)
898 struct mount *mp = ncp->nc_mount;
900 KKASSERT(mp != NULL);
901 if (ncp->nc_flag & NCF_UNRESOLVED) {
902 while (vfs_busy(mp, 0, NULL, curthread))
904 ncp->nc_error = VFS_ROOT(mp, &vp);
905 if (ncp->nc_error == 0) {
906 cache_setvp(ncp, vp);
909 printf("[diagnostic] cache_resolve_mp: failed to resolve mount %p\n", mp);
910 cache_setvp(ncp, NULL);
912 vfs_unbusy(mp, curthread);
914 return(ncp->nc_error);
918 * Lookup an entry in the cache.
920 * XXX OLD API ROUTINE! WHEN ALL VFSs HAVE BEEN CLEANED UP THIS PROCEDURE
923 * Lookup is called with dvp pointing to the directory to search,
924 * cnp pointing to the name of the entry being sought.
926 * If the lookup succeeds, the vnode is returned in *vpp, and a
927 * status of -1 is returned.
929 * If the lookup determines that the name does not exist (negative cacheing),
930 * a status of ENOENT is returned.
932 * If the lookup fails, a status of zero is returned.
934 * Matching UNRESOLVED entries are resolved.
936 * HACKS: we create dummy nodes for parents
939 cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
941 struct namecache *ncp;
942 struct namecache *par;
943 struct namecache *bpar;
945 globaldata_t gd = mycpu;
950 * Obtain the namecache entry associated with dvp. If there is no
951 * entry then assume a miss.
953 if ((par = TAILQ_FIRST(&dvp->v_namecache)) == NULL) {
954 if ((cnp->cn_flags & CNP_MAKEENTRY) == 0) {
959 gd->gd_nchstats->ncs_miss++;
964 * Deal with "." and "..". Note that if the namecache is disjoint,
965 * we won't find a vnode for ".." and we return a miss.
967 if (cnp->cn_nameptr[0] == '.') {
968 if (cnp->cn_namelen == 1) {
971 numposhits++; /* include in total statistics */
974 if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] == '.') {
975 if ((cnp->cn_flags & CNP_MAKEENTRY) == 0) {
980 if (par->nc_parent == NULL ||
981 par->nc_parent->nc_vp == NULL) {
983 gd->gd_nchstats->ncs_miss++;
986 *vpp = par->nc_parent->nc_vp;
988 numposhits++; /* include in total statistics */
994 * Try to locate an existing entry
997 hash = fnv_32_buf(cnp->cn_nameptr, cnp->cn_namelen, FNV1_32_INIT);
999 hash = fnv_32_buf(&bpar, sizeof(bpar), hash);
1001 LIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) {
1005 * Zap entries that have timed out.
1007 if (ncp->nc_timeout &&
1008 (int)(ncp->nc_timeout - ticks) < 0
1010 cache_zap(cache_hold(ncp));
1015 * Break out if we find a matching entry.
1017 if (ncp->nc_parent == par &&
1018 ncp->nc_nlen == cnp->cn_namelen &&
1019 bcmp(ncp->nc_name, cnp->cn_nameptr, ncp->nc_nlen) == 0
1028 * We found an entry but it is unresolved, act the same as if we
1029 * failed to locate the entry. cache_enter() will do the right
1032 if (ncp && (ncp->nc_flag & NCF_UNRESOLVED)) {
1038 * If we failed to locate an entry, return 0 (indicates failure).
1041 if ((cnp->cn_flags & CNP_MAKEENTRY) == 0) {
1046 gd->gd_nchstats->ncs_miss++;
1051 * If we found an entry, but we don't want to have one, we zap it.
1053 if ((cnp->cn_flags & CNP_MAKEENTRY) == 0) {
1055 gd->gd_nchstats->ncs_badhits++;
1061 * If the vnode is not NULL then return the positive match.
1065 gd->gd_nchstats->ncs_goodhits++;
1072 * If the vnode is NULL we found a negative match. If we want to
1073 * create it, purge the negative match and return failure (as if
1074 * we hadn't found a match in the first place).
1076 if (cnp->cn_nameiop == NAMEI_CREATE) {
1078 gd->gd_nchstats->ncs_badhits++;
1086 * We found a "negative" match, ENOENT notifies client of this match.
1087 * The nc_flag field records whether this is a whiteout. Since there
1088 * is no vnode we can use the vnode tailq link field with ncneglist.
1090 TAILQ_REMOVE(&ncneglist, ncp, nc_vnode);
1091 TAILQ_INSERT_TAIL(&ncneglist, ncp, nc_vnode);
1092 gd->gd_nchstats->ncs_neghits++;
1093 if (ncp->nc_flag & NCF_WHITEOUT)
1094 cnp->cn_flags |= CNP_ISWHITEOUT;
1100 * Add an entry to the cache. (OLD API)
1102 * XXX OLD API ROUTINE! WHEN ALL VFSs HAVE BEEN CLEANED UP THIS PROCEDURE
1105 static void cache_rehash(struct namecache *ncp);
1108 cache_enter(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
1110 struct namecache *par;
1111 struct namecache *ncp;
1112 struct namecache *new_ncp;
1113 struct namecache *bpar;
1114 struct nchashhead *nchpp;
1118 * If the directory has no namecache entry we bail. This will result
1119 * in a lot of misses but frankly we don't have much of a choice if
1120 * we want to be compatible with the new api's storage scheme.
1122 if ((ncp = TAILQ_FIRST(&dvp->v_namecache)) == NULL)
1127 * This may be a bit confusing. "." and ".." are 'virtual' entries.
1128 * We do not actually create a namecache entry representing either.
1129 * However, the ".." case is used to linkup a potentially disjoint
1130 * directory with its parent, to disconnect a directory from its
1131 * parent, or to change an existing linkage that may no longer be
1132 * correct (as might occur when a subdirectory is renamed).
1135 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
1139 if (cnp->cn_namelen == 2 && cnp->cn_nameptr[0] == '.' &&
1140 cnp->cn_nameptr[1] == '.'
1143 * ncp is associated with dvp
1144 * par is not necessarily associated with any vp
1145 * vp represents the new parent directory of dvp (..)
1147 par = ncp->nc_parent; /* old parent of ncp/dvp */
1150 cache_unlink_parent(ncp);
1151 printf("[diagnostic] cache_enter: disconnecting1 %*.*s\n", ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
1153 } else if (par == NULL || par->nc_vp != vp) {
1154 cache_unlink_parent(ncp);
1155 if ((par = TAILQ_FIRST(&vp->v_namecache)) == NULL) {
1156 printf("[diagnostic] cache_enter: disconnecting2 %*.*s\n", ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
1159 * par/vp is the new parent of ncp.
1162 cache_link_parent(ncp, par);
1163 printf("[diagnostic] cache_enter: moving %*.*s\n", ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
1164 if (ncp->nc_flag & NCF_HASHED)
1174 * Ok, no special cases, ncp is actually the parent directory so
1175 * assign it to par. Note that it is held.
1181 * Locate other entries associated with this vnode and zap them,
1182 * because the purge code may not be able to find them due to
1183 * the topology not yet being consistent. This is a hack (this
1184 * whole routine is a hack, actually, so that makes this a hack
1189 TAILQ_FOREACH(ncp, &vp->v_namecache, nc_vnode) {
1190 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0 &&
1191 ncp->nc_parent != par) {
1192 cache_zap(cache_hold(ncp));
1200 * Try to find a match in the hash table, allocate a new entry if
1201 * we can't. We have to retry the loop after any potential blocking
1205 hash = fnv_32_buf(cnp->cn_nameptr, cnp->cn_namelen, FNV1_32_INIT);
1206 hash = fnv_32_buf(&bpar, sizeof(bpar), hash);
1210 LIST_FOREACH(ncp, (NCHHASH(hash)), nc_hash) {
1214 * Break out if we find a matching entry.
1216 if (ncp->nc_parent == par &&
1217 ncp->nc_nlen == cnp->cn_namelen &&
1218 bcmp(ncp->nc_name, cnp->cn_nameptr, ncp->nc_nlen) == 0
1225 if (new_ncp == NULL) {
1226 new_ncp = cache_alloc();
1227 new_ncp->nc_name = malloc(cnp->cn_namelen,
1228 M_VFSCACHE, M_WAITOK);
1232 ncp->nc_nlen = cnp->cn_namelen;
1233 bcopy(cnp->cn_nameptr, ncp->nc_name, cnp->cn_namelen);
1234 nchpp = NCHHASH(hash);
1235 LIST_INSERT_HEAD(nchpp, ncp, nc_hash);
1236 ncp->nc_flag |= NCF_HASHED;
1237 cache_link_parent(ncp, par);
1238 } else if (new_ncp) {
1239 cache_free(new_ncp);
1244 * Avoid side effects if we are simply re-entering the same
1247 if ((ncp->nc_flag & NCF_UNRESOLVED) == 0 && ncp->nc_vp == vp) {
1248 ncp->nc_error = vp ? 0 : ENOENT;
1250 cache_setunresolved(ncp);
1251 cache_setvp(ncp, vp);
1257 if (cnp->cn_flags & CNP_CACHETIMEOUT) {
1258 if ((ncp->nc_timeout = ticks + cnp->cn_timeout) == 0)
1259 ncp->nc_timeout = 1;
1263 * If the target vnode is NULL if this is to be a negative cache
1267 ncp->nc_flag &= ~NCF_WHITEOUT;
1268 if (cnp->cn_flags & CNP_ISWHITEOUT)
1269 ncp->nc_flag |= NCF_WHITEOUT;
1274 * Don't cache too many negative hits
1276 if (numneg > MINNEG && numneg * ncnegfactor > numcache) {
1277 ncp = TAILQ_FIRST(&ncneglist);
1278 KKASSERT(ncp != NULL);
1279 cache_zap(cache_hold(ncp));
1284 cache_rehash(struct namecache *ncp)
1286 struct nchashhead *nchpp;
1289 if (ncp->nc_flag & NCF_HASHED) {
1290 ncp->nc_flag &= ~NCF_HASHED;
1291 LIST_REMOVE(ncp, nc_hash);
1293 hash = fnv_32_buf(ncp->nc_name, ncp->nc_nlen, FNV1_32_INIT);
1294 hash = fnv_32_buf(&ncp->nc_parent, sizeof(ncp->nc_parent), hash);
1295 nchpp = NCHHASH(hash);
1296 LIST_INSERT_HEAD(nchpp, ncp, nc_hash);
1297 ncp->nc_flag |= NCF_HASHED;
1302 * Name cache initialization, from vfsinit() when we are booting
1310 /* initialise per-cpu namecache effectiveness statistics. */
1311 for (i = 0; i < ncpus; ++i) {
1312 gd = globaldata_find(i);
1313 gd->gd_nchstats = &nchstats[i];
1316 TAILQ_INIT(&ncneglist);
1317 nchashtbl = hashinit(desiredvnodes*2, M_VFSCACHE, &nchash);
1321 * Called from start_init() to bootstrap the root filesystem. Returns
1322 * a referenced, unlocked namecache record.
1325 cache_allocroot(struct vnode *vp)
1327 struct namecache *ncp = cache_alloc();
1329 ncp->nc_flag |= NCF_MOUNTPT | NCF_ROOT;
1330 cache_setvp(ncp, vp);
1335 * vfs_cache_setroot()
1337 * Create an association between the root of our namecache and
1338 * the root vnode. This routine may be called several times during
1341 * If the caller intends to save the returned namecache pointer somewhere
1342 * it must cache_hold() it.
1345 vfs_cache_setroot(struct vnode *nvp, struct namecache *ncp)
1348 struct namecache *oncp;
1362 * Invalidate all namecache entries to a particular vnode as well as
1363 * any direct children of that vnode in the namecache. This is a
1364 * 'catch all' purge used by filesystems that do not know any better.
1366 * A new vnode v_id is generated. Note that no vnode will ever have a
1369 * Note that the linkage between the vnode and its namecache entries will
1370 * be removed, but the namecache entries themselves might stay put due to
1371 * active references from elsewhere in the system or due to the existance of
1372 * the children. The namecache topology is left intact even if we do not
1373 * know what the vnode association is. Such entries will be marked
1376 * XXX: Only time and the size of v_id prevents this from failing:
1377 * XXX: In theory we should hunt down all (struct vnode*, v_id)
1378 * XXX: soft references and nuke them, at least on the global
1379 * XXX: v_id wraparound. The period of resistance can be extended
1380 * XXX: by incrementing each vnodes v_id individually instead of
1381 * XXX: using the global v_id.
1384 cache_purge(struct vnode *vp)
1386 static u_long nextid;
1387 struct namecache *ncp;
1388 struct namecache *kid;
1389 struct namecache *nextkid;
1392 * Disassociate the vnode from its namecache entries along with
1393 * (to support NFS) any resolved direct children.
1395 while ((ncp = TAILQ_FIRST(&vp->v_namecache)) != NULL) {
1398 if ((nextkid = TAILQ_FIRST(&ncp->nc_list)) != NULL)
1399 cache_hold(nextkid);
1400 while ((kid = nextkid) != NULL) {
1401 if ((nextkid = TAILQ_NEXT(kid, nc_entry)) != NULL)
1402 cache_hold(nextkid);
1403 if ((kid->nc_flag & NCF_UNRESOLVED) == 0)
1404 cache_setunresolved(kid);
1411 * Calculate a new unique id for ".." handling
1415 } while (nextid == vp->v_id || nextid == 0);
1420 * Flush all entries referencing a particular filesystem.
1422 * Since we need to check it anyway, we will flush all the invalid
1423 * entries at the same time.
1426 cache_purgevfs(struct mount *mp)
1428 struct nchashhead *nchpp;
1429 struct namecache *ncp, *nnp;
1432 * Scan hash tables for applicable entries.
1434 for (nchpp = &nchashtbl[nchash]; nchpp >= nchashtbl; nchpp--) {
1435 ncp = LIST_FIRST(nchpp);
1439 nnp = LIST_NEXT(ncp, nc_hash);
1442 if (ncp->nc_vp && ncp->nc_vp->v_mount == mp)
1454 * Test whether the vnode is at a leaf in the nameicache tree.
1456 * Returns 0 if it is a leaf, -1 if it isn't.
1459 cache_leaf_test(struct vnode *vp)
1461 struct namecache *scan;
1462 struct namecache *ncp;
1464 TAILQ_FOREACH(scan, &vp->v_namecache, nc_vnode) {
1465 TAILQ_FOREACH(ncp, &scan->nc_list, nc_entry) {
1466 /* YYY && ncp->nc_vp->v_type == VDIR ? */
1467 if (ncp->nc_vp != NULL)
1475 * Perform canonical checks and cache lookup and pass on to filesystem
1476 * through the vop_cachedlookup only if needed.
1479 * struct vnode a_dvp;
1480 * struct vnode **a_vpp;
1481 * struct componentname *a_cnp;
1485 vfs_cache_lookup(struct vop_lookup_args *ap)
1487 struct vnode *dvp, *vp;
1490 struct vnode **vpp = ap->a_vpp;
1491 struct componentname *cnp = ap->a_cnp;
1492 struct ucred *cred = cnp->cn_cred;
1493 int flags = cnp->cn_flags;
1494 struct thread *td = cnp->cn_td;
1495 u_long vpid; /* capability number of vnode */
1499 lockparent = flags & CNP_LOCKPARENT;
1501 if (dvp->v_type != VDIR)
1504 if ((flags & CNP_ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
1505 (cnp->cn_nameiop == NAMEI_DELETE || cnp->cn_nameiop == NAMEI_RENAME)) {
1509 error = VOP_ACCESS(dvp, VEXEC, cred, td);
1514 error = cache_lookup(dvp, vpp, cnp);
1517 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
1519 if (error == ENOENT)
1524 cnp->cn_flags &= ~CNP_PDIRUNLOCK;
1525 if (dvp == vp) { /* lookup on "." */
1528 } else if (flags & CNP_ISDOTDOT) {
1529 VOP_UNLOCK(dvp, NULL, 0, td);
1530 cnp->cn_flags |= CNP_PDIRUNLOCK;
1531 error = vget(vp, NULL, LK_EXCLUSIVE, td);
1532 if (!error && lockparent && (flags & CNP_ISLASTCN)) {
1533 if ((error = vn_lock(dvp, NULL, LK_EXCLUSIVE, td)) == 0)
1534 cnp->cn_flags &= ~CNP_PDIRUNLOCK;
1537 error = vget(vp, NULL, LK_EXCLUSIVE, td);
1538 if (!lockparent || error || !(flags & CNP_ISLASTCN)) {
1539 VOP_UNLOCK(dvp, NULL, 0, td);
1540 cnp->cn_flags |= CNP_PDIRUNLOCK;
1544 * Check that the capability number did not change
1545 * while we were waiting for the lock.
1548 if (vpid == vp->v_id)
1551 if (lockparent && dvp != vp && (flags & CNP_ISLASTCN)) {
1552 VOP_UNLOCK(dvp, NULL, 0, td);
1553 cnp->cn_flags |= CNP_PDIRUNLOCK;
1556 if (cnp->cn_flags & CNP_PDIRUNLOCK) {
1557 error = vn_lock(dvp, NULL, LK_EXCLUSIVE, td);
1560 cnp->cn_flags &= ~CNP_PDIRUNLOCK;
1562 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
1565 static int disablecwd;
1566 SYSCTL_INT(_debug, OID_AUTO, disablecwd, CTLFLAG_RW, &disablecwd, 0, "");
1568 static u_long numcwdcalls; STATNODE(CTLFLAG_RD, numcwdcalls, &numcwdcalls);
1569 static u_long numcwdfail1; STATNODE(CTLFLAG_RD, numcwdfail1, &numcwdfail1);
1570 static u_long numcwdfail2; STATNODE(CTLFLAG_RD, numcwdfail2, &numcwdfail2);
1571 static u_long numcwdfail3; STATNODE(CTLFLAG_RD, numcwdfail3, &numcwdfail3);
1572 static u_long numcwdfail4; STATNODE(CTLFLAG_RD, numcwdfail4, &numcwdfail4);
1573 static u_long numcwdfound; STATNODE(CTLFLAG_RD, numcwdfound, &numcwdfound);
1576 __getcwd(struct __getcwd_args *uap)
1586 buflen = uap->buflen;
1589 if (buflen > MAXPATHLEN)
1590 buflen = MAXPATHLEN;
1592 buf = malloc(buflen, M_TEMP, M_WAITOK);
1593 bp = kern_getcwd(buf, buflen, &error);
1595 error = copyout(bp, uap->buf, strlen(bp) + 1);
1601 kern_getcwd(char *buf, size_t buflen, int *error)
1603 struct proc *p = curproc;
1605 int i, slash_prefixed;
1606 struct filedesc *fdp;
1607 struct namecache *ncp;
1616 for (vp = fdp->fd_cdir; vp != fdp->fd_rdir && vp != rootvnode;) {
1617 if (vp->v_flag & VROOT) {
1618 if (vp->v_mount == NULL) { /* forced unmount */
1622 vp = vp->v_mount->mnt_vnodecovered;
1625 TAILQ_FOREACH(ncp, &vp->v_namecache, nc_vnode) {
1626 if (ncp->nc_parent && ncp->nc_parent->nc_vp &&
1636 for (i = ncp->nc_nlen - 1; i >= 0; i--) {
1642 *--bp = ncp->nc_name[i];
1651 vp = ncp->nc_parent->nc_vp;
1653 if (!slash_prefixed) {
1667 * Thus begins the fullpath magic.
1671 #define STATNODE(name) \
1672 static u_int name; \
1673 SYSCTL_UINT(_vfs_cache, OID_AUTO, name, CTLFLAG_RD, &name, 0, "")
1675 static int disablefullpath;
1676 SYSCTL_INT(_debug, OID_AUTO, disablefullpath, CTLFLAG_RW,
1677 &disablefullpath, 0, "");
1679 STATNODE(numfullpathcalls);
1680 STATNODE(numfullpathfail1);
1681 STATNODE(numfullpathfail2);
1682 STATNODE(numfullpathfail3);
1683 STATNODE(numfullpathfail4);
1684 STATNODE(numfullpathfound);
1687 vn_fullpath(struct proc *p, struct vnode *vn, char **retbuf, char **freebuf)
1690 int i, slash_prefixed;
1691 struct filedesc *fdp;
1692 struct namecache *ncp;
1696 if (disablefullpath)
1702 /* vn is NULL, client wants us to use p->p_textvp */
1704 if ((vn = p->p_textvp) == NULL)
1708 buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
1709 bp = buf + MAXPATHLEN - 1;
1713 for (vp = vn; vp != fdp->fd_rdir && vp != rootvnode;) {
1714 if (vp->v_flag & VROOT) {
1715 if (vp->v_mount == NULL) { /* forced unmount */
1719 vp = vp->v_mount->mnt_vnodecovered;
1722 TAILQ_FOREACH(ncp, &vp->v_namecache, nc_vnode) {
1723 if (ncp->nc_parent && ncp->nc_parent->nc_vp &&
1733 for (i = ncp->nc_nlen - 1; i >= 0; i--) {
1739 *--bp = ncp->nc_name[i];
1748 vp = ncp->nc_parent->nc_vp;
1750 if (!slash_prefixed) {