35 #include <sys/cdefs.h>
38 #include "opt_kdtrace.h"
39 #include "opt_ktrace.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/filedesc.h>
44 #include <sys/fnv_hash.h>
45 #include <sys/kernel.h>
47 #include <sys/malloc.h>
48 #include <sys/fcntl.h>
49 #include <sys/mount.h>
50 #include <sys/namei.h>
52 #include <sys/rwlock.h>
54 #include <sys/syscallsubr.h>
55 #include <sys/sysctl.h>
56 #include <sys/sysproto.h>
57 #include <sys/vnode.h>
59 #include <sys/ktrace.h>
71 "char *",
"struct vnode *");
74 "struct vnode *",
"char *");
78 "struct vnode *",
"char *");
117 struct vnode *nc_dvp;
121 struct timespec nc_time;
122 struct timespec nc_dotdottime;
130 #define NCF_WHITE 0x01
131 #define NCF_ISDOTDOT 0x02
155 #define NCHHASH(hash) \
156 (&nchashtbl[(hash) & nchash])
159 static u_long nchash;
160 SYSCTL_ULONG(_debug, OID_AUTO, nchash, CTLFLAG_RD, &nchash, 0,
162 static u_long ncnegfactor = 16;
163 SYSCTL_ULONG(_vfs, OID_AUTO, ncnegfactor, CTLFLAG_RW, &ncnegfactor, 0,
165 static u_long numneg;
166 SYSCTL_ULONG(_debug, OID_AUTO, numneg, CTLFLAG_RD, &numneg, 0,
167 "Number of negative entries in
namecache");
168 static u_long numcache;
169 SYSCTL_ULONG(_debug, OID_AUTO, numcache, CTLFLAG_RD, &numcache, 0,
170 "Number of namecache entries");
171 static u_long numcachehv;
172 SYSCTL_ULONG(_debug, OID_AUTO, numcachehv, CTLFLAG_RD, &numcachehv, 0,
173 "Number of namecache entries with vnodes held");
174 static u_int ncsizefactor = 2;
175 SYSCTL_UINT(_vfs, OID_AUTO, ncsizefactor, CTLFLAG_RW, &ncsizefactor, 0,
176 "Size factor for namecache");
178 struct nchstats nchstats;
180 static struct rwlock cache_lock;
181 RW_SYSINIT(vfscache, &cache_lock, "Name Cache");
183 #define CACHE_UPGRADE_LOCK() rw_try_upgrade(&cache_lock)
184 #define CACHE_RLOCK() rw_rlock(&cache_lock)
185 #define CACHE_RUNLOCK() rw_runlock(&cache_lock)
186 #define CACHE_WLOCK() rw_wlock(&cache_lock)
187 #define CACHE_WUNLOCK() rw_wunlock(&cache_lock)
196 static uma_zone_t cache_zone_small;
197 static uma_zone_t cache_zone_small_ts;
198 static uma_zone_t cache_zone_large;
199 static uma_zone_t cache_zone_large_ts;
201 #define CACHE_PATH_CUTOFF 35
203 static struct namecache *
204 cache_alloc(
int len,
int ts)
209 return (uma_zalloc(cache_zone_large_ts, M_WAITOK));
211 return (uma_zalloc(cache_zone_large, M_WAITOK));
214 return (uma_zalloc(cache_zone_small_ts, M_WAITOK));
216 return (uma_zalloc(cache_zone_small, M_WAITOK));
226 ts = ncp->nc_flag &
NCF_TS;
229 uma_zfree(cache_zone_small_ts, ncp);
231 uma_zfree(cache_zone_small, ncp);
233 uma_zfree(cache_zone_large_ts, ncp);
235 uma_zfree(cache_zone_large, ncp);
243 if ((ncp->nc_flag &
NCF_TS) == 0)
244 return (ncp->nc_name);
246 return (ncp_ts->nc_name);
253 KASSERT((ncp->nc_flag &
NCF_TS) != 0 ||
254 (tsp == NULL && ticksp == NULL),
264 SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
265 "VFS namecache enabled");
268 SYSCTL_INT(_debug_sizeof, OID_AUTO, namecache, CTLFLAG_RD, SYSCTL_NULL_INT_PTR,
269 sizeof(
struct namecache),
"sizeof(struct namecache)");
274 static SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW, 0,
275 "Name cache statistics");
276 #define STATNODE(mode, name, var, descr) \
277 SYSCTL_ULONG(_vfs_cache, OID_AUTO, name, mode, var, 0, descr);
278 STATNODE(CTLFLAG_RD, numneg, &numneg,
"Number of negative cache entries");
279 STATNODE(CTLFLAG_RD, numcache, &numcache,
"Number of cache entries");
281 "Number of cache lookups");
283 "Number of '.' hits");
285 "Number of '..' hits");
287 "Number of checks in lookup");
289 "Number of cache misses");
291 "Number of cache misses we do not want to cache");
293 "Number of cache hits (positive) we do not want to cache");
295 "Number of cache hits (positive)");
297 "Number of cache hits (negative) we do not want to cache");
299 "Number of cache hits (negative)");
301 "Number of updates of the cache after lookup (write lock + retry)");
303 SYSCTL_OPAQUE(_vfs_cache, OID_AUTO, nchstats, CTLFLAG_RD | CTLFLAG_MPSAFE,
304 &nchstats,
sizeof(nchstats),
"LU",
305 "VFS cache effectiveness statistics");
309 static void cache_zap(
struct namecache *ncp);
312 static int vn_fullpath1(
struct thread *td,
struct vnode *vp,
struct vnode *rdir,
313 char *
buf,
char **retbuf, u_int buflen);
315 static MALLOC_DEFINE(M_VFSCACHE,
"vfscache",
"VFS name cache entries");
321 static SYSCTL_NODE(_debug, OID_AUTO, hashstat, CTLFLAG_RW, NULL,
325 sysctl_debug_hashstat_rawnchash(SYSCTL_HANDLER_ARGS)
328 struct nchashhead *ncpp;
329 struct namecache *ncp;
333 n_nchash = nchash + 1;
335 return SYSCTL_OUT(req, 0, n_nchash *
sizeof(
int));
338 for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
341 LIST_FOREACH(ncp, ncpp, nc_hash) {
345 error = SYSCTL_OUT(req, &count,
sizeof(count));
351 SYSCTL_PROC(_debug_hashstat, OID_AUTO, rawnchash, CTLTYPE_INT|CTLFLAG_RD|
352 CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_rawnchash,
"S,int",
353 "nchash chain lengths");
356 sysctl_debug_hashstat_nchash(SYSCTL_HANDLER_ARGS)
359 struct nchashhead *ncpp;
360 struct namecache *ncp;
362 int count, maxlength, used, pct;
365 return SYSCTL_OUT(req, 0, 4 *
sizeof(
int));
367 n_nchash = nchash + 1;
372 for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
375 LIST_FOREACH(ncp, ncpp, nc_hash) {
381 if (maxlength < count)
384 n_nchash = nchash + 1;
385 pct = (used * 100 * 100) / n_nchash;
386 error = SYSCTL_OUT(req, &n_nchash,
sizeof(n_nchash));
389 error = SYSCTL_OUT(req, &used,
sizeof(used));
392 error = SYSCTL_OUT(req, &maxlength,
sizeof(maxlength));
395 error = SYSCTL_OUT(req, &pct,
sizeof(pct));
400 SYSCTL_PROC(_debug_hashstat, OID_AUTO, nchash, CTLTYPE_INT|CTLFLAG_RD|
401 CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_nchash,
"I",
402 "nchash chain lengths");
413 struct namecache *ncp;
417 rw_assert(&cache_lock, RA_WLOCKED);
418 CTR2(KTR_VFS,
"cache_zap(%p) vp %p", ncp, ncp->nc_vp);
420 if (ncp->nc_vp != NULL) {
421 SDT_PROBE3(vfs, namecache, zap, done, ncp->nc_dvp,
424 SDT_PROBE2(vfs, namecache, zap_negative, done, ncp->nc_dvp,
429 LIST_REMOVE(ncp, nc_hash);
431 if (ncp == ncp->nc_dvp->v_cache_dd)
432 ncp->nc_dvp->v_cache_dd = NULL;
434 LIST_REMOVE(ncp, nc_src);
435 if (LIST_EMPTY(&ncp->nc_dvp->v_cache_src)) {
441 TAILQ_REMOVE(&ncp->nc_vp->v_cache_dst, ncp, nc_dst);
442 if (ncp == ncp->nc_vp->v_cache_dd)
443 ncp->nc_vp->v_cache_dd = NULL;
445 TAILQ_REMOVE(&ncneg, ncp, nc_dst);
475 struct componentname *cnp;
476 struct timespec *tsp;
479 struct namecache *ncp;
481 int error, ltype, wlocked;
484 cnp->cn_flags &= ~MAKEENTRY;
494 if (cnp->cn_nameptr[0] ==
'.') {
495 if (cnp->cn_namelen == 1) {
497 CTR2(KTR_VFS,
"cache_lookup(%p, %s) found via .",
498 dvp, cnp->cn_nameptr);
500 SDT_PROBE3(vfs, namecache,
lookup, hit, dvp,
".", *vpp);
507 if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] ==
'.') {
509 if (dvp->v_cache_dd == NULL) {
510 SDT_PROBE3(vfs, namecache,
lookup, miss, dvp,
514 if ((cnp->cn_flags & MAKEENTRY) == 0) {
519 dvp->v_cache_dd = NULL;
523 ncp = dvp->v_cache_dd;
530 goto negative_success;
531 CTR3(KTR_VFS,
"cache_lookup(%p, %s) found %p via ..",
532 dvp, cnp->cn_nameptr, *vpp);
533 SDT_PROBE3(vfs, namecache,
lookup, hit, dvp,
"..",
544 hash = fnv_32_buf(cnp->cn_nameptr, cnp->cn_namelen, FNV1_32_INIT);
545 hash = fnv_32_buf(&dvp,
sizeof(dvp), hash);
546 LIST_FOREACH(ncp, (
NCHHASH(hash)), nc_hash) {
548 if (ncp->nc_dvp == dvp && ncp->nc_nlen == cnp->cn_namelen &&
549 !bcmp(
nc_get_name(ncp), cnp->cn_nameptr, ncp->nc_nlen))
555 SDT_PROBE3(vfs, namecache,
lookup, miss, dvp, cnp->cn_nameptr,
557 if ((cnp->cn_flags & MAKEENTRY) == 0) {
567 if ((cnp->cn_flags & MAKEENTRY) == 0) {
569 nchstats.ncs_badhits++;
580 nchstats.ncs_goodhits++;
582 CTR4(KTR_VFS,
"cache_lookup(%p, %s) found %p via ncp %p",
583 dvp, cnp->cn_nameptr, *vpp, ncp);
592 if (cnp->cn_nameiop == CREATE) {
594 nchstats.ncs_badhits++;
611 TAILQ_REMOVE(&ncneg, ncp, nc_dst);
612 TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst);
613 nchstats.ncs_neghits++;
615 cnp->cn_flags |= ISWHITEOUT;
616 SDT_PROBE2(vfs, namecache,
lookup, hit__negative, dvp,
648 ltype = cnp->cn_lkflags & LK_TYPE_MASK;
649 if (ltype != VOP_ISLOCKED(*vpp)) {
650 if (ltype == LK_EXCLUSIVE) {
651 vn_lock(*vpp, LK_UPGRADE | LK_RETRY);
652 if ((*vpp)->v_iflag & VI_DOOMED) {
659 vn_lock(*vpp, LK_DOWNGRADE | LK_RETRY);
664 if (cnp->cn_flags & ISDOTDOT) {
665 ltype = VOP_ISLOCKED(dvp);
673 error =
vget(*vpp, cnp->cn_lkflags | LK_INTERLOCK, cnp->cn_thread);
674 if (cnp->cn_flags & ISDOTDOT) {
675 vn_lock(dvp, ltype | LK_RETRY);
676 if (dvp->v_iflag & VI_DOOMED) {
687 if ((cnp->cn_flags & ISLASTCN) &&
688 (cnp->cn_lkflags & LK_TYPE_MASK) == LK_EXCLUSIVE) {
689 ASSERT_VOP_ELOCKED(*vpp,
"cache_lookup");
708 struct componentname *cnp;
709 struct timespec *tsp;
710 struct timespec *dtsp;
712 struct namecache *ncp, *n2;
714 struct nchashhead *ncpp;
721 CTR3(KTR_VFS,
"cache_enter(%p, %p, %s)", dvp, vp, cnp->cn_nameptr);
722 VNASSERT(vp == NULL || (vp->v_iflag & VI_DOOMED) == 0, vp,
723 (
"cache_enter: Adding a doomed vnode"));
724 VNASSERT(dvp == NULL || (dvp->v_iflag & VI_DOOMED) == 0, dvp,
725 (
"cache_enter: Doomed vnode used as src"));
737 if (cnp->cn_nameptr[0] ==
'.') {
738 if (cnp->cn_namelen == 1)
740 if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] ==
'.') {
747 if ((ncp = dvp->v_cache_dd) != NULL &&
749 KASSERT(ncp->nc_dvp == dvp,
750 (
"wrong isdotdot parent"));
751 if (ncp->nc_vp != NULL) {
752 TAILQ_REMOVE(&ncp->nc_vp->v_cache_dst,
755 TAILQ_REMOVE(&ncneg, ncp, nc_dst);
759 TAILQ_INSERT_HEAD(&vp->v_cache_dst,
762 TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst);
769 dvp->v_cache_dd = NULL;
770 SDT_PROBE3(vfs, namecache, enter, done, dvp,
"..", vp);
783 ncp = cache_alloc(cnp->cn_namelen, tsp != NULL);
790 n3->nc_ticks =
ticks;
793 n3->nc_dotdottime = *dtsp;
797 len = ncp->nc_nlen = cnp->cn_namelen;
798 hash = fnv_32_buf(cnp->cn_nameptr, len, FNV1_32_INIT);
799 strlcpy(
nc_get_name(ncp), cnp->cn_nameptr, len + 1);
800 hash = fnv_32_buf(&dvp,
sizeof(dvp), hash);
809 LIST_FOREACH(n2, ncpp, nc_hash) {
810 if (n2->nc_dvp == dvp &&
811 n2->nc_nlen == cnp->cn_namelen &&
812 !bcmp(
nc_get_name(n2), cnp->cn_nameptr, n2->nc_nlen)) {
814 KASSERT((n2->nc_flag &
NCF_TS) != 0,
839 if (dvp->v_cache_dd != NULL) {
844 KASSERT(vp == NULL || vp->v_type == VDIR,
845 (
"wrong vnode type %p", vp));
846 dvp->v_cache_dd = ncp;
852 if (cnp->cn_flags & ISWHITEOUT)
854 }
else if (vp->v_type == VDIR) {
861 if ((n2 = vp->v_cache_dd) != NULL &&
864 vp->v_cache_dd = ncp;
867 vp->v_cache_dd = NULL;
874 LIST_INSERT_HEAD(ncpp, ncp, nc_hash);
876 if (LIST_EMPTY(&dvp->v_cache_src)) {
880 LIST_INSERT_HEAD(&dvp->v_cache_src, ncp, nc_src);
889 TAILQ_INSERT_HEAD(&vp->v_cache_dst, ncp, nc_dst);
890 SDT_PROBE3(vfs, namecache, enter, done, dvp,
nc_get_name(ncp),
893 TAILQ_INSERT_TAIL(&ncneg, ncp, nc_dst);
894 SDT_PROBE2(vfs, namecache, enter_negative, done, dvp,
897 if (numneg * ncnegfactor > numcache) {
898 ncp = TAILQ_FIRST(&ncneg);
899 KASSERT(ncp->nc_vp == NULL, (
"ncp %p vp %p on ncneg",
919 cache_zone_small = uma_zcreate(
"S VFS Cache",
921 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
922 cache_zone_small_ts = uma_zcreate(
"STS VFS Cache",
924 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
925 cache_zone_large = uma_zcreate(
"L VFS Cache",
926 sizeof(
struct namecache) + NAME_MAX + 1,
927 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
928 cache_zone_large_ts = uma_zcreate(
"LTS VFS Cache",
930 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_ZINIT);
945 CTR1(KTR_VFS,
"cache_purge(%p)", vp);
946 SDT_PROBE1(vfs, namecache, purge, done, vp);
948 while (!LIST_EMPTY(&vp->v_cache_src))
950 while (!TAILQ_EMPTY(&vp->v_cache_dst))
951 cache_zap(TAILQ_FIRST(&vp->v_cache_dst));
952 if (vp->v_cache_dd != NULL) {
954 (
"lost dotdot link"));
957 KASSERT(vp->v_cache_dd == NULL, (
"incomplete purge"));
968 struct namecache *cp, *ncp;
970 CTR1(KTR_VFS,
"cache_purge_negative(%p)", vp);
971 SDT_PROBE1(vfs, namecache, purge_negative, done, vp);
973 LIST_FOREACH_SAFE(cp, &vp->v_cache_src, nc_src, ncp) {
974 if (cp->nc_vp == NULL)
987 struct nchashhead *ncpp;
988 struct namecache *ncp, *nnp;
991 SDT_PROBE1(vfs, namecache, purgevfs, done, mp);
993 for (ncpp = &nchashtbl[nchash]; ncpp >= nchashtbl; ncpp--) {
994 LIST_FOREACH_SAFE(ncp, ncpp, nc_hash, nnp) {
995 if (ncp->nc_dvp->v_mount == mp)
1009 struct vop_lookup_args
1017 struct vnode **vpp = ap->a_vpp;
1018 struct componentname *cnp = ap->a_cnp;
1019 struct ucred *cred = cnp->cn_cred;
1020 int flags = cnp->cn_flags;
1021 struct thread *td = cnp->cn_thread;
1026 if (dvp->v_type != VDIR)
1029 if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
1030 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
1033 error = VOP_ACCESS(dvp, VEXEC, cred, td);
1039 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
1049 SYSCTL_INT(_debug, OID_AUTO, disablecwd, CTLFLAG_RW, &disablecwd, 0,
1050 "Disable the getcwd syscall");
1056 struct __getcwd_args *uap;
1059 return (
kern___getcwd(td, uap->buf, UIO_USERSPACE, uap->buflen));
1066 struct filedesc *fdp;
1067 struct vnode *cdir, *rdir;
1068 int error, vfslocked;
1074 if (buflen > MAXPATHLEN)
1075 buflen = MAXPATHLEN;
1077 tmpbuf =
malloc(buflen, M_TEMP, M_WAITOK);
1078 fdp = td->td_proc->p_fd;
1079 FILEDESC_SLOCK(fdp);
1080 cdir = fdp->fd_cdir;
1082 rdir = fdp->fd_rdir;
1084 FILEDESC_SUNLOCK(fdp);
1085 error =
vn_fullpath1(td, cdir, rdir, tmpbuf, &bp, buflen);
1086 vfslocked = VFS_LOCK_GIANT(rdir->v_mount);
1088 VFS_UNLOCK_GIANT(vfslocked);
1089 vfslocked = VFS_LOCK_GIANT(cdir->v_mount);
1091 VFS_UNLOCK_GIANT(vfslocked);
1094 if (bufseg == UIO_SYSSPACE)
1095 bcopy(bp, buf, strlen(bp) + 1);
1097 error = copyout(bp, buf, strlen(bp) + 1);
1099 if (KTRPOINT(curthread, KTR_NAMEI))
1103 free(tmpbuf, M_TEMP);
1112 #define STATNODE(name, descr) \
1113 static u_int name; \
1114 SYSCTL_UINT(_vfs_cache, OID_AUTO, name, CTLFLAG_RD, &name, 0, descr)
1117 SYSCTL_INT(_debug, OID_AUTO, disablefullpath, CTLFLAG_RW, &disablefullpath, 0,
1118 "Disable the vn_fullpath function");
1121 STATNODE(numfullpathcalls,
"Number of fullpath search calls");
1122 STATNODE(numfullpathfail1,
"Number of fullpath search errors (ENOTDIR)");
1124 "Number of fullpath search errors (VOP_VPTOCNP failures)");
1125 STATNODE(numfullpathfail4,
"Number of fullpath search errors (ENOMEM)");
1126 STATNODE(numfullpathfound,
"Number of successful fullpath calls");
1133 vn_fullpath(
struct thread *td,
struct vnode *vn,
char **retbuf,
char **freebuf)
1136 struct filedesc *fdp;
1138 int error, vfslocked;
1140 if (disablefullpath)
1145 buf =
malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
1146 fdp = td->td_proc->p_fd;
1147 FILEDESC_SLOCK(fdp);
1148 rdir = fdp->fd_rdir;
1150 FILEDESC_SUNLOCK(fdp);
1151 error =
vn_fullpath1(td, vn, rdir, buf, retbuf, MAXPATHLEN);
1152 vfslocked = VFS_LOCK_GIANT(rdir->v_mount);
1154 VFS_UNLOCK_GIANT(vfslocked);
1171 char **retbuf,
char **freebuf)
1176 if (disablefullpath)
1180 buf =
malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
1206 struct namecache *ncp;
1207 int error, vfslocked;
1209 TAILQ_FOREACH(ncp, &((*vp)->v_cache_dst), nc_dst) {
1214 if (*buflen < ncp->nc_nlen) {
1216 vfslocked = VFS_LOCK_GIANT((*vp)->v_mount);
1218 VFS_UNLOCK_GIANT(vfslocked);
1221 SDT_PROBE3(vfs, namecache, fullpath,
return, error,
1225 *buflen -= ncp->nc_nlen;
1226 memcpy(buf + *buflen,
nc_get_name(ncp), ncp->nc_nlen);
1227 SDT_PROBE3(vfs, namecache, fullpath, hit, ncp->nc_dvp,
1233 vfslocked = VFS_LOCK_GIANT(dvp->v_mount);
1235 VFS_UNLOCK_GIANT(vfslocked);
1239 SDT_PROBE1(vfs, namecache, fullpath, miss, vp);
1242 vfslocked = VFS_LOCK_GIANT((*vp)->v_mount);
1243 vn_lock(*vp, LK_SHARED | LK_RETRY);
1244 error = VOP_VPTOCNP(*vp, &dvp, cred, buf, buflen);
1246 VFS_UNLOCK_GIANT(vfslocked);
1249 SDT_PROBE3(vfs, namecache, fullpath,
return, error, vp, NULL);
1255 if (dvp->v_iflag & VI_DOOMED) {
1258 vfslocked = VFS_LOCK_GIANT(dvp->v_mount);
1260 VFS_UNLOCK_GIANT(vfslocked);
1262 SDT_PROBE3(vfs, namecache, fullpath,
return, error, vp, NULL);
1277 char *
buf,
char **retbuf, u_int buflen)
1279 int error, slash_prefixed, vfslocked;
1280 #ifdef KDTRACE_HOOKS
1281 struct vnode *startvp = vp;
1290 SDT_PROBE1(vfs, namecache, fullpath, entry, vp);
1294 if (vp->v_type != VDIR) {
1300 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1302 VFS_UNLOCK_GIANT(vfslocked);
1305 buf[--buflen] =
'/';
1309 if (vp->v_vflag & VV_ROOT) {
1310 if (vp->v_iflag & VI_DOOMED) {
1312 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1314 VFS_UNLOCK_GIANT(vfslocked);
1316 SDT_PROBE3(vfs, namecache, fullpath,
return,
1320 vp1 = vp->v_mount->mnt_vnodecovered;
1323 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1325 VFS_UNLOCK_GIANT(vfslocked);
1330 if (vp->v_type != VDIR) {
1332 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1334 VFS_UNLOCK_GIANT(vfslocked);
1337 SDT_PROBE3(vfs, namecache, fullpath,
return,
1346 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1348 VFS_UNLOCK_GIANT(vfslocked);
1350 SDT_PROBE3(vfs, namecache, fullpath,
return, error,
1354 buf[--buflen] =
'/';
1359 if (!slash_prefixed) {
1362 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1364 VFS_UNLOCK_GIANT(vfslocked);
1366 SDT_PROBE3(vfs, namecache, fullpath,
return, ENOMEM,
1370 buf[--buflen] =
'/';
1374 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1376 VFS_UNLOCK_GIANT(vfslocked);
1378 SDT_PROBE3(vfs, namecache, fullpath,
return, 0, startvp, buf + buflen);
1379 *retbuf = buf + buflen;
1386 struct namecache *ncp;
1389 ASSERT_VOP_LOCKED(vp,
"vn_dir_dd_ino");
1391 TAILQ_FOREACH(ncp, &(vp->v_cache_dst), nc_dst) {
1397 if (
vget(ddvp, LK_INTERLOCK | LK_SHARED | LK_NOWAIT, curthread))
1408 struct namecache *ncp;
1412 TAILQ_FOREACH(ncp, &vp->v_cache_dst, nc_dst)
1419 l = min(ncp->nc_nlen, buflen - 1);
1430 void cache_enter(
struct vnode *dvp,
struct vnode *vp,
1431 struct componentname *cnp);
1432 int cache_lookup(
struct vnode *dvp,
struct vnode **vpp,
1433 struct componentname *cnp);
1436 cache_enter(
struct vnode *dvp,
struct vnode *vp,
struct componentname *cnp)
1443 cache_lookup(
struct vnode *dvp,
struct vnode **vpp,
struct componentname *cnp)
1466 struct nameidata nd;
1469 int error, vfslocked;
1471 VFS_ASSERT_GIANT(vp->v_mount);
1472 ASSERT_VOP_ELOCKED(vp, __func__);
1475 if (disablefullpath)
1487 if (strlen(rpath) >= pathlen) {
1489 error = ENAMETOOLONG;
1498 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | MPSAFE | AUDITVNODE1,
1499 UIO_SYSSPACE, path, td);
1505 vfslocked = NDHASGIANT(&nd);
1506 NDFREE(&nd, NDF_ONLY_PNBUF);
1510 strcpy(path, rpath);
1515 VFS_UNLOCK_GIANT(vfslocked);
#define STATNODE(mode, name, var, descr)
static char * nc_get_name(struct namecache *ncp)
void * hashinit(int elements, struct malloc_type *type, u_long *hashmask)
int vn_fullpath_global(struct thread *td, struct vnode *vn, char **retbuf, char **freebuf)
void NDFREE(struct nameidata *ndp, const u_int flags)
RW_SYSINIT(khelplistlock,&khelp_list_lock,"helper list lock")
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
void cache_purge(struct vnode *vp)
int vfs_cache_lookup(struct vop_lookup_args *ap)
int vn_path_to_global_path(struct thread *td, struct vnode *vp, char *path, u_int pathlen)
int vn_vptocnp(struct vnode **vp, struct ucred *cred, char *buf, u_int *buflen)
int vget(struct vnode *vp, int flags, struct thread *td)
TAILQ_HEAD(note_info_list, note_info)
struct vnode * vn_dir_dd_ino(struct vnode *vp)
int cache_lookup_times(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct timespec *tsp, int *ticksp)
int vn_fullpath(struct thread *td, struct vnode *vn, char **retbuf, char **freebuf)
SDT_PROVIDER_DECLARE(vfs)
int vn_commname(struct vnode *vp, char *buf, u_int buflen)
int sys___getcwd(struct thread *td, struct __getcwd_args *uap)
SYSCTL_UINT(_kern_eventtimer, OID_AUTO, idletick, CTLFLAG_RW,&idletick, 0,"Run periodic events when idle")
void vdrop(struct vnode *vp)
void vref(struct vnode *vp)
static void cache_out_ts(struct namecache *ncp, struct timespec *tsp, int *ticksp)
void vput(struct vnode *vp)
SYSCTL_ULONG(_kern, OID_AUTO, ps_arg_cache_limit, CTLFLAG_RW,&ps_arg_cache_limit, 0,"")
int cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp)
static void nchinit(void *dummy __unused)
static void cache_free(struct namecache *ncp)
static void cache_zap(struct namecache *ncp)
void cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, struct timespec *tsp, struct timespec *dtsp)
void cache_purgevfs(struct mount *mp)
int kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg, u_int buflen)
int namei(struct nameidata *ndp)
#define CACHE_UPGRADE_LOCK()
SYSCTL_OPAQUE(_vfs_cache, OID_AUTO, nchstats, CTLFLAG_RD|CTLFLAG_MPSAFE,&nchstats, sizeof(nchstats),"LU","VFS cache effectiveness statistics")
#define CACHE_PATH_CUTOFF
void cache_enter(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
SYSCTL_PROC(_kern, OID_AUTO, acct_chkfreq, CTLTYPE_INT|CTLFLAG_RW,&acctchkfreq, 0, sysctl_acct_chkfreq,"I","frequency for checking the free space")
SDT_PROBE_DEFINE3(vfs, namecache, enter, done,"struct vnode *","char *","struct vnode *")
void free(void *addr, struct malloc_type *mtp)
static u_long numupgrades
static LIST_HEAD(nchashhead, namecache)
void vhold(struct vnode *vp)
static MALLOC_DEFINE(M_VFSCACHE,"vfscache","VFS name cache entries")
void vrele(struct vnode *vp)
void cache_purge_negative(struct vnode *vp)
SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_SECOND, nchinit, NULL)
static SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW, 0,"Name cache statistics")
SDT_PROBE_DEFINE2(vfs, namecache, enter_negative, done,"struct vnode *","char *")
static int disablefullpath
SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW,&doingcache, 0,"VFS namecache enabled")
static int vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf, u_int buflen)
static int vn_vptocnp_locked(struct vnode **vp, struct ucred *cred, char *buf, u_int *buflen)
int lookup(struct nameidata *ndp)
SDT_PROBE_DEFINE1(vfs, namecache, fullpath, entry,"struct vnode *")