41#include "opt_ktrace.h"
45#include <sys/capsicum.h>
46#include <sys/counter.h>
47#include <sys/filedesc.h>
48#include <sys/fnv_hash.h>
49#include <sys/kernel.h>
52#include <sys/malloc.h>
62#include <sys/syscallsubr.h>
63#include <sys/sysctl.h>
64#include <sys/sysproto.h>
68#include <sys/ktrace.h>
71#include <machine/_inttypes.h>
74#include <sys/capsicum.h>
76#include <security/audit/audit.h>
77#include <security/mac/mac_framework.h>
210static SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
223 "struct namecache *",
"int",
"int");
226 "char *",
"struct vnode *");
229 "struct vnode *",
"char *");
233 "struct vnode *",
"char *");
237 "struct componentname *");
239 "struct componentname *");
267 "the state must fit in a union with a pointer without growing it");
273 struct vnode *nc_dvp;
309#define CACHE_ZONE_ALIGNMENT UMA_ALIGNOF(time_t)
325#define CACHE_PATH_CUTOFF 45
326#define CACHE_LARGE_PAD 6
328#define CACHE_PATH_CUTOFF 41
329#define CACHE_LARGE_PAD 2
332#define CACHE_ZONE_SMALL_SIZE (offsetof(struct namecache, nc_name) + CACHE_PATH_CUTOFF + 1)
333#define CACHE_ZONE_SMALL_TS_SIZE (offsetof(struct namecache_ts, nc_nc) + CACHE_ZONE_SMALL_SIZE)
334#define CACHE_ZONE_LARGE_SIZE (offsetof(struct namecache, nc_name) + NAME_MAX + 1 + CACHE_LARGE_PAD)
335#define CACHE_ZONE_LARGE_TS_SIZE (offsetof(struct namecache_ts, nc_nc) + CACHE_ZONE_LARGE_SIZE)
342#define nc_vp n_un.nu_vp
343#define nc_neg n_un.nu_neg
348#define NCF_WHITE 0x01
349#define NCF_ISDOTDOT 0x02
352#define NCF_DVDROP 0x10
353#define NCF_NEGATIVE 0x20
354#define NCF_INVALID 0x40
374 (
"%s: entry %p already invalid", __func__, ncp));
376 atomic_thread_fence_rel();
385#define cache_ncp_canuse(ncp) ({ \
386 struct namecache *_ncp = (ncp); \
389 atomic_thread_fence_acq(); \
390 _nc_flag = atomic_load_char(&_ncp->nc_flag); \
391 __predict_true((_nc_flag & (NCF_INVALID | NCF_WIP)) == 0); \
397#define cache_fpl_neg_ncp_canuse(ncp) ({ \
398 struct namecache *_ncp = (ncp); \
401 atomic_thread_fence_acq(); \
402 _nc_flag = atomic_load_char(&_ncp->nc_flag); \
403 __predict_true((_nc_flag & (NCF_INVALID | NCF_WIP | NCF_WHITE)) == 0); \
408static SYSCTL_NODE(_vfs_cache, OID_AUTO, param, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
409 "Name cache parameters");
413 "Total namecache capacity");
417 "Size factor for namecache");
421 "Ratio of negative namecache entries");
432 "Negative entry count above which automatic eviction is allowed");
437#define NCHHASH(hash) \
438 (&nchashtbl[(hash) & nchash])
441SYSCTL_ULONG(_debug, OID_AUTO, nchash, CTLFLAG_RD, &nchash, 0,
442 "Size of namecache hash table");
443static u_long __exclusive_cache_line numneg;
444static u_long __exclusive_cache_line numcache;
446struct nchstats nchstats;
449SYSCTL_BOOL(_vfs, OID_AUTO, cache_rename_add, CTLFLAG_RW,
450 &cache_rename_add, 0,
"");
452static u_int __exclusive_cache_line neg_cycle;
455#define numneglists (ncneghash + 1)
458 struct mtx nl_evict_lock;
467static inline struct neglist *
479 return (&ncp->nc_neg);
482#define numbucketlocks (ncbuckethash + 1)
485#define HASH2BUCKETLOCK(hash) \
486 ((struct mtx *)(&bucketlocks[((hash) & ncbuckethash)]))
488#define numvnodelocks (ncvnodehash + 1)
491static inline struct mtx *
504 (tsp == NULL && ticksp == NULL),
517SYSCTL_INT(_debug, OID_AUTO, vfscache, CTLFLAG_RW, &doingcache, 0,
518 "VFS namecache enabled");
523 sizeof(
struct namecache),
"sizeof(struct namecache)");
528static SYSCTL_NODE(_vfs_cache, OID_AUTO, stats, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
529 "Name cache statistics");
531#define STATNODE_ULONG(name, varname, descr) \
532 SYSCTL_ULONG(_vfs_cache_stats, OID_AUTO, name, CTLFLAG_RD, &varname, 0, descr);
533#define STATNODE_COUNTER(name, varname, descr) \
534 static COUNTER_U64_DEFINE_EARLY(varname); \
535 SYSCTL_COUNTER_U64(_vfs_cache_stats, OID_AUTO, name, CTLFLAG_RD, &varname, \
546 "Number of cache hits (positive) we do not want to cache");
549 "Number of cache hits (negative) we do not want to cache");
553STATNODE_COUNTER(fullpathfail1, numfullpathfail1,
"Number of fullpath search errors (ENOTDIR)");
555 "Number of fullpath search errors (VOP_VPTOCNP failures)");
556STATNODE_COUNTER(fullpathfail4, numfullpathfail4,
"Number of fullpath search errors (ENOMEM)");
558STATNODE_COUNTER(symlinktoobig, symlinktoobig,
"Number of times symlink did not fit the cache");
563static SYSCTL_NODE(_vfs_cache, OID_AUTO, debug, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
564 "Name cache debugging");
565#define DEBUGNODE_ULONG(name, varname, descr) \
566 SYSCTL_ULONG(_vfs_cache_debug, OID_AUTO, name, CTLFLAG_RD, &varname, 0, descr);
567#define DEBUGNODE_COUNTER(name, varname, descr) \
568 static COUNTER_U64_DEFINE_EARLY(varname); \
569 SYSCTL_COUNTER_U64(_vfs_cache_debug, OID_AUTO, name, CTLFLAG_RD, &varname, \
572 "Number of successful removals after relocking");
579 "Number of times 3-way vnode locking failed");
583 char **retbuf,
size_t *buflen,
size_t addend);
585 char **retbuf,
size_t *buflen);
587 char **retbuf,
size_t *len,
size_t addend);
596 mtx_assert(vlp, MA_OWNED);
621 VNPASS(LIST_EMPTY(&vp->v_cache_src), vp);
623 counter_u64_add(numcachehv, 1);
635 counter_u64_add(numcachehv, -1);
656 counter_u64_add(symlinktoobig, 1);
657 SDT_PROBE1(vfs,
namecache, symlink, alloc__fail, size);
665 MPASS(
string != NULL);
667 (
"%s: size %zu too big", __func__, size));
677 __assert_unreachable();
686 if (__predict_false(
ts)) {
691 ncp = &ncp_ts->
nc_nc;
737 lnumcache = atomic_fetchadd_long(&numcache, 1) + 1;
739 lnumcache = atomic_load_long(&numcache);
741 if (__predict_false(lnumcache >=
ncsize)) {
742 atomic_subtract_long(&numcache, 1);
743 counter_u64_add(numdrops, 1);
758 atomic_subtract_long(&numcache, 1);
768 if (TAILQ_EMPTY(batch))
770 TAILQ_FOREACH_SAFE(ncp, batch, nc_dst, nnp) {
777 atomic_subtract_long(&numcache, i);
779 SDT_PROBE1(vfs,
namecache, purge, batch, i);
812 vp->v_nchash = fnv_32_buf(&vp,
sizeof(vp), FNV1_32_INIT);
819 return (fnv_32_buf(
name, len, dvp->v_nchash));
826 return (dvp->v_nchash);
833 return (fnv_32_buf(&c, 1, hash));
843static inline struct nchashhead *
852static inline struct mtx *
868 mtx_assert(blp, MA_OWNED);
877 mtx_assert(blp, MA_NOTOWNED);
880#define cache_assert_bucket_locked(x) do { } while (0)
881#define cache_assert_bucket_unlocked(x) do { } while (0)
884#define cache_sort_vnodes(x, y) _cache_sort_vnodes((void **)(x), (void **)(y))
890 MPASS(*p1 != NULL || *p2 != NULL);
942 if (!mtx_trylock(vlp1))
945 if (!mtx_trylock(vlp2)) {
958 MPASS(vlp1 != NULL || vlp2 != NULL);
971 MPASS(vlp1 != NULL || vlp2 != NULL);
982 struct nchstats snap;
984 if (req->oldptr == NULL)
985 return (SYSCTL_OUT(req, 0,
sizeof(snap)));
995 return (SYSCTL_OUT(req, &snap,
sizeof(snap)));
997SYSCTL_PROC(_vfs_cache, OID_AUTO, nchstats, CTLTYPE_OPAQUE | CTLFLAG_RD |
999 "VFS cache effectiveness statistics");
1016 if (error != 0 || req->newptr == NULL)
1021 if (val < 0 || val > 99)
1030 "I",
"Negative entry \% of namecache capacity above which automatic eviction is allowed");
1037 CTLFLAG_RW | CTLFLAG_MPSAFE, NULL,
1038 "hash table stats");
1041sysctl_debug_hashstat_rawnchash(SYSCTL_HANDLER_ARGS)
1043 struct nchashhead *ncpp;
1045 int i, error, n_nchash, *cntbuf;
1048 n_nchash = nchash + 1;
1049 if (req->oldptr == NULL)
1050 return SYSCTL_OUT(req, 0, n_nchash *
sizeof(
int));
1051 cntbuf =
malloc(n_nchash *
sizeof(
int), M_TEMP, M_ZERO | M_WAITOK);
1053 if (n_nchash != nchash + 1) {
1055 free(cntbuf, M_TEMP);
1059 for (ncpp = nchashtbl, i = 0; i < n_nchash; ncpp++, i++)
1060 CK_SLIST_FOREACH(ncp, ncpp, nc_hash)
1063 for (error = 0, i = 0; i < n_nchash; i++)
1064 if ((error = SYSCTL_OUT(req, &cntbuf[i],
sizeof(
int))) != 0)
1066 free(cntbuf, M_TEMP);
1069SYSCTL_PROC(_debug_hashstat, OID_AUTO, rawnchash, CTLTYPE_INT|CTLFLAG_RD|
1070 CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_rawnchash,
"S,int",
1071 "nchash chain lengths");
1074sysctl_debug_hashstat_nchash(SYSCTL_HANDLER_ARGS)
1077 struct nchashhead *ncpp;
1080 int count, maxlength, used, pct;
1083 return SYSCTL_OUT(req, 0, 4 *
sizeof(
int));
1086 n_nchash = nchash + 1;
1091 for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
1093 CK_SLIST_FOREACH(ncp, ncpp, nc_hash) {
1098 if (maxlength <
count)
1101 n_nchash = nchash + 1;
1103 pct = (used * 100) / (n_nchash / 100);
1104 error = SYSCTL_OUT(req, &n_nchash,
sizeof(n_nchash));
1107 error = SYSCTL_OUT(req, &used,
sizeof(used));
1110 error = SYSCTL_OUT(req, &maxlength,
sizeof(maxlength));
1113 error = SYSCTL_OUT(req, &pct,
sizeof(pct));
1118SYSCTL_PROC(_debug_hashstat, OID_AUTO, nchash, CTLTYPE_INT|CTLFLAG_RD|
1119 CTLFLAG_MPSAFE, 0, 0, sysctl_debug_hashstat_nchash,
"I",
1120 "nchash statistics (number of total/used buckets, maximum chain length, usage percentage)");
1139static SYSCTL_NODE(_vfs_cache, OID_AUTO, neg, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
1140 "Name cache negative entry statistics");
1143 "Number of negative cache entries");
1147 "Number of created negative entries");
1151 "Number of evicted negative entries");
1155 &neg_evict_skipped_empty,
1156 "Number of times evicting failed due to lack of entries");
1160 &neg_evict_skipped_missed,
1161 "Number of times evicting failed due to target entry disappearing");
1165 &neg_evict_skipped_contended,
1166 "Number of times evicting failed due to contention");
1169 "Number of cache hits (negative)");
1180 return (SYSCTL_OUT(req, &out,
sizeof(out)));
1184 "Number of hot negative entries");
1195 counter_u64_add(neg_created, 1);
1198#define CACHE_NEG_PROMOTION_THRESH 2
1207 n = atomic_load_char(&ns->
neg_hit);
1211 if (atomic_fcmpset_8(&ns->
neg_hit, &n, n + 1))
1222#define cache_neg_hit_abort(ncp) do { } while (0)
1228 SDT_PROBE2(vfs,
namecache, lookup, hit__negative, ncp->nc_dvp, ncp->
nc_name);
1229 counter_u64_add(numneghits, 1);
1243 mtx_assert(&nl->nl_lock, MA_OWNED);
1245 TAILQ_REMOVE(&nl->nl_list, ncp, nc_dst);
1246 TAILQ_INSERT_TAIL(&nl->nl_hotlist, ncp, nc_dst);
1263 mtx_assert(&nl->nl_lock, MA_OWNED);
1265 TAILQ_REMOVE(&nl->nl_hotlist, ncp, nc_dst);
1266 TAILQ_INSERT_TAIL(&nl->nl_list, ncp, nc_dst);
1269 atomic_store_char(&ns->
neg_hit, 0);
1291 mtx_lock(&nl->nl_lock);
1308 CK_SLIST_FOREACH(ncp, (
NCHHASH(hash)), nc_hash) {
1316 if (__predict_false(ncp == NULL)) {
1323 if (!(ncp->nc_dvp == dvp && ncp->
nc_nlen == cnp->cn_namelen &&
1331 nc_flag = atomic_load_char(&ncp->
nc_flag);
1343 mtx_unlock(&nl->nl_lock);
1347 mtx_unlock(&nl->nl_lock);
1357 mtx_lock(&nl->nl_lock);
1359 mtx_unlock(&nl->nl_lock);
1370 mtx_lock(&nl->nl_lock);
1371 TAILQ_INSERT_TAIL(&nl->nl_list, ncp, nc_dst);
1372 mtx_unlock(&nl->nl_lock);
1373 atomic_add_long(&numneg, 1);
1385 mtx_lock(&nl->nl_lock);
1387 TAILQ_REMOVE(&nl->nl_hotlist, ncp, nc_dst);
1390 TAILQ_REMOVE(&nl->nl_list, ncp, nc_dst);
1392 mtx_unlock(&nl->nl_lock);
1393 atomic_subtract_long(&numneg, 1);
1396static struct neglist *
1402 c = atomic_fetchadd_int(&neg_cycle, 1) + 1;
1404 if (!mtx_trylock(&nl->nl_evict_lock)) {
1405 counter_u64_add(neg_evict_skipped_contended, 1);
1418 mtx_assert(&nl->nl_evict_lock, MA_OWNED);
1419 mtx_assert(&nl->nl_lock, MA_OWNED);
1420 ncp = TAILQ_FIRST(&nl->nl_list);
1425 for (i = 1; i < 4; i++) {
1426 ncp = TAILQ_NEXT(ncp, nc_dst);
1455 mtx_lock(&nl->nl_lock);
1456 ncp = TAILQ_FIRST(&nl->nl_hotlist);
1462 counter_u64_add(neg_evict_skipped_empty, 1);
1463 mtx_unlock(&nl->nl_lock);
1464 mtx_unlock(&nl->nl_evict_lock);
1472 mtx_unlock(&nl->nl_lock);
1473 mtx_unlock(&nl->nl_evict_lock);
1480 CK_SLIST_FOREACH(ncp2, (
NCHHASH(hash)), nc_hash) {
1481 if (ncp2 == ncp && ncp2->nc_dvp == dvp &&
1486 counter_u64_add(neg_evict_skipped_missed, 1);
1492 SDT_PROBE2(vfs,
namecache, evict_negative, done, ncp->nc_dvp,
1495 counter_u64_add(neg_evicted, 1);
1522 if (
ncsize - 1000 < lnumcache)
1524 lnumneg = atomic_load_long(&numneg);
1542 struct nchashhead *ncpp;
1543 struct vnode *dvp, *vp;
1556 CK_SLIST_REMOVE(ncpp, ncp,
namecache, nc_hash);
1559 TAILQ_REMOVE(&vp->v_cache_dst, ncp, nc_dst);
1560 if (ncp == vp->v_cache_dd) {
1561 atomic_store_ptr(&vp->v_cache_dd, NULL);
1568 if (ncp == dvp->v_cache_dd) {
1569 atomic_store_ptr(&dvp->v_cache_dd, NULL);
1572 LIST_REMOVE(ncp, nc_src);
1573 if (LIST_EMPTY(&dvp->v_cache_src)) {
1584 MPASS(ncp->nc_dvp == vp);
1598 struct mtx *pvlp, *vlp1, *vlp2, *to_unlock;
1601 MPASS(vp == ncp->nc_dvp || vp == ncp->nc_vp);
1605 if (*vlpp != NULL) {
1618 if (*vlpp == vlp1 || *vlpp == vlp2) {
1622 if (*vlpp != NULL) {
1631 if (!mtx_trylock(vlp1))
1639 if (to_unlock != NULL)
1640 mtx_unlock(to_unlock);
1647 MPASS(*vlpp == NULL);
1658 struct vnode *dvp,
struct mtx *dvlp,
struct mtx *vlp, uint32_t hash,
1668 CK_SLIST_FOREACH(rncp, (
NCHHASH(hash)), nc_hash) {
1669 if (rncp == ncp && rncp->nc_dvp == dvp &&
1670 rncp->
nc_nlen == cnp->cn_namelen &&
1678 counter_u64_add(zap_bucket_relock_success, 1);
1687static int __noinline
1689 uint32_t hash,
struct mtx *blp)
1691 struct mtx *dvlp, *vlp;
1712static __noinline
int
1717 struct mtx *dvlp, *dvlp2;
1721 if (cnp->cn_namelen == 2 &&
1722 cnp->cn_nameptr[0] ==
'.' && cnp->cn_nameptr[1] ==
'.') {
1727 ncp = dvp->v_cache_dd;
1732 SDT_PROBE2(vfs,
namecache, removecnp, miss, dvp, cnp);
1738 MPASS(dvp->v_cache_dd == NULL);
1744 atomic_store_ptr(&dvp->v_cache_dd, NULL);
1749 SDT_PROBE2(vfs,
namecache, removecnp, hit, dvp, cnp);
1756 if (CK_SLIST_EMPTY(
NCHHASH(hash)))
1761 CK_SLIST_FOREACH(ncp, (
NCHHASH(hash)), nc_hash) {
1762 if (ncp->nc_dvp == dvp && ncp->
nc_nlen == cnp->cn_namelen &&
1773 if (__predict_false(error != 0)) {
1777 counter_u64_add(numposzaps, 1);
1778 SDT_PROBE2(vfs,
namecache, removecnp, hit, dvp, cnp);
1782 counter_u64_add(nummisszap, 1);
1783 SDT_PROBE2(vfs,
namecache, removecnp, miss, dvp, cnp);
1787static int __noinline
1789 struct timespec *tsp,
int *ticksp)
1794 counter_u64_add(dothits, 1);
1795 SDT_PROBE3(vfs,
namecache, lookup, hit, dvp,
".", *vpp);
1805 ltype = cnp->cn_lkflags & LK_TYPE_MASK;
1806 if (ltype != VOP_ISLOCKED(*vpp)) {
1807 if (ltype == LK_EXCLUSIVE) {
1808 vn_lock(*vpp, LK_UPGRADE | LK_RETRY);
1809 if (VN_IS_DOOMED((*vpp))) {
1816 vn_lock(*vpp, LK_DOWNGRADE | LK_RETRY);
1821static int __noinline
1823 struct timespec *tsp,
int *ticksp)
1832 MPASS((cnp->cn_flags & ISDOTDOT) != 0);
1834 if ((cnp->cn_flags & MAKEENTRY) == 0) {
1839 counter_u64_add(dotdothits, 1);
1843 ncp = dvp->v_cache_dd;
1845 SDT_PROBE2(vfs,
namecache, lookup, miss, dvp,
"..");
1857 goto negative_success;
1858 SDT_PROBE3(vfs,
namecache, lookup, hit, dvp,
"..", *vpp);
1862 ncp_ts = __containerof(ncp,
struct namecache_ts, nc_nc);
1867 ltype = VOP_ISLOCKED(dvp);
1872 vn_lock(dvp, ltype | LK_RETRY);
1873 if (VN_IS_DOOMED(dvp)) {
1885 if (__predict_false(cnp->cn_nameiop == CREATE)) {
1886 if (cnp->cn_flags & ISLASTCN) {
1887 counter_u64_add(numnegzaps, 1);
1903 cnp->cn_flags |= ISWHITEOUT;
1945static int __noinline
1947 struct timespec *tsp,
int *ticksp)
1956 MPASS((cnp->cn_flags & ISDOTDOT) == 0);
1957 MPASS((cnp->cn_flags & (MAKEENTRY | NC_KEEPPOSENTRY)) != 0);
1964 CK_SLIST_FOREACH(ncp, (
NCHHASH(hash)), nc_hash) {
1965 if (ncp->nc_dvp == dvp && ncp->
nc_nlen == cnp->cn_namelen &&
1970 if (__predict_false(ncp == NULL)) {
1972 SDT_PROBE2(vfs,
namecache, lookup, miss, dvp, cnp->cn_nameptr);
1973 counter_u64_add(nummiss, 1);
1978 goto negative_success;
1980 counter_u64_add(numposhits, 1);
1997 if (__predict_true(cnp->cn_nameiop == CREATE)) {
1998 if (cnp->cn_flags & ISLASTCN) {
1999 counter_u64_add(numnegzaps, 1);
2001 if (__predict_false(error != 0)) {
2018 cnp->cn_flags |= ISWHITEOUT;
2023cache_lookup(
struct vnode *dvp,
struct vnode **vpp,
struct componentname *cnp,
2024 struct timespec *tsp,
int *ticksp)
2030 bool whiteout, neg_promote;
2033 MPASS((tsp == NULL && ticksp == NULL) || (tsp != NULL && ticksp != NULL));
2036 if (__predict_false(!doingcache)) {
2037 cnp->cn_flags &= ~MAKEENTRY;
2042 if (__predict_false(cnp->cn_nameptr[0] ==
'.')) {
2043 if (cnp->cn_namelen == 1)
2045 if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] ==
'.')
2049 MPASS((cnp->cn_flags & ISDOTDOT) == 0);
2051 if ((cnp->cn_flags & (MAKEENTRY | NC_KEEPPOSENTRY)) == 0) {
2059 CK_SLIST_FOREACH(ncp, (
NCHHASH(hash)), nc_hash) {
2060 if (ncp->nc_dvp == dvp && ncp->
nc_nlen == cnp->cn_namelen &&
2065 if (__predict_false(ncp == NULL)) {
2067 SDT_PROBE2(vfs,
namecache, lookup, miss, dvp, cnp->cn_nameptr);
2068 counter_u64_add(nummiss, 1);
2074 goto negative_success;
2076 counter_u64_add(numposhits, 1);
2088 if (__predict_false(vs == VGET_NONE)) {
2099 if (cnp->cn_nameiop == CREATE) {
2100 if (cnp->cn_flags & ISLASTCN) {
2123 cnp->cn_flags |= ISWHITEOUT;
2140 bzero(cel,
sizeof(*cel));
2147 struct mtx *vlp1, *vlp2;
2149 MPASS(cel->
vlp[0] == NULL);
2150 MPASS(cel->
vlp[1] == NULL);
2151 MPASS(cel->
vlp[2] == NULL);
2153 MPASS(vp != NULL || dvp != NULL);
2171 MPASS(cel->
vlp[0] != NULL || cel->
vlp[1] != NULL);
2173 if (cel->
vlp[0] != NULL)
2174 mtx_unlock(cel->
vlp[0]);
2175 if (cel->
vlp[1] != NULL)
2176 mtx_unlock(cel->
vlp[1]);
2177 if (cel->
vlp[2] != NULL)
2178 mtx_unlock(cel->
vlp[2]);
2189 MPASS(cel->
vlp[2] == NULL);
2195 if (vlp >= cel->
vlp[1]) {
2198 if (mtx_trylock(vlp))
2202 if (vlp < cel->vlp[0]) {
2204 mtx_lock(cel->
vlp[0]);
2205 mtx_lock(cel->
vlp[1]);
2207 if (cel->
vlp[0] != NULL)
2208 mtx_lock(cel->
vlp[0]);
2210 mtx_lock(cel->
vlp[1]);
2224 MPASS(cel->
blp[0] == NULL);
2225 MPASS(cel->
blp[1] == NULL);
2241 if (cel->
blp[0] != NULL)
2242 mtx_unlock(cel->
blp[0]);
2243 mtx_unlock(cel->
blp[1]);
2261 struct mtx *blps[2];
2268 if (vp == NULL || vp->v_type != VDIR)
2270 ncp = atomic_load_consume_ptr(&vp->v_cache_dd);
2273 nc_flag = atomic_load_char(&ncp->
nc_flag);
2276 MPASS(ncp->nc_dvp == vp);
2286 if (ncp == vp->v_cache_dd &&
2304 struct mtx *blps[2];
2311 ncp = atomic_load_consume_ptr(&dvp->v_cache_dd);
2314 nc_flag = atomic_load_char(&ncp->
nc_flag);
2317 MPASS(ncp->nc_dvp == dvp);
2323 if (ncp == dvp->v_cache_dd &&
2344static void __noinline
2346 struct componentname *cnp)
2353 if (atomic_load_ptr(&dvp->v_cache_dd) == NULL)
2355 len = cnp->cn_namelen;
2359 ncp = dvp->v_cache_dd;
2361 KASSERT(ncp->nc_dvp == dvp, (
"wrong isdotdot parent"));
2366 atomic_store_ptr(&dvp->v_cache_dd, NULL);
2377 struct timespec *tsp,
struct timespec *dtsp)
2382 struct nchashhead *ncpp;
2387 KASSERT(cnp->cn_namelen <= NAME_MAX,
2388 (
"%s: passed len %ld exceeds NAME_MAX (%d)", __func__, cnp->cn_namelen,
2390 VNPASS(!VN_IS_DOOMED(dvp), dvp);
2391 VNPASS(dvp->v_type != VNON, dvp);
2393 VNPASS(!VN_IS_DOOMED(vp), vp);
2394 VNPASS(vp->v_type != VNON, vp);
2396 if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] ==
'.') {
2398 (
"%s: different vnodes for dot entry (%p; %p)\n", __func__,
2402 (
"%s: same vnode for non-dot entry [%s] (%p)\n", __func__,
2403 cnp->cn_nameptr, dvp));
2407 if (__predict_false(!doingcache))
2412 if (__predict_false(cnp->cn_nameptr[0] ==
'.')) {
2413 if (cnp->cn_namelen == 1)
2415 if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] ==
'.') {
2439 ncp_ts = __containerof(ncp,
struct namecache_ts, nc_nc);
2448 len = ncp->
nc_nlen = cnp->cn_namelen;
2450 memcpy(ncp->
nc_name, cnp->cn_nameptr, len);
2460 CK_SLIST_FOREACH(n2, ncpp, nc_hash) {
2461 if (n2->nc_dvp == dvp &&
2462 n2->
nc_nlen == cnp->cn_namelen &&
2467 (
"%s: found entry pointing to a different vnode (%p != %p) ; name [%s]",
2468 __func__, NULL, vp, cnp->cn_nameptr));
2470 KASSERT(n2->nc_vp == vp,
2471 (
"%s: found entry pointing to a different vnode (%p != %p) ; name [%s]",
2472 __func__, n2->nc_vp, vp, cnp->cn_nameptr));
2488 n2_ts->nc_time = ncp_ts->
nc_time;
2489 n2_ts->nc_ticks = ncp_ts->
nc_ticks;
2492 n2_ts->nc_nc.nc_flag |=
NCF_DTS;
2498 goto out_unlock_free;
2507 if (dvp->v_cache_dd != NULL)
2508 goto out_unlock_free;
2509 KASSERT(vp == NULL || vp->v_type == VDIR,
2510 (
"wrong vnode type %p", vp));
2511 atomic_thread_fence_rel();
2512 atomic_store_ptr(&dvp->v_cache_dd, ncp);
2522 if ((ndd = vp->v_cache_dd) != NULL) {
2528 atomic_thread_fence_rel();
2529 atomic_store_ptr(&vp->v_cache_dd, ncp);
2530 }
else if (vp->v_type != VDIR) {
2531 if (vp->v_cache_dd != NULL) {
2532 atomic_store_ptr(&vp->v_cache_dd, NULL);
2538 if (LIST_EMPTY(&dvp->v_cache_src)) {
2541 LIST_INSERT_HEAD(&dvp->v_cache_src, ncp, nc_src);
2550 TAILQ_INSERT_HEAD(&vp->v_cache_dst, ncp, nc_dst);
2554 if (cnp->cn_flags & ISWHITEOUT)
2557 SDT_PROBE2(vfs,
namecache, enter_negative, done, dvp,
2565 CK_SLIST_INSERT_HEAD(ncpp, ncp, nc_hash);
2567 atomic_thread_fence_rel();
2598 struct timespec *tsp,
struct timespec *dtsp,
int flags)
2601 MPASS((
flags & ~(VFS_CACHE_DROPOLD)) == 0);
2603 if (
flags & VFS_CACHE_DROPOLD)
2619static struct nchashhead *
2622 struct nchashhead *hashtbl;
2627 hashtbl =
malloc((u_long)hashsize *
sizeof(*hashtbl), M_VFSCACHE, M_WAITOK);
2628 for (i = 0; i < hashsize; i++)
2629 CK_SLIST_INIT(&hashtbl[i]);
2630 *hashmask = hashsize - 1;
2638 free(hashtbl, M_VFSCACHE);
2674 mtx_init(&
bucketlocks[i],
"ncbuc", NULL, MTX_DUPOK | MTX_RECURSE);
2679 mtx_init(&
vnodelocks[i],
"ncvn", NULL, MTX_DUPOK | MTX_RECURSE);
2682 mtx_init(&
neglists[i].nl_evict_lock,
"ncnege", NULL, MTX_DEF);
2683 mtx_init(&
neglists[i].nl_lock,
"ncnegl", NULL, MTX_DEF);
2685 TAILQ_INIT(&
neglists[i].nl_hotlist);
2694 LIST_INIT(&vp->v_cache_src);
2695 TAILQ_INIT(&vp->v_cache_dst);
2696 vp->v_cache_dd = NULL;
2713 MPASS(temphash < nchash);
2720 atomic_store_long(&nchash, temphash);
2721 atomic_thread_fence_rel();
2722 vfs_smr_synchronize();
2727 atomic_store_ptr(&nchashtbl, temptbl);
2728 atomic_thread_fence_rel();
2729 vfs_smr_synchronize();
2745 MPASS(nchash < new_hash);
2750 atomic_store_ptr(&nchashtbl, new_tbl);
2751 atomic_thread_fence_rel();
2752 vfs_smr_synchronize();
2757 atomic_store_long(&nchash, new_hash);
2758 atomic_thread_fence_rel();
2759 vfs_smr_synchronize();
2768 struct nchashhead *new_nchashtbl, *old_nchashtbl, *temptbl;
2769 u_long new_nchash, old_nchash, temphash;
2780 new_nchashtbl =
nchinittbl(newmaxvnodes, &new_nchash);
2782 if (nchash == new_nchash) {
2796 old_nchashtbl = nchashtbl;
2797 old_nchash = nchash;
2799 for (i = 0; i <= old_nchash; i++) {
2800 while ((ncp = CK_SLIST_FIRST(&old_nchashtbl[i])) != NULL) {
2803 CK_SLIST_REMOVE(&old_nchashtbl[i], ncp,
namecache, nc_hash);
2804 CK_SLIST_INSERT_HEAD(&new_nchashtbl[hash & new_nchash], ncp, nc_hash);
2822 struct cache_freebatch batch;
2824 struct mtx *vlp, *vlp2;
2831 while (!LIST_EMPTY(&vp->v_cache_src)) {
2832 ncp = LIST_FIRST(&vp->v_cache_src);
2835 TAILQ_INSERT_TAIL(&batch, ncp, nc_dst);
2837 while (!TAILQ_EMPTY(&vp->v_cache_dst)) {
2838 ncp = TAILQ_FIRST(&vp->v_cache_dst);
2841 TAILQ_INSERT_TAIL(&batch, ncp, nc_dst);
2843 ncp = vp->v_cache_dd;
2846 (
"lost dotdot link"));
2849 TAILQ_INSERT_TAIL(&batch, ncp, nc_dst);
2851 KASSERT(vp->v_cache_dd == NULL, (
"incomplete purge"));
2865 if (LIST_EMPTY(&vp->v_cache_src) && TAILQ_EMPTY(&vp->v_cache_dst) &&
2866 atomic_load_ptr(&vp->v_cache_dd) == NULL)
2875 SDT_PROBE1(vfs,
namecache, purge, done, vp);
2889 VNPASS(VN_IS_DOOMED(vp), vp);
2913 struct cache_freebatch batch;
2917 SDT_PROBE1(vfs,
namecache, purge_negative, done, vp);
2918 if (LIST_EMPTY(&vp->v_cache_src))
2923 LIST_FOREACH_SAFE(ncp, &vp->v_cache_src, nc_src, nnp) {
2927 TAILQ_INSERT_TAIL(&batch, ncp, nc_dst);
2938 struct vnode *tvp,
struct componentname *fcnp,
struct componentname *tcnp)
2941 ASSERT_VOP_IN_SEQC(fdvp);
2942 ASSERT_VOP_IN_SEQC(fvp);
2943 ASSERT_VOP_IN_SEQC(tdvp);
2945 ASSERT_VOP_IN_SEQC(tvp);
2951 (
"%s: lingering negative entry", __func__));
2967 if (cache_rename_add) {
2968 cache_enter(tdvp, fvp, tcnp);
2976 ASSERT_VOP_IN_SEQC(dvp);
2977 ASSERT_VOP_IN_SEQC(vp);
2986cache_validate(
struct vnode *dvp,
struct vnode *vp,
struct componentname *cnp)
2993 if (CK_SLIST_EMPTY(
NCHHASH(hash)))
2997 CK_SLIST_FOREACH(ncp, (
NCHHASH(hash)), nc_hash) {
2998 if (ncp->nc_dvp == dvp && ncp->
nc_nlen == cnp->cn_namelen &&
3000 if (ncp->nc_vp != vp)
3001 panic(
"%s: mismatch (%p != %p); ncp %p [%s] dvp %p\n",
3002 __func__, vp, ncp->nc_vp, ncp, ncp->
nc_name, ncp->nc_dvp);
3015 struct vnode *vp, *mvp;
3016 size_t visited, purged;
3018 visited = purged = 0;
3023 MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
3036 SDT_PROBE3(vfs,
namecache, purgevfs, done, mp, visited, purged);
3049 struct vnode **vpp = ap->a_vpp;
3050 struct componentname *cnp = ap->a_cnp;
3051 int flags = cnp->cn_flags;
3056 if (dvp->v_type != VDIR)
3059 if ((
flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
3060 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
3069 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp));
3083 buflen = uap->buflen;
3084 if (__predict_false(buflen < 2))
3086 if (buflen > MAXPATHLEN)
3087 buflen = MAXPATHLEN;
3092 error = copyout(retbuf, uap->buf, buflen);
3104 pwd = pwd_get_smr();
3107 VFS_SMR_ASSERT_NOT_ENTERED();
3116 if (KTRPOINT(curthread, KTR_NAMEI) && error == 0)
3135 size_t size,
int flags,
enum uio_seg pathseg)
3137 struct nameidata nd;
3138 char *retbuf, *freebuf;
3143 NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW | SAVENAME | WANTPARENT | AUDITVNODE1,
3145 if ((error =
namei(&nd)) != 0)
3148 nd.ni_cnd.cn_namelen, &retbuf, &freebuf, &size);
3150 error = copyout(retbuf,
buf, size);
3151 free(freebuf, M_TEMP);
3162 uap->flags, UIO_USERSPACE));
3177 if (__predict_false(vp == NULL))
3180 buflen = MAXPATHLEN;
3183 pwd = pwd_get_smr();
3185 VFS_SMR_ASSERT_NOT_ENTERED();
3211 if (__predict_false(vp == NULL))
3213 buflen = MAXPATHLEN;
3217 VFS_SMR_ASSERT_NOT_ENTERED();
3234 TAILQ_FOREACH(ncp, &vp->v_cache_dst, nc_dst) {
3251 ncp = (*vp)->v_cache_dd;
3254 (
"%s: mismatch for dd entry (%p != %p)", __func__,
3260 if (*buflen < ncp->nc_nlen) {
3263 counter_u64_add(numfullpathfail4, 1);
3265 SDT_PROBE3(vfs,
namecache, fullpath,
return, error,
3271 SDT_PROBE3(vfs,
namecache, fullpath, hit, ncp->nc_dvp,
3280 SDT_PROBE1(vfs,
namecache, fullpath, miss, vp);
3283 vn_lock(*vp, LK_SHARED | LK_RETRY);
3284 error = VOP_VPTOCNP(*vp, &dvp,
buf, buflen);
3287 counter_u64_add(numfullpathfail2, 1);
3288 SDT_PROBE3(vfs,
namecache, fullpath,
return, error, vp, NULL);
3293 if (VN_IS_DOOMED(dvp)) {
3297 SDT_PROBE3(vfs,
namecache, fullpath,
return, error, vp, NULL);
3318 size_t *len,
size_t addend)
3321 struct vnode *startvp = vp;
3326 bool slash_prefixed;
3328 VNPASS(vp->v_type == VDIR || VN_IS_DOOMED(vp), vp);
3329 VNPASS(vp->v_usecount > 0, vp);
3333 slash_prefixed =
true;
3338 slash_prefixed =
false;
3343 SDT_PROBE1(vfs,
namecache, fullpath, entry, vp);
3344 counter_u64_add(numfullpathcalls, 1);
3352 if ((vp->v_vflag & VV_ROOT) != 0) {
3353 vn_lock(vp, LK_RETRY | LK_SHARED);
3363 if (VN_IS_DOOMED(vp) ||
3364 (vp1 = vp->v_mount->mnt_vnodecovered) == NULL ||
3365 vp1->v_mountedhere != vp->v_mount) {
3368 SDT_PROBE3(vfs,
namecache, fullpath,
return,
3378 if (vp->v_type != VDIR) {
3380 counter_u64_add(numfullpathfail1, 1);
3382 SDT_PROBE3(vfs,
namecache, fullpath,
return,
3392 SDT_PROBE3(vfs,
namecache, fullpath,
return, error,
3396 buf[--buflen] =
'/';
3397 slash_prefixed =
true;
3401 if (!slash_prefixed) {
3404 counter_u64_add(numfullpathfail4, 1);
3405 SDT_PROBE3(vfs,
namecache, fullpath,
return, ENOMEM,
3409 buf[--buflen] =
'/';
3411 counter_u64_add(numfullpathfound, 1);
3414 *retbuf =
buf + buflen;
3415 SDT_PROBE3(vfs,
namecache, fullpath,
return, 0, startvp, *retbuf);
3436#define cache_rev_failed(var) cache_rev_failed_impl((var), __LINE__)
3440 char **retbuf,
size_t *buflen,
size_t addend)
3443 struct vnode *startvp = vp;
3454 seqc_t vp_seqc, tvp_seqc;
3457 VFS_SMR_ASSERT_ENTERED();
3464 orig_buflen = *buflen;
3467 MPASS(*buflen >= 2);
3469 buf[*buflen] =
'\0';
3485 vp_seqc = vn_seqc_read_any(vp);
3486 if (seqc_in_modify(vp_seqc)) {
3495 if ((vp->v_vflag & VV_ROOT) != 0) {
3496 mp = atomic_load_ptr(&vp->v_mount);
3501 tvp = atomic_load_ptr(&mp->mnt_vnodecovered);
3502 tvp_seqc = vn_seqc_read_any(tvp);
3503 if (seqc_in_modify(tvp_seqc)) {
3507 if (!vn_seqc_consistent(vp, vp_seqc)) {
3515 ncp = atomic_load_consume_ptr(&vp->v_cache_dd);
3525 if (ncp->
nc_nlen >= *buflen) {
3535 tvp_seqc = vn_seqc_read_any(tvp);
3536 if (seqc_in_modify(tvp_seqc)) {
3540 if (!vn_seqc_consistent(vp, vp_seqc)) {
3547 if (__predict_false(atomic_load_ptr(&vp->v_cache_dd) != ncp)) {
3562 *retbuf =
buf + *buflen;
3563 *buflen = orig_buflen - *buflen + addend;
3564 SDT_PROBE2(vfs,
namecache, fullpath_smr, hit, startvp, *retbuf);
3568 *buflen = orig_buflen;
3569 SDT_PROBE4(vfs,
namecache, fullpath_smr, miss, startvp, ncp, reason, i);
3578 size_t orig_buflen, addend;
3584 orig_buflen = *buflen;
3588 if (vp->v_type != VDIR) {
3590 buf[*buflen] =
'\0';
3600 addend = orig_buflen - *buflen;
3621 const char *hrdl_name,
size_t hrdl_name_length,
3622 char **retbuf,
char **freebuf,
size_t *buflen)
3632 if (*buflen > MAXPATHLEN)
3633 *buflen = MAXPATHLEN;
3635 buf =
malloc(*buflen, M_TEMP, M_WAITOK);
3664 addend = hrdl_name_length + 2;
3665 if (*buflen < addend) {
3670 tmpbuf =
buf + *buflen;
3672 memcpy(&tmpbuf[1], hrdl_name, hrdl_name_length);
3673 tmpbuf[addend - 1] =
'\0';
3678 pwd = pwd_get_smr();
3681 VFS_SMR_ASSERT_NOT_ENTERED();
3708 ASSERT_VOP_LOCKED(vp,
"vn_dir_dd_ino");
3711 TAILQ_FOREACH(ncp, &(vp->v_cache_dst), nc_dst) {
3734 TAILQ_FOREACH(ncp, &vp->v_cache_dst, nc_dst)
3741 l = min(ncp->
nc_nlen, buflen - 1);
3762 struct nameidata nd;
3767 ASSERT_VOP_ELOCKED(vp, __func__);
3778 if (strlen(rpath) >= pathlen) {
3780 error = ENAMETOOLONG;
3789 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_SYSSPACE,
path);
3795 NDFREE(&nd, NDF_ONLY_PNBUF);
3799 strcpy(
path, rpath);
3812db_print_vpath(
struct vnode *vp)
3815 while (vp != NULL) {
3816 db_printf(
"%p: ", vp);
3821 if (vp->v_vflag & VV_ROOT) {
3822 db_printf(
"<mount point>");
3823 vp = vp->v_mount->mnt_vnodecovered;
3829 ncp = TAILQ_FIRST(&vp->v_cache_dst);
3832 for (i = 0; i < ncp->
nc_nlen; i++)
3833 db_printf(
"%c", *ncn++);
3846DB_SHOW_COMMAND(vpath, db_show_vpath)
3851 db_printf(
"usage: show vpath <struct vnode *>\n");
3855 vp = (
struct vnode *)
addr;
3863#define CACHE_FPL_FAILED -2020
3872 mac_on = mac_vnode_check_lookup_enabled();
3873 mac_on |= mac_vnode_check_readlink_enabled();
3879 if (lookup_flag && !mac_on) {
3917struct cache_fpl_debug {
3940 struct cache_fpl_debug debug;
3961 cnp->cn_pnbuf = NULL;
3962 cnp->cn_nameptr = NULL;
3966static struct vnode *
3969 struct nameidata *ndp;
3970 struct componentname *cnp;
3975 MPASS(*(cnp->cn_nameptr) ==
'/');
3979 if (__predict_false(*(cnp->cn_nameptr) ==
'/')) {
3983 }
while (*(cnp->cn_nameptr) ==
'/');
3986 return (ndp->ni_rootdir);
4002 fpl->
snd.cn_nameptr = fpl->
ndp->ni_cnd.cn_nameptr;
4003 fpl->
snd.ni_pathlen = fpl->debug.ni_pathlen;
4013 fpl->debug.ni_pathlen = fpl->
snd.ni_pathlen;
4025 fpl->
ndp->ni_resflags = 0;
4026 fpl->
ndp->ni_cnd.cn_nameptr = fpl->
ndp->ni_cnd.cn_pnbuf;
4031#define cache_fpl_smr_assert_entered(fpl) ({ \
4032 struct cache_fpl *_fpl = (fpl); \
4033 MPASS(_fpl->in_smr == true); \
4034 VFS_SMR_ASSERT_ENTERED(); \
4036#define cache_fpl_smr_assert_not_entered(fpl) ({ \
4037 struct cache_fpl *_fpl = (fpl); \
4038 MPASS(_fpl->in_smr == false); \
4039 VFS_SMR_ASSERT_NOT_ENTERED(); \
4046 case CACHE_FPL_STATUS_UNSET:
4047 __assert_unreachable();
4049 case CACHE_FPL_STATUS_DESTROYED:
4050 case CACHE_FPL_STATUS_ABORTED:
4051 case CACHE_FPL_STATUS_PARTIAL:
4052 case CACHE_FPL_STATUS_HANDLED:
4057#define cache_fpl_smr_assert_entered(fpl) do { } while (0)
4058#define cache_fpl_smr_assert_not_entered(fpl) do { } while (0)
4059#define cache_fpl_assert_status(fpl) do { } while (0)
4062#define cache_fpl_smr_enter_initial(fpl) ({ \
4063 struct cache_fpl *_fpl = (fpl); \
4065 _fpl->in_smr = true; \
4068#define cache_fpl_smr_enter(fpl) ({ \
4069 struct cache_fpl *_fpl = (fpl); \
4070 MPASS(_fpl->in_smr == false); \
4072 _fpl->in_smr = true; \
4075#define cache_fpl_smr_exit(fpl) ({ \
4076 struct cache_fpl *_fpl = (fpl); \
4077 MPASS(_fpl->in_smr == true); \
4079 _fpl->in_smr = false; \
4086 if (fpl->
status != CACHE_FPL_STATUS_UNSET) {
4087 KASSERT(fpl->
status == CACHE_FPL_STATUS_PARTIAL,
4088 (
"%s: converting to abort from %d at %d, set at %d\n",
4092 fpl->
status = CACHE_FPL_STATUS_ABORTED;
4097#define cache_fpl_aborted_early(x) cache_fpl_aborted_early_impl((x), __LINE__)
4099static int __noinline
4102 struct nameidata *ndp;
4103 struct componentname *cnp;
4108 if (fpl->
status != CACHE_FPL_STATUS_UNSET) {
4109 KASSERT(fpl->
status == CACHE_FPL_STATUS_PARTIAL,
4110 (
"%s: converting to abort from %d at %d, set at %d\n",
4113 fpl->
status = CACHE_FPL_STATUS_ABORTED;
4122 if (ndp->ni_loopcnt > 0) {
4123 fpl->
status = CACHE_FPL_STATUS_DESTROYED;
4129#define cache_fpl_aborted(x) cache_fpl_aborted_impl((x), __LINE__)
4131static int __noinline
4135 KASSERT(fpl->
status == CACHE_FPL_STATUS_UNSET,
4136 (
"%s: setting to partial at %d, but already set to %d at %d\n",
4139 fpl->
status = CACHE_FPL_STATUS_PARTIAL;
4144#define cache_fpl_partial(x) cache_fpl_partial_impl((x), __LINE__)
4150 KASSERT(fpl->
status == CACHE_FPL_STATUS_UNSET,
4151 (
"%s: setting to handled at %d, but already set to %d at %d\n",
4154 fpl->
status = CACHE_FPL_STATUS_HANDLED;
4159#define cache_fpl_handled(x) cache_fpl_handled_impl((x), __LINE__)
4165 KASSERT(fpl->
status == CACHE_FPL_STATUS_UNSET,
4166 (
"%s: setting to handled at %d, but already set to %d at %d\n",
4171 fpl->
status = CACHE_FPL_STATUS_HANDLED;
4179#define cache_fpl_handled_error(x, e) cache_fpl_handled_error_impl((x), (e), __LINE__)
4185 return (fpl->
status != CACHE_FPL_STATUS_UNSET);
4188#define CACHE_FPL_SUPPORTED_CN_FLAGS \
4189 (NC_NOMAKEENTRY | NC_KEEPPOSENTRY | LOCKLEAF | LOCKPARENT | WANTPARENT | \
4190 FAILIFEXISTS | FOLLOW | EMPTYPATH | LOCKSHARED | SAVENAME | SAVESTART | \
4191 WILLBEDIR | ISOPEN | NOMACCHECK | AUDITVNODE1 | AUDITVNODE2 | NOCAPCHECK | \
4192 OPENREAD | OPENWRITE)
4194#define CACHE_FPL_INTERNAL_CN_FLAGS \
4195 (ISDOTDOT | MAKEENTRY | ISLASTCN)
4198 "supported and internal flags overlap");
4204 return (*ndp->ni_next == 0);
4212 return (*(fpl->
nulchar - 1) ==
'/');
4219 if (cnp->cn_namelen == 2 &&
4220 cnp->cn_nameptr[1] ==
'.' && cnp->cn_nameptr[0] ==
'.')
4228 struct nameidata *ndp;
4229 struct componentname *cnp;
4244 if (IN_CAPABILITY_MODE(td)) {
4248 if (AUDITING_TD(td)) {
4252 if (ndp->ni_startdir != NULL) {
4259static int __noinline
4262 struct nameidata *ndp;
4263 struct componentname *cnp;
4271 if (__predict_false(error != 0)) {
4275 if ((*vpp)->v_type != VDIR) {
4276 if (!((cnp->cn_flags & EMPTYPATH) != 0 && cnp->cn_pnbuf[0] ==
'\0')) {
4284static int __noinline
4288 struct componentname *cnp;
4304static int __noinline
4307 struct nameidata *ndp;
4308 struct componentname *cnp;
4336 if (__predict_false(dvs == VGET_NONE)) {
4342 if (!vn_seqc_consistent(dvp, dvp_seqc)) {
4350 if (cnp->cn_nameptr != fpl->
snd.cn_nameptr) {
4351 panic(
"%s: cn_nameptr mismatch (%p != %p) full [%s]\n", __func__,
4352 cnp->cn_nameptr, fpl->
snd.cn_nameptr, cnp->cn_pnbuf);
4356 ndp->ni_startdir = dvp;
4357 cnp->cn_flags |= MAKEENTRY;
4359 cnp->cn_flags |= ISLASTCN;
4361 cnp->cn_flags |= ISDOTDOT;
4367 if (__predict_false(*(cnp->cn_nameptr) ==
'/')) {
4371 }
while (*(cnp->cn_nameptr) ==
'/');
4374 ndp->ni_pathlen = fpl->
nulchar - cnp->cn_nameptr + 1;
4376 if (ndp->ni_pathlen != fpl->debug.ni_pathlen) {
4377 panic(
"%s: mismatch (%zu != %zu) nulchar %p nameptr %p [%s] ; full string [%s]\n",
4378 __func__, ndp->ni_pathlen, fpl->debug.ni_pathlen, fpl->
nulchar,
4379 cnp->cn_nameptr, cnp->cn_nameptr, cnp->cn_pnbuf);
4388 struct componentname *cnp;
4397 if ((cnp->cn_flags & LOCKLEAF) != 0) {
4398 lkflags = LK_SHARED;
4399 if ((cnp->cn_flags & LOCKSHARED) == 0)
4400 lkflags = LK_EXCLUSIVE;
4402 if (__predict_false(error != 0)) {
4409 if (!vn_seqc_consistent(tvp, tvp_seqc)) {
4410 if ((cnp->cn_flags & LOCKLEAF) != 0)
4423static int __noinline
4426 struct nameidata *ndp;
4427 struct componentname *cnp;
4429 struct vnode *dvp, *tvp;
4440 MPASS(*(cnp->cn_nameptr) !=
'/');
4442 if ((cnp->cn_flags & LOCKPARENT) == 0)
4443 MPASS((cnp->cn_flags & WANTPARENT) != 0);
4444 MPASS((cnp->cn_flags & TRAILINGSLASH) == 0);
4445 MPASS(cnp->cn_nameiop == CREATE || cnp->cn_nameiop == DELETE ||
4446 cnp->cn_nameiop == RENAME);
4447 MPASS((cnp->cn_flags & MAKEENTRY) == 0);
4448 MPASS((cnp->cn_flags & ISDOTDOT) == 0);
4450 docache = (cnp->cn_flags & NOCACHE) ^ NOCACHE;
4451 if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)
4463 mp = atomic_load_ptr(&dvp->v_mount);
4464 if (__predict_false(mp == NULL)) {
4468 if (__predict_false(mp->mnt_flag & MNT_RDONLY)) {
4474 if (cnp->cn_nameiop == CREATE) {
4480 if (fpl->
tvp != NULL && (cnp->cn_flags & FAILIFEXISTS) != 0) {
4501 if (__predict_false(dvs == VGET_NONE)) {
4506 if (!vn_seqc_consistent(dvp, dvp_seqc)) {
4511 error = vn_lock(dvp, LK_EXCLUSIVE);
4512 if (__predict_false(error != 0)) {
4518 cnp->cn_flags |= ISLASTCN;
4520 cnp->cn_flags |= MAKEENTRY;
4522 cnp->cn_flags |= ISDOTDOT;
4523 cnp->cn_lkflags = LK_EXCLUSIVE;
4524 error = VOP_LOOKUP(dvp, &tvp, cnp);
4539 fpl->
savename = (cnp->cn_flags & SAVENAME) != 0;
4542 if ((cnp->cn_flags & SAVESTART) != 0) {
4543 ndp->ni_startdir = dvp;
4545 cnp->cn_flags |= SAVENAME;
4548 MPASS(error == EJUSTRETURN);
4549 if ((cnp->cn_flags & LOCKPARENT) == 0) {
4562 if (__predict_false(tvp == dvp)) {
4572 if (tvp->v_type == VLNK) {
4573 if ((cnp->cn_flags & FOLLOW) != 0) {
4590 if ((cnp->cn_flags & FAILIFEXISTS) != 0) {
4596 if ((cnp->cn_flags & LOCKLEAF) == 0) {
4600 if ((cnp->cn_flags & LOCKPARENT) == 0) {
4604 if ((cnp->cn_flags & SAVESTART) != 0) {
4605 ndp->ni_startdir = dvp;
4607 cnp->cn_flags |= SAVENAME;
4614static int __noinline
4617 struct nameidata *ndp;
4627static int __noinline
4630 struct componentname *cnp;
4631 enum vgetstate dvs, tvs;
4632 struct vnode *dvp, *tvp;
4641 MPASS((cnp->cn_flags & (LOCKPARENT|WANTPARENT)) != 0);
4647 if (__predict_false(dvs == VGET_NONE)) {
4651 if (__predict_false(tvs == VGET_NONE)) {
4659 if ((cnp->cn_flags & LOCKPARENT) != 0) {
4661 if (__predict_false(error != 0)) {
4669 if (!vn_seqc_consistent(dvp, dvp_seqc)) {
4671 if ((cnp->cn_flags & LOCKPARENT) != 0)
4679 if (__predict_false(error != 0)) {
4680 MPASS(fpl->
status == CACHE_FPL_STATUS_ABORTED ||
4681 fpl->
status == CACHE_FPL_STATUS_DESTROYED);
4682 if ((cnp->cn_flags & LOCKPARENT) != 0)
4689 MPASS(fpl->
status == CACHE_FPL_STATUS_HANDLED);
4696 struct componentname *cnp;
4698 struct vnode *dvp, *tvp;
4706 MPASS(*(cnp->cn_nameptr) !=
'/');
4708 if (cnp->cn_nameiop != LOOKUP) {
4712 if ((cnp->cn_flags & (LOCKPARENT|WANTPARENT)) != 0)
4716 if (__predict_false(tvs == VGET_NONE)) {
4720 if (!vn_seqc_consistent(dvp, dvp_seqc)) {
4735static int __noinline
4738 struct componentname *cnp;
4753 for (cp = cnp->cn_pnbuf; *cp !=
'\0'; cp++) {
4755 (
"%s: encountered non-slash; string [%s]\n", __func__,
4760 if (__predict_false(cnp->cn_nameiop != LOOKUP)) {
4765 MPASS((cnp->cn_flags & SAVESTART) == 0);
4767 if ((cnp->cn_flags & (LOCKPARENT|WANTPARENT)) != 0) {
4773 if (__predict_false(dvs == VGET_NONE)) {
4777 if ((cnp->cn_flags & LOCKLEAF) != 0) {
4778 lkflags = LK_SHARED;
4779 if ((cnp->cn_flags & LOCKSHARED) == 0)
4780 lkflags = LK_EXCLUSIVE;
4782 if (__predict_false(error != 0)) {
4791static int __noinline
4794 struct nameidata *ndp;
4795 struct componentname *cnp;
4807 MPASS(*cnp->cn_pnbuf ==
'\0');
4809 if (__predict_false((cnp->cn_flags & EMPTYPATH) == 0)) {
4814 MPASS((cnp->cn_flags & (LOCKPARENT | WANTPARENT)) == 0);
4818 if (__predict_false(tvs == VGET_NONE)) {
4822 if ((cnp->cn_flags & LOCKLEAF) != 0) {
4823 lkflags = LK_SHARED;
4824 if ((cnp->cn_flags & LOCKSHARED) == 0)
4825 lkflags = LK_EXCLUSIVE;
4827 if (__predict_false(error != 0)) {
4834 ndp->ni_resflags |= NIRES_EMPTYPATH;
4838static int __noinline
4841 struct nameidata *ndp;
4842 struct componentname *cnp;
4844 struct vnode *dvp, *tvp;
4853 MPASS((cnp->cn_flags & MAKEENTRY) == 0);
4854 MPASS((cnp->cn_flags & ISDOTDOT) == 0);
4855 if (cnp->cn_nameiop == LOOKUP)
4856 MPASS((cnp->cn_flags & NOCACHE) == 0);
4862 if (__predict_false(cnp->cn_namelen > NAME_MAX)) {
4867 if (cnp->cn_nameptr[0] ==
'/') {
4871 if (cnp->cn_pnbuf[0] ==
'\0') {
4875 if (cnp->cn_nameptr[0] ==
'\0') {
4876 if (fpl->
tvp == NULL) {
4882 if (cnp->cn_nameiop != LOOKUP) {
4887 MPASS((cnp->cn_flags & SAVESTART) == 0);
4913 if (__predict_false(dvs == VGET_NONE)) {
4918 if (!vn_seqc_consistent(dvp, dvp_seqc)) {
4923 error = vn_lock(dvp, LK_SHARED);
4924 if (__predict_false(error != 0)) {
4933 cnp->cn_flags |= ISLASTCN | MAKEENTRY;
4934 cnp->cn_lkflags = LK_SHARED;
4935 if ((cnp->cn_flags & LOCKSHARED) == 0) {
4936 cnp->cn_lkflags = LK_EXCLUSIVE;
4938 error = VOP_LOOKUP(dvp, &tvp, cnp);
4954 MPASS((cnp->cn_flags & SAVENAME) == 0);
4958 MPASS(error == EJUSTRETURN);
4959 if ((cnp->cn_flags & (WANTPARENT | LOCKPARENT)) == 0) {
4961 }
else if ((cnp->cn_flags & LOCKPARENT) == 0) {
4967 if (tvp->v_type == VLNK) {
4968 if ((cnp->cn_flags & FOLLOW) != 0) {
4981 if ((cnp->cn_flags & LOCKLEAF) == 0) {
4985 if ((cnp->cn_flags & (WANTPARENT | LOCKPARENT)) == 0) {
4987 }
else if ((cnp->cn_flags & LOCKPARENT) == 0) {
4993static int __noinline
4998 MPASS(!seqc_in_modify(fpl->
dvp_seqc));
5007 counter_u64_add(dothits, 1);
5017static int __noinline
5020 struct nameidata *ndp;
5021 struct componentname *cnp;
5036 for (
pr = cnp->cn_cred->cr_prison;
pr != NULL;
5038 if (dvp ==
pr->pr_root)
5041 if (dvp == ndp->ni_rootdir ||
5042 dvp == ndp->ni_topdir ||
5046 fpl->
tvp_seqc = vn_seqc_read_any(dvp);
5047 if (seqc_in_modify(fpl->
tvp_seqc)) {
5053 if ((dvp->v_vflag & VV_ROOT) != 0) {
5061 ncp = atomic_load_consume_ptr(&dvp->v_cache_dd);
5066 nc_flag = atomic_load_char(&ncp->
nc_flag);
5070 fpl->
tvp = ncp->nc_vp;
5072 fpl->
tvp = ncp->nc_dvp;
5076 if (seqc_in_modify(fpl->
tvp_seqc)) {
5083 if (__predict_false(atomic_load_ptr(&dvp->v_cache_dd) != ncp)) {
5091 counter_u64_add(dotdothits, 1);
5095static int __noinline
5098 u_char nc_flag __diagused;
5102 nc_flag = atomic_load_char(&ncp->
nc_flag);
5108 if (__predict_false(fpl->
cnp->cn_nameiop != LOOKUP)) {
5134 struct nameidata *ndp;
5135 struct componentname *cnp;
5141 if (__predict_false(len == 0)) {
5145 if (__predict_false(len > MAXPATHLEN - 2)) {
5151 ndp->ni_pathlen = fpl->
nulchar - cnp->cn_nameptr - cnp->cn_namelen + 1;
5153 if (ndp->ni_pathlen != fpl->debug.ni_pathlen) {
5154 panic(
"%s: mismatch (%zu != %zu) nulchar %p nameptr %p [%s] ; full string [%s]\n",
5155 __func__, ndp->ni_pathlen, fpl->debug.ni_pathlen, fpl->
nulchar,
5156 cnp->cn_nameptr, cnp->cn_nameptr, cnp->cn_pnbuf);
5160 if (__predict_false(len + ndp->ni_pathlen > MAXPATHLEN)) {
5161 return (ENAMETOOLONG);
5164 if (__predict_false(ndp->ni_loopcnt++ >= MAXSYMLINKS)) {
5169 if (ndp->ni_pathlen > 1) {
5170 bcopy(ndp->ni_next, cnp->cn_pnbuf + len, ndp->ni_pathlen);
5174 cnp->cn_pnbuf[len] =
'/';
5175 cnp->cn_pnbuf[len + 1] =
'\0';
5177 cnp->cn_pnbuf[len] =
'\0';
5180 bcopy(
string, cnp->cn_pnbuf, len);
5182 ndp->ni_pathlen += adjust;
5184 cnp->cn_nameptr = cnp->cn_pnbuf;
5185 fpl->
nulchar = &cnp->cn_nameptr[ndp->ni_pathlen - 1];
5190static int __noinline
5194 struct nameidata *ndp;
5195 struct componentname *cnp;
5196 struct vnode *dvp, *tvp;
5205 if ((cnp->cn_flags & FOLLOW) == 0) {
5210 mp = atomic_load_ptr(&dvp->v_mount);
5211 if (__predict_false(mp == NULL)) {
5219 if (__predict_false((mp->mnt_flag & MNT_NOSYMFOLLOW) != 0)) {
5224 error = VOP_FPLOOKUP_SYMLINK(tvp, fpl);
5225 if (__predict_false(error != 0)) {
5239 if (*(cnp->cn_nameptr) ==
'/') {
5242 if (seqc_in_modify(fpl->
dvp_seqc)) {
5250 mp = atomic_load_ptr(&fpl->
dvp->v_mount);
5251 if (__predict_false(mp == NULL)) {
5265 struct componentname *cnp;
5267 struct vnode *dvp, *tvp;
5276 if (__predict_false(cnp->cn_nameptr[0] ==
'.')) {
5277 if (cnp->cn_namelen == 1) {
5280 if (cnp->cn_namelen == 2 && cnp->cn_nameptr[1] ==
'.') {
5287 CK_SLIST_FOREACH(ncp, (
NCHHASH(hash)), nc_hash) {
5288 if (ncp->nc_dvp == dvp && ncp->
nc_nlen == cnp->cn_namelen &&
5293 if (__predict_false(ncp == NULL)) {
5297 tvp = atomic_load_ptr(&ncp->nc_vp);
5298 nc_flag = atomic_load_char(&ncp->
nc_flag);
5308 fpl->
tvp_seqc = vn_seqc_read_any(tvp);
5309 if (seqc_in_modify(fpl->
tvp_seqc)) {
5313 counter_u64_add(numposhits, 1);
5328 if ((mp->mnt_kern_flag & MNTK_FPLOOKUP) == 0)
5351static int __noinline
5354 struct mount *mp, *prev_mp;
5355 struct mount_pcpu *mpcpu, *prev_mpcpu;
5362 VNPASS(vp->v_type == VDIR || vp->v_type == VBAD, vp);
5363 mp = atomic_load_ptr(&vp->v_mountedhere);
5364 if (__predict_false(mp == NULL)) {
5370 if (!vfs_op_thread_enter_crit(mp, mpcpu)) {
5371 if (prev_mp != NULL)
5372 vfs_op_thread_exit_crit(prev_mp, prev_mpcpu);
5375 if (prev_mp != NULL)
5376 vfs_op_thread_exit_crit(prev_mp, prev_mpcpu);
5377 if (!vn_seqc_consistent(vp, vp_seqc)) {
5378 vfs_op_thread_exit_crit(mp, mpcpu);
5382 vfs_op_thread_exit_crit(mp, mpcpu);
5385 vp = atomic_load_ptr(&mp->mnt_rootvnode);
5387 vfs_op_thread_exit_crit(mp, mpcpu);
5390 vp_seqc = vn_seqc_read_any(vp);
5391 if (seqc_in_modify(vp_seqc)) {
5392 vfs_op_thread_exit_crit(mp, mpcpu);
5397 mp = atomic_load_ptr(&vp->v_mountedhere);
5402 vfs_op_thread_exit_crit(prev_mp, prev_mpcpu);
5408static int __noinline
5412 struct mount_pcpu *mpcpu;
5419 VNPASS(vp->v_type == VDIR || vp->v_type == VBAD, vp);
5420 mp = atomic_load_ptr(&vp->v_mountedhere);
5421 if (__predict_false(mp == NULL)) {
5425 if (!vfs_op_thread_enter_crit(mp, mpcpu)) {
5428 if (!vn_seqc_consistent(vp, vp_seqc)) {
5429 vfs_op_thread_exit_crit(mp, mpcpu);
5433 vfs_op_thread_exit_crit(mp, mpcpu);
5436 vp = atomic_load_ptr(&mp->mnt_rootvnode);
5437 if (__predict_false(vp == NULL)) {
5438 vfs_op_thread_exit_crit(mp, mpcpu);
5441 vp_seqc = vn_seqc_read_any(vp);
5442 vfs_op_thread_exit_crit(mp, mpcpu);
5443 if (seqc_in_modify(vp_seqc)) {
5446 mp = atomic_load_ptr(&vp->v_mountedhere);
5447 if (__predict_false(mp != NULL)) {
5470 return ((vn_irflag_read(vp) & VIRF_MOUNTPOINT) != 0);
5490 fpl->debug.ni_pathlen += n;
5491 KASSERT(fpl->debug.ni_pathlen <= PATH_MAX,
5492 (
"%s: pathlen overflow to %zd\n", __func__, fpl->debug.ni_pathlen));
5499 fpl->debug.ni_pathlen -= n;
5500 KASSERT(fpl->debug.ni_pathlen <= PATH_MAX,
5501 (
"%s: pathlen underflow to %zd\n", __func__, fpl->debug.ni_pathlen));
5542 struct nameidata *ndp;
5543 struct componentname *cnp;
5561 MPASS(&cnp->cn_nameptr[fpl->debug.ni_pathlen - 1] >= cnp->cn_pnbuf);
5562 KASSERT(&cnp->cn_nameptr[fpl->debug.ni_pathlen - 1] == fpl->
nulchar,
5563 (
"%s: mismatch between pathlen (%zu) and nulchar (%p != %p), string [%s]\n",
5564 __func__, fpl->debug.ni_pathlen, &cnp->cn_nameptr[fpl->debug.ni_pathlen - 1],
5565 fpl->
nulchar, cnp->cn_pnbuf));
5566 KASSERT(*fpl->
nulchar ==
'\0',
5567 (
"%s: expected nul at %p; string [%s]\n", __func__, fpl->
nulchar,
5571 for (cp = cnp->cn_nameptr; *cp !=
'/'; cp++) {
5572 KASSERT(*cp !=
'\0',
5573 (
"%s: encountered unexpected nul; string [%s]\n", __func__,
5581 cnp->cn_namelen = cp - cnp->cn_nameptr;
5589 if (cnp->cn_namelen <= NAME_MAX) {
5591 panic(
"%s: mismatched hash for [%s] len %ld", __func__,
5592 cnp->cn_nameptr, cnp->cn_namelen);
5609 struct nameidata *ndp;
5610 struct componentname *cnp;
5615 cnp->cn_nameptr = ndp->ni_next;
5616 KASSERT(*(cnp->cn_nameptr) ==
'/',
5617 (
"%s: should have seen slash at %p ; buf %p [%s]\n", __func__,
5618 cnp->cn_nameptr, cnp->cn_pnbuf, cnp->cn_pnbuf));
5632static int __noinline
5635 struct nameidata *ndp;
5636 struct componentname *cnp;
5641 MPASS(*(cnp->cn_nameptr) ==
'/');
5645 }
while (*(cnp->cn_nameptr) ==
'/');
5657 ndp->ni_next = cnp->cn_nameptr;
5685static int __noinline
5691 struct nameidata *ndp;
5692 struct componentname *cnp;
5695 char *cn_nameptr_orig, *cn_nameptr_slash;
5704 MPASS(fpl->
dvp == fpl->
tvp);
5706 (
"%s: expected trailing slash at %p; string [%s]\n", __func__, fpl->
nulchar - 1,
5708 KASSERT(cnp->cn_nameptr[0] ==
'\0',
5709 (
"%s: expected nul char at %p; string [%s]\n", __func__, &cnp->cn_nameptr[0],
5711 KASSERT(cnp->cn_namelen == 0,
5712 (
"%s: namelen 0 but got %ld; string [%s]\n", __func__, cnp->cn_namelen,
5714 MPASS(cnp->cn_nameptr > cnp->cn_pnbuf);
5716 if (cnp->cn_nameiop != LOOKUP) {
5720 if (__predict_false(tvp->v_type != VDIR)) {
5721 if (!vn_seqc_consistent(tvp, tvp_seqc)) {
5731 ndp->ni_next = &cnp->cn_nameptr[0];
5737 cn_nameptr_orig = cnp->cn_nameptr;
5738 while (cnp->cn_nameptr >= cnp->cn_pnbuf) {
5740 if (cnp->cn_nameptr[0] !=
'/') {
5750 cn_nameptr_slash = cnp->cn_nameptr;
5751 while (cnp->cn_nameptr > cnp->cn_pnbuf) {
5753 if (cnp->cn_nameptr[0] ==
'/') {
5757 if (cnp->cn_nameptr[0] ==
'/') {
5761 cnp->cn_namelen = cn_nameptr_slash - cnp->cn_nameptr + 1;
5766 ni_pathlen = fpl->
nulchar - cnp->cn_nameptr + 1;
5767 if (ni_pathlen != fpl->debug.ni_pathlen) {
5768 panic(
"%s: mismatch (%zu != %zu) nulchar %p nameptr %p [%s] ; full string [%s]\n",
5769 __func__, ni_pathlen, fpl->debug.ni_pathlen, fpl->
nulchar,
5770 cnp->cn_nameptr, cnp->cn_nameptr, cnp->cn_pnbuf);
5777 if (cnp->cn_nameptr[0] ==
'.' && cnp->cn_namelen == 1) {
5785 ncp = atomic_load_consume_ptr(&tvp->v_cache_dd);
5786 if (__predict_false(ncp == NULL)) {
5789 nc_flag = atomic_load_char(&ncp->
nc_flag);
5793 fpl->
dvp = ncp->nc_dvp;
5795 if (seqc_in_modify(fpl->
dvp_seqc)) {
5804static int __noinline
5807 struct componentname *cnp;
5818 if (cnp->cn_pnbuf[0] ==
'\0') {
5836 if (cnp->cn_nameptr[0] ==
'\0' && fpl->
tvp == NULL) {
5843 if (__predict_false(cnp->cn_namelen > NAME_MAX)) {
5853 if (dvp->v_type != VDIR) {
5887 if (!vn_seqc_consistent(dvp, dvp_seqc)) {
5894 if (!vn_seqc_consistent(dvp, dvp_seqc)) {
5908 struct nameidata *ndp;
5909 struct componentname *cnp;
5926 mp = atomic_load_ptr(&dvp->v_mount);
5931 MPASS(fpl->
tvp == NULL);
5936 error = VOP_FPLOOKUP_VEXEC(fpl->
dvp, cnp->cn_cred);
5937 if (__predict_false(error != 0)) {
5949 if (fpl->
tvp->v_type == VLNK) {
5960 if (!vn_seqc_consistent(fpl->
dvp, fpl->
dvp_seqc)) {
6059 struct componentname *cnp;
6062 fpl.
status = CACHE_FPL_STATUS_UNSET;
6065 fpl.
cnp = cnp = &ndp->ni_cnd;
6066 MPASS(ndp->ni_lcf == 0);
6068 (
"%s: internal flags found in cn_flags %" PRIx64, __func__,
6070 if ((cnp->cn_flags & SAVESTART) != 0) {
6071 MPASS(cnp->cn_nameiop != LOOKUP);
6073 MPASS(cnp->cn_nameptr == cnp->cn_pnbuf);
6077 SDT_PROBE3(vfs, fplookup, lookup, done, ndp, fpl.
line, fpl.
status);
6078 return (EOPNOTSUPP);
6085 fpl.debug.ni_pathlen = ndp->ni_pathlen;
6087 fpl.
nulchar = &cnp->cn_nameptr[ndp->ni_pathlen - 1];
6089 fpl.
savename = (cnp->cn_flags & SAVENAME) != 0;
6092 pwd = pwd_get_smr();
6094 ndp->ni_rootdir = pwd->pwd_rdir;
6095 ndp->ni_topdir = pwd->pwd_jdir;
6097 if (cnp->cn_pnbuf[0] ==
'/') {
6099 MPASS(ndp->ni_resflags == 0);
6100 ndp->ni_resflags = NIRES_ABS;
6102 if (ndp->ni_dirfd == AT_FDCWD) {
6103 dvp = pwd->pwd_cdir;
6106 if (__predict_false(error != 0)) {
6112 SDT_PROBE4(vfs,
namei, lookup, entry, dvp, cnp->cn_pnbuf, cnp->cn_flags,
true);
6118 if (SDT_PROBES_ENABLED()) {
6119 SDT_PROBE3(vfs, fplookup, lookup, done, ndp, fpl.
line, fpl.
status);
6120 if (fpl.
status == CACHE_FPL_STATUS_HANDLED)
6121 SDT_PROBE4(vfs,
namei, lookup,
return, error, ndp->ni_vp,
true,
6125 if (__predict_true(fpl.
status == CACHE_FPL_STATUS_HANDLED)) {
6128 MPASS(fpl.
dvp == NULL);
6129 MPASS(fpl.
tvp == NULL);
6132 ndp->ni_dvp = fpl.
dvp;
6133 ndp->ni_vp = fpl.
tvp;
6135 cnp->cn_flags |= HASBUF;
device_property_type_t type
SYSCTL_BOOL(__CONCAT(_kern_elf, __ELF_WORD_SIZE), OID_AUTO, allow_wx, CTLFLAG_RWTUN, &__elfN(allow_wx), 0, "Allow pages to be mapped simultaneously writable and executable")
struct pwd * pwd_hold(struct thread *td)
bool pwd_hold_smr(struct pwd *pwd)
void pwd_drop(struct pwd *pwd)
int fgetvp_lookup_smr(int fd, struct nameidata *ndp, struct vnode **vpp, bool *fsearch)
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
void mtx_wait_unlocked(struct mtx *m)
static struct pollrec pr[POLL_LIST_LEN]
void panic(const char *fmt,...)
int sysctl_handle_int(SYSCTL_HANDLER_ARGS)
struct nameidata_outer snd_outer
struct componentname * cnp
struct nameidata_saved snd
enum cache_fpl_status status
struct timespec nc_dotdottime
static bool kasan_enabled __read_mostly
__read_mostly cap_rights_t cap_fstat_rights
uint64_t counter_u64_fetch(counter_u64_t c)
static __noinline int cache_remove_cnp(struct vnode *dvp, struct componentname *cnp)
SYSCTL_COUNTER_U64(_vfs_cache_neg, OID_AUTO, created, CTLFLAG_RD, &neg_created, "Number of created negative entries")
static int __noinline cache_zap_locked_bucket(struct namecache *ncp, struct componentname *cnp, uint32_t hash, struct mtx *blp)
static u_long __read_mostly ncnegfactor
static u_int __read_mostly ncsize
SYSCTL_ULONG(_vfs_cache_param, OID_AUTO, negfactor, CTLFLAG_RW, &ncnegfactor, 0, "Ratio of negative namecache entries")
static void cache_hold_vnode(struct vnode *vp)
void cache_purgevfs(struct mount *mp)
#define CACHE_ZONE_LARGE_SIZE
static int cache_trylock_vnodes(struct mtx *vlp1, struct mtx *vlp2)
#define cache_fpl_smr_assert_entered(fpl)
SYSCTL_PROC(_vfs_cache, OID_AUTO, nchstats, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE, 0, 0, sysctl_nchstats, "LU", "VFS cache effectiveness statistics")
static void cache_fpl_restore_abort(struct cache_fpl *fpl)
SDT_PROBE_DEFINE2(vfs, namecache, enter_negative, done, "struct vnode *", "char *")
static int vn_fullpath_dir(struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf, size_t *len, size_t addend)
#define STATNODE_COUNTER(name, varname, descr)
static struct namecache * cache_alloc_uma(int len, bool ts)
static uint32_t cache_get_hash(char *name, u_char len, struct vnode *dvp)
static long cache_lock_vnodes_cel_3_failures
static void cache_purge_impl(struct vnode *vp)
SDT_PROBE_DECLARE(vfs, namei, lookup, entry)
SDT_PROBE_DEFINE1(vfs, namecache, fullpath, entry, "struct vnode *")
static u_int __read_mostly neg_min
#define CACHE_FPL_SUPPORTED_CN_FLAGS
static void cache_fpl_cleanup_cnp(struct componentname *cnp)
static int cache_fpl_handled_error_impl(struct cache_fpl *fpl, int error, int line)
static void nchinit(void *dummy __unused)
void cache_purge_negative(struct vnode *vp)
static void cache_enter_unlock(struct celockstate *cel)
static void __noinline cache_enter_dotdot_prep(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
int vn_vptocnp(struct vnode **vp, char *buf, size_t *buflen)
static int cache_fplookup_impl(struct vnode *dvp, struct cache_fpl *fpl)
static struct mtx * VP2VNODELOCK(struct vnode *vp)
static int cache_zap_unlocked_bucket(struct namecache *ncp, struct componentname *cnp, struct vnode *dvp, struct mtx *dvlp, struct mtx *vlp, uint32_t hash, struct mtx *blp)
int vn_commname(struct vnode *vp, char *buf, u_int buflen)
static struct neglist neglists[numneglists]
static bool cache_zap_locked_vnode_kl2(struct namecache *ncp, struct vnode *vp, struct mtx **vlpp)
static void cache_fpl_pathlen_inc(struct cache_fpl *fpl)
void cache_fast_lookup_enabled_recalc(void)
void cache_vop_rmdir(struct vnode *dvp, struct vnode *vp)
char * cache_symlink_alloc(size_t size, int flags)
static void cache_fpl_pathlen_sub(struct cache_fpl *fpl, size_t n)
static void cache_fplookup_parse_advance(struct cache_fpl *fpl)
#define cache_sort_vnodes(x, y)
#define CACHE_ZONE_SMALL_TS_SIZE
#define CACHE_ZONE_ALIGNMENT
static void cache_lock_all_vnodes(void)
static void cache_neg_hit_finish(struct namecache *ncp)
static uint32_t cache_get_hash_iter(char c, uint32_t hash)
static bool cache_fplookup_mp_supported(struct mount *mp)
static void cache_neg_demote_locked(struct namecache *ncp)
static int __noinline cache_fplookup_final_withparent(struct cache_fpl *fpl)
static struct mtx __read_mostly * vnodelocks
static long zap_bucket_fail2
__aligned(CACHE_LINE_SIZE)
static void cache_neg_insert(struct namecache *ncp)
void cache_changesize(u_long newmaxvnodes)
static void cache_fpl_restore_partial(struct cache_fpl *fpl)
static void cache_fpl_checkpoint_outer(struct cache_fpl *fpl)
void cache_vnode_init(struct vnode *vp)
static void cache_recalc_neg_min(u_int val)
#define CACHE_PATH_CUTOFF
static uma_zone_t __read_mostly cache_zone_small
static struct namecache * vn_dd_from_dst(struct vnode *vp)
#define cache_fpl_smr_assert_not_entered(fpl)
static struct neglist * cache_neg_evict_select_list(void)
static int kern___realpathat(struct thread *td, int fd, const char *path, char *buf, size_t size, int flags, enum uio_seg pathseg)
static void cache_drop_vnode(struct vnode *vp)
static struct nchashhead * nchinittbl(u_long elements, u_long *hashmask)
void cache_enter_time_flags(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, struct timespec *tsp, struct timespec *dtsp, int flags)
#define cache_fpl_assert_status(fpl)
static struct namecache * cache_neg_evict_select_entry(struct neglist *nl)
static int cache_fplookup_final_child(struct cache_fpl *fpl, enum vgetstate tvs)
static MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries")
CTASSERT((nitems(((struct celockstate *) 0) ->vlp)==3))
static bool cache_neg_promote_cond(struct vnode *dvp, struct componentname *cnp, struct namecache *oncp, uint32_t hash)
static bool cache_neg_hit_prep(struct namecache *ncp)
static u_int cache_roundup_2(u_int val)
int vn_path_to_global_path(struct thread *td, struct vnode *vp, char *path, u_int pathlen)
static void cache_celockstate_init(struct celockstate *cel)
#define cache_fpl_aborted_early(x)
int sys___getcwd(struct thread *td, struct __getcwd_args *uap)
static struct nchashhead * NCP2BUCKET(struct namecache *ncp)
static int __noinline cache_fplookup_dirfd(struct cache_fpl *fpl, struct vnode **vpp)
static int __noinline cache_fplookup_dot(struct cache_fpl *fpl)
static void cache_lock_vnodes_cel(struct celockstate *cel, struct vnode *vp, struct vnode *dvp)
static void cache_fpl_checkpoint(struct cache_fpl *fpl)
static uma_zone_t __read_mostly cache_zone_small_ts
#define cache_fpl_handled_error(x, e)
static void cache_free_batch(struct cache_freebatch *batch)
static int __noinline cache_fplookup_degenerate(struct cache_fpl *fpl)
static bool cache_fpl_islastcn(struct nameidata *ndp)
int vn_fullpath_global(struct vnode *vp, char **retbuf, char **freebuf)
static uint32_t cache_get_hash_iter_start(struct vnode *dvp)
static bool cache_fplookup_is_mp(struct cache_fpl *fpl)
static int __noinline cache_lookup_dotdot(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct timespec *tsp, int *ticksp)
static void cache_free(struct namecache *ncp)
static int sysctl_neg_hot(SYSCTL_HANDLER_ARGS)
#define DEBUGNODE_ULONG(name, varname, descr)
static u_int __read_mostly ncbuckethash
SDT_PROVIDER_DECLARE(vfs)
static int cache_fpl_handled_impl(struct cache_fpl *fpl, int line)
static void cache_neg_promote(struct namecache *ncp)
static int __noinline cache_fplookup_noentry(struct cache_fpl *fpl)
static struct mtx * NCP2BUCKETLOCK(struct namecache *ncp)
static int vn_fullpath_any(struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf, size_t *buflen)
int vfs_cache_lookup(struct vop_lookup_args *ap)
#define cache_fpl_handled(x)
static bool cache_lock_vnodes_cel_3(struct celockstate *cel, struct vnode *vp)
#define STATNODE_ULONG(name, varname, descr)
static void cache_unlock_vnodes(struct mtx *vlp1, struct mtx *vlp2)
#define cache_ncp_canuse(ncp)
static bool cache_fpl_terminated(struct cache_fpl *fpl)
static void cache_lock_all_buckets(void)
static int sysctl_negminpct(SYSCTL_HANDLER_ARGS)
TAILQ_HEAD(cache_freebatch, namecache)
int sys___realpathat(struct thread *td, struct __realpathat_args *uap)
#define DEBUGNODE_COUNTER(name, varname, descr)
static void cache_fpl_pathlen_dec(struct cache_fpl *fpl)
static bool cache_has_entries(struct vnode *vp)
#define cache_fpl_smr_exit(fpl)
static struct mtx_padalign __read_mostly * bucketlocks
static void cache_lock_vnodes(struct mtx *vlp1, struct mtx *vlp2)
#define CACHE_FPL_INTERNAL_CN_FLAGS
static void cache_assert_vlp_locked(struct mtx *vlp)
static int __noinline cache_fplookup_failed_vexec(struct cache_fpl *fpl, int error)
static int sysctl_nchstats(SYSCTL_HANDLER_ARGS)
static void cache_zap_locked(struct namecache *ncp)
static int cache_fplookup_trailingslash(struct cache_fpl *fpl)
_Static_assert(sizeof(struct negstate)<=sizeof(struct vnode *), "the state must fit in a union with a pointer without growing it")
int cache_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct timespec *tsp, int *ticksp)
static uma_zone_t __read_mostly cache_zone_large
void cache_vop_rename(struct vnode *fdvp, struct vnode *fvp, struct vnode *tdvp, struct vnode *tvp, struct componentname *fcnp, struct componentname *tcnp)
static struct namecache * cache_alloc(int len, bool ts)
#define CACHE_NEG_PROMOTION_THRESH
static long zap_bucket_fail
static void cache_free_uma(struct namecache *ncp)
static int __noinline cache_fplookup_final_modifying(struct cache_fpl *fpl)
static void cache_enter_lock(struct celockstate *cel, struct vnode *dvp, struct vnode *vp, uint32_t hash)
static void cache_assert_vnode_locked(struct vnode *vp)
static void cache_prehash(struct vnode *vp)
int vn_getcwd(char *buf, char **retbuf, size_t *buflen)
static void cache_out_ts(struct namecache *ncp, struct timespec *tsp, int *ticksp)
static void cache_neg_promote_locked(struct namecache *ncp)
static int cache_fplookup_next(struct cache_fpl *fpl)
static COUNTER_U64_DEFINE_EARLY(neg_created)
static void cache_fplookup_parse(struct cache_fpl *fpl)
#define cache_fpl_partial(x)
static void cache_ncp_invalidate(struct namecache *ncp)
static bool cache_fpl_isdotdot(struct componentname *cnp)
static int cache_fplookup_cross_mount(struct cache_fpl *fpl)
SDT_PROBE_DEFINE4(vfs, namecache, fullpath_smr, miss, "struct vnode *", "struct namecache *", "int", "int")
#define cache_neg_hit_abort(ncp)
static void cache_changesize_set_temp(struct nchashhead *temptbl, u_long temphash)
static struct negstate * NCP2NEGSTATE(struct namecache *ncp)
static void cache_unlock_vnodes_cel(struct celockstate *cel)
int vn_fullpath(struct vnode *vp, char **retbuf, char **freebuf)
#define cache_assert_bucket_locked(x)
static int __noinline cache_fplookup_dotdot(struct cache_fpl *fpl)
SYSCTL_UINT(_vfs_cache_param, OID_AUTO, size, CTLFLAG_RW, &ncsize, 0, "Total namecache capacity")
SDT_PROBE_DEFINE3(vfs, namecache, enter, done, "struct vnode *", "char *", "struct vnode *")
int cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status, struct pwd **pwdp)
static int syscal_vfs_cache_fast_lookup(SYSCTL_HANDLER_ARGS)
static uma_zone_t __read_mostly cache_zone_large_ts
static int cache_fpl_aborted_early_impl(struct cache_fpl *fpl, int line)
static int __noinline cache_fpl_aborted_impl(struct cache_fpl *fpl, int line)
void cache_purge_vgone(struct vnode *vp)
#define HASH2BUCKETLOCK(hash)
void cache_purge(struct vnode *vp)
static struct neglist * NCP2NEGLIST(struct namecache *ncp)
static void cache_unlock_buckets_cel(struct celockstate *cel)
static void cache_zap_negative_locked_vnode_kl(struct namecache *ncp, struct vnode *vp)
#define cache_fpl_smr_enter_initial(fpl)
static bool cache_neg_evict_cond(u_long lnumcache)
static int __noinline cache_fplookup_emptypath(struct cache_fpl *fpl)
static int cache_fplookup_skip_slashes(struct cache_fpl *fpl)
static int __noinline cache_fplookup_symlink(struct cache_fpl *fpl)
static char __read_frequently cache_fast_lookup_enabled
SYSCTL_INT(_debug_sizeof, OID_AUTO, namecache, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, sizeof(struct namecache), "sizeof(struct namecache)")
static uint32_t cache_get_hash_iter_finish(uint32_t hash)
void cache_enter_time(struct vnode *dvp, struct vnode *vp, struct componentname *cnp, struct timespec *tsp, struct timespec *dtsp)
static int __noinline cache_lookup_dot(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct timespec *tsp, int *ticksp)
static void ncfreetbl(struct nchashhead *hashtbl)
static bool cache_neg_evict(void)
static void cache_neg_remove(struct namecache *ncp)
#define CACHE_ZONE_SMALL_SIZE
static int __noinline cache_fpl_partial_impl(struct cache_fpl *fpl, int line)
void cache_symlink_free(char *string, size_t size)
static bool cache_can_fplookup(struct cache_fpl *fpl)
static void cache_neg_init(struct namecache *ncp)
static int cache_fast_lookup
static int __noinline cache_fplookup_negative_promote(struct cache_fpl *fpl, struct namecache *oncp, uint32_t hash)
static void cache_lock_buckets_cel(struct celockstate *cel, struct mtx *blp1, struct mtx *blp2)
static int cache_fplookup_partial_setup(struct cache_fpl *fpl)
static void cache_changesize_set_new(struct nchashhead *new_tbl, u_long new_hash)
SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_SECOND, nchinit, NULL)
static int __noinline cache_fplookup_modifying(struct cache_fpl *fpl)
int vn_fullpath_hardlink(struct vnode *vp, struct vnode *dvp, const char *hrdl_name, size_t hrdl_name_length, char **retbuf, char **freebuf, size_t *buflen)
#define cache_fpl_aborted(x)
#define CACHE_ZONE_LARGE_TS_SIZE
static void cache_fpl_pathlen_add(struct cache_fpl *fpl, size_t n)
static int __noinline cache_lookup_fallback(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct timespec *tsp, int *ticksp)
static __read_mostly CK_SLIST_HEAD(nchashhead, namecache)
static int __noinline cache_fplookup_climb_mount(struct cache_fpl *fpl)
static void cache_unlock_all_buckets(void)
#define cache_fpl_neg_ncp_canuse(ncp)
static int __noinline cache_fplookup_neg(struct cache_fpl *fpl, struct namecache *ncp, uint32_t hash)
static struct vnode * cache_fpl_handle_root(struct cache_fpl *fpl)
static SYSCTL_NODE(_vfs, OID_AUTO, cache, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "Name cache")
int cache_symlink_resolve(struct cache_fpl *fpl, const char *string, size_t len)
struct vnode * vn_dir_dd_ino(struct vnode *vp)
static void cache_unlock_all_vnodes(void)
static void __inline cache_rev_failed_impl(int *reason, int line)
static int cache_fplookup_final(struct cache_fpl *fpl)
static void _cache_sort_vnodes(void **p1, void **p2)
static void cache_enter_lock_dd(struct celockstate *cel, struct vnode *dvp, struct vnode *vp, uint32_t hash)
#define cache_rev_failed(var)
static bool cache_fpl_istrailingslash(struct cache_fpl *fpl)
static int vn_fullpath_any_smr(struct vnode *vp, struct vnode *rdir, char *buf, char **retbuf, size_t *buflen, size_t addend)
static u_int __read_mostly ncvnodehash
#define cache_assert_bucket_unlocked(x)
void() NDFREE(struct nameidata *ndp, const u_int flags)
int namei(struct nameidata *ndp)
void vhold(struct vnode *vp)
enum vgetstate vget_prep_smr(struct vnode *vp)
int vn_dir_check_exec(struct vnode *vp, struct componentname *cnp)
void vref(struct vnode *vp)
void vget_finish_ref(struct vnode *vp, enum vgetstate vs)
int vget_finish(struct vnode *vp, int flags, enum vgetstate vs)
void vget_abort(struct vnode *vp, enum vgetstate vs)
void vrefact(struct vnode *vp)
enum vgetstate vget_prep(struct vnode *vp)
void vrele(struct vnode *vp)
void vput(struct vnode *vp)
void vdrop(struct vnode *vp)