Index: sbin/mount_nfs/mount_nfs.8 =================================================================== --- sbin/mount_nfs/mount_nfs.8 (revision 225431) +++ sbin/mount_nfs/mount_nfs.8 (working copy) @@ -151,6 +151,10 @@ (Necessary for some old .Bx servers.) +.It Cm nametimeo Ns = Ns Aq Ar value +Override the default of NFS_DEFAULT_NAMETIMEO for the timeout (in seconds) +for positive name cache entries. +If this is set to 0 it disables positive name caching for the mount point. .It Cm negnametimeo Ns = Ns Aq Ar value Override the default of NFS_DEFAULT_NEGNAMETIMEO for the timeout (in seconds) for negative name cache entries. If this is set to 0 it disables negative Index: sys/fs/nfsclient/nfs_clvfsops.c =================================================================== --- sys/fs/nfsclient/nfs_clvfsops.c (revision 225463) +++ sys/fs/nfsclient/nfs_clvfsops.c (working copy) @@ -104,7 +104,7 @@ static int mountnfs(struct nfs_args *, struct mount *, struct sockaddr *, char *, u_char *, int, u_char *, int, u_char *, int, struct vnode **, struct ucred *, - struct thread *, int); + struct thread *, int, int); static void nfs_getnlminfo(struct vnode *, uint8_t *, size_t *, struct sockaddr_storage *, int *, off_t *, struct timeval *); @@ -516,7 +516,8 @@ dirlen = 0; nam = sodupsockaddr((struct sockaddr *)sin, M_WAITOK); if ((error = mountnfs(args, mp, nam, path, NULL, 0, dirpath, dirlen, - NULL, 0, vpp, td->td_ucred, td, NFS_DEFAULT_NEGNAMETIMEO)) != 0) { + NULL, 0, vpp, td->td_ucred, td, NFS_DEFAULT_NAMETIMEO, + NFS_DEFAULT_NEGNAMETIMEO)) != 0) { printf("nfs_mountroot: mount %s on /: %d\n", path, error); return (error); } @@ -711,7 +712,7 @@ "retrans", "acregmin", "acregmax", "acdirmin", "acdirmax", "resvport", "readahead", "hostname", "timeout", "addr", "fh", "nfsv3", "sec", "principal", "nfsv4", "gssname", "allgssname", "dirpath", - "negnametimeo", "nocto", "wcommitsize", + "nametimeo", "negnametimeo", "nocto", "wcommitsize", NULL }; /* @@ -756,6 +757,7 @@ char hst[MNAMELEN]; u_char nfh[NFSX_FHMAX], krbname[100], dirpath[100], srvkrbname[100]; char *opt, *name, *secname; + int nametimeo = NFS_DEFAULT_NAMETIMEO; int negnametimeo = NFS_DEFAULT_NEGNAMETIMEO; int dirlen, has_nfs_args_opt, krbnamelen, srvkrbnamelen; size_t hstlen; @@ -964,6 +966,14 @@ } args.flags |= NFSMNT_TIMEO; } + if (vfs_getopt(mp->mnt_optnew, "nametimeo", (void **)&opt, NULL) == 0) { + ret = sscanf(opt, "%d", &nametimeo); + if (ret != 1 || nametimeo < 0) { + vfs_mount_error(mp, "illegal nametimeo: %s", opt); + error = EINVAL; + goto out; + } + } if (vfs_getopt(mp->mnt_optnew, "negnametimeo", (void **)&opt, NULL) == 0) { ret = sscanf(opt, "%d", &negnametimeo); @@ -1105,7 +1115,7 @@ args.fh = nfh; error = mountnfs(&args, mp, nam, hst, krbname, krbnamelen, dirpath, dirlen, srvkrbname, srvkrbnamelen, &vp, td->td_ucred, td, - negnametimeo); + nametimeo, negnametimeo); out: if (!error) { MNT_ILOCK(mp); @@ -1149,7 +1159,7 @@ mountnfs(struct nfs_args *argp, struct mount *mp, struct sockaddr *nam, char *hst, u_char *krbname, int krbnamelen, u_char *dirpath, int dirlen, u_char *srvkrbname, int srvkrbnamelen, struct vnode **vpp, - struct ucred *cred, struct thread *td, int negnametimeo) + struct ucred *cred, struct thread *td, int nametimeo, int negnametimeo) { struct nfsmount *nmp; struct nfsnode *np; @@ -1216,7 +1226,9 @@ } vfs_getnewfsid(mp); nmp->nm_mountp = mp; - mtx_init(&nmp->nm_mtx, "NFSmount lock", NULL, MTX_DEF | MTX_DUPOK); + mtx_init(&nmp->nm_mtx, "NFSmount lock", NULL, MTX_DEF | MTX_DUPOK); + + nmp->nm_nametimeo = nametimeo; nmp->nm_negnametimeo = negnametimeo; nfs_decode_args(mp, nmp, argp, hst, cred, td); Index: sys/fs/nfsclient/nfsmount.h =================================================================== --- sys/fs/nfsclient/nfsmount.h (revision 225463) +++ sys/fs/nfsclient/nfsmount.h (working copy) @@ -66,6 +66,7 @@ u_int64_t nm_maxfilesize; /* maximum file size */ int nm_tprintf_initial_delay; /* initial delay */ int nm_tprintf_delay; /* interval for messages */ + int nm_nametimeo; /* timeout for +ve entries (sec) */ int nm_negnametimeo; /* timeout for -ve entries (sec) */ /* Newnfs additions */ @@ -106,6 +107,10 @@ */ #define VFSTONFS(mp) ((struct nfsmount *)((mp)->mnt_data)) +#ifndef NFS_DEFAULT_NAMETIMEO +#define NFS_DEFAULT_NAMETIMEO 60 +#endif + #ifndef NFS_DEFAULT_NEGNAMETIMEO #define NFS_DEFAULT_NEGNAMETIMEO 60 #endif Index: sys/fs/nfsclient/nfs_clvnops.c =================================================================== --- sys/fs/nfsclient/nfs_clvnops.c (revision 225463) +++ sys/fs/nfsclient/nfs_clvnops.c (working copy) @@ -1026,7 +1026,8 @@ * We only accept a positive hit in the cache if the * change time of the file matches our cached copy. * Otherwise, we discard the cache entry and fallback - * to doing a lookup RPC. + * to doing a lookup RPC. We also only trust cache + * entries for less than nm_nametimeo seconds. * * To better handle stale file handles and attributes, * clear the attribute cache of this node if it is a @@ -1047,7 +1048,8 @@ mtx_unlock(&newnp->n_mtx); } if (nfscl_nodeleg(newvp, 0) == 0 || - (VOP_GETATTR(newvp, &vattr, cnp->cn_cred) == 0 && + ((u_int)(ticks - ncticks) < (nmp->nm_nametimeo * hz) && + VOP_GETATTR(newvp, &vattr, cnp->cn_cred) == 0 && timespeccmp(&vattr.va_ctime, &nctime, ==))) { NFSINCRGLOBAL(newnfsstats.lookupcache_hits); if (cnp->cn_nameiop != LOOKUP && Index: sys/nfsclient/nfs_vnops.c =================================================================== --- sys/nfsclient/nfs_vnops.c (revision 225463) +++ sys/nfsclient/nfs_vnops.c (working copy) @@ -960,7 +960,8 @@ * We only accept a positive hit in the cache if the * change time of the file matches our cached copy. * Otherwise, we discard the cache entry and fallback - * to doing a lookup RPC. + * to doing a lookup RPC. We also only trust cache + * entries for less than nm_nametimeo seconds. * * To better handle stale file handles and attributes, * clear the attribute cache of this node if it is a @@ -981,7 +982,8 @@ KDTRACE_NFS_ATTRCACHE_FLUSH_DONE(newvp); mtx_unlock(&newnp->n_mtx); } - if (VOP_GETATTR(newvp, &vattr, cnp->cn_cred) == 0 && + if ((u_int)(ticks - ncticks) < (nmp->nm_nametimeo * hz) && + VOP_GETATTR(newvp, &vattr, cnp->cn_cred) == 0 && timespeccmp(&vattr.va_ctime, &nctime, ==)) { nfsstats.lookupcache_hits++; if (cnp->cn_nameiop != LOOKUP && Index: sys/nfsclient/nfsmount.h =================================================================== --- sys/nfsclient/nfsmount.h (revision 225463) +++ sys/nfsclient/nfsmount.h (working copy) @@ -83,6 +83,7 @@ struct rpc_timers nm_timers[NFS_MAX_TIMER]; /* RTT Timers for rpcs */ char nm_principal[MNAMELEN]; /* GSS-API principal of server */ gss_OID nm_mech_oid; /* OID of selected GSS-API mechanism */ + int nm_nametimeo; /* timeout for +ve entries (sec) */ int nm_negnametimeo; /* timeout for -ve entries (sec) */ /* NFSv4 */ @@ -116,6 +117,10 @@ #define NFS_TPRINTF_DELAY 30 #endif +#ifndef NFS_DEFAULT_NAMETIMEO +#define NFS_DEFAULT_NAMETIMEO 60 +#endif + #ifndef NFS_DEFAULT_NEGNAMETIMEO #define NFS_DEFAULT_NEGNAMETIMEO 60 #endif Index: sys/nfsclient/nfs_vfsops.c =================================================================== --- sys/nfsclient/nfs_vfsops.c (revision 225463) +++ sys/nfsclient/nfs_vfsops.c (working copy) @@ -115,7 +115,7 @@ struct nfs_args *argp, const char *hostname); static int mountnfs(struct nfs_args *, struct mount *, struct sockaddr *, char *, struct vnode **, - struct ucred *cred, int); + struct ucred *cred, int, int); static void nfs_getnlminfo(struct vnode *, uint8_t *, size_t *, struct sockaddr_storage *, int *, off_t *, struct timeval *); @@ -557,8 +557,8 @@ int error; nam = sodupsockaddr((struct sockaddr *)sin, M_WAITOK); - if ((error = mountnfs(args, mp, nam, path, vpp, - td->td_ucred, NFS_DEFAULT_NEGNAMETIMEO)) != 0) { + if ((error = mountnfs(args, mp, nam, path, vpp, td->td_ucred, + NFS_DEFAULT_NAMETIMEO, NFS_DEFAULT_NEGNAMETIMEO)) != 0) { printf("nfs_mountroot: mount %s on /: %d\n", path, error); return (error); } @@ -786,6 +786,7 @@ "wsize", "rsize", "retrans", "acregmin", "acregmax", "acdirmin", "acdirmax", "deadthresh", "hostname", "timeout", "addr", "fh", "nfsv3", "sec", "maxgroups", "principal", "negnametimeo", "nocto", "wcommitsize", + "nametimeo", NULL }; /* @@ -834,6 +835,7 @@ size_t len; u_char nfh[NFSX_V3FHMAX]; char *opt; + int nametimeo = NFS_DEFAULT_NAMETIMEO; int negnametimeo = NFS_DEFAULT_NEGNAMETIMEO; has_nfs_args_opt = 0; @@ -1056,6 +1058,14 @@ } args.flags |= NFSMNT_MAXGRPS; } + if (vfs_getopt(mp->mnt_optnew, "nametimeo", (void **)&opt, NULL) == 0) { + ret = sscanf(opt, "%d", &nametimeo); + if (ret != 1 || nametimeo < 0) { + vfs_mount_error(mp, "illegal nametimeo: %s", opt); + error = EINVAL; + goto out; + } + } if (vfs_getopt(mp->mnt_optnew, "negnametimeo", (void **)&opt, NULL) == 0) { ret = sscanf(opt, "%d", &negnametimeo); @@ -1163,7 +1173,7 @@ goto out; } error = mountnfs(&args, mp, nam, args.hostname, &vp, - curthread->td_ucred, negnametimeo); + curthread->td_ucred, nametimeo, negnametimeo); out: if (!error) { MNT_ILOCK(mp); @@ -1205,7 +1215,8 @@ */ static int mountnfs(struct nfs_args *argp, struct mount *mp, struct sockaddr *nam, - char *hst, struct vnode **vpp, struct ucred *cred, int negnametimeo) + char *hst, struct vnode **vpp, struct ucred *cred, int nametimeo, + int negnametimeo) { struct nfsmount *nmp; struct nfsnode *np; @@ -1255,6 +1266,7 @@ nmp->nm_numgrps = NFS_MAXGRPS; nmp->nm_readahead = NFS_DEFRAHEAD; nmp->nm_deadthresh = NFS_MAXDEADTHRESH; + nmp->nm_nametimeo = nametimeo; nmp->nm_negnametimeo = negnametimeo; nmp->nm_tprintf_delay = nfs_tprintf_delay; if (nmp->nm_tprintf_delay < 0)