svn commit: r207634 - stable/7/sys/nfsclient
John Baldwin
jhb at FreeBSD.org
Tue May 4 21:21:05 UTC 2010
Author: jhb
Date: Tue May 4 21:21:05 2010
New Revision: 207634
URL: http://svn.freebsd.org/changeset/base/207634
Log:
MFC: 202767,202774
Add a timeout for the negative name cache entries in the NFS client.
This avoids a bogus negative name cache entry from persisting forever
when another client creates an entry with the same name within the
same NFS server time of day clock tick. Unlike 8.x and later, the
timeout is only adjustable via a system-wide sysctl
(vfs.nfs.negative_name_timeout) rather than a mount option. Setting
the timeout to 0 disables negative name caching.
I also fixed one obvious typo where args.timeo should be
args.maxgrouplist.
Modified:
stable/7/sys/nfsclient/nfs_vfsops.c
stable/7/sys/nfsclient/nfs_vnops.c
stable/7/sys/nfsclient/nfsmount.h
stable/7/sys/nfsclient/nfsnode.h
Modified: stable/7/sys/nfsclient/nfs_vfsops.c
==============================================================================
--- stable/7/sys/nfsclient/nfs_vfsops.c Tue May 4 21:16:01 2010 (r207633)
+++ stable/7/sys/nfsclient/nfs_vfsops.c Tue May 4 21:21:05 2010 (r207634)
@@ -951,7 +951,7 @@ nfs_mount(struct mount *mp, struct threa
}
if (vfs_getopt(mp->mnt_optnew, "maxgroups", (void **)&opt, NULL) == 0) {
ret = sscanf(opt, "%d", &args.maxgrouplist);
- if (ret != 1 || args.timeo <= 0) {
+ if (ret != 1 || args.maxgrouplist <= 0) {
vfs_mount_error(mp, "illegal maxgroups: %s",
opt);
error = EINVAL;
Modified: stable/7/sys/nfsclient/nfs_vnops.c
==============================================================================
--- stable/7/sys/nfsclient/nfs_vnops.c Tue May 4 21:16:01 2010 (r207633)
+++ stable/7/sys/nfsclient/nfs_vnops.c Tue May 4 21:21:05 2010 (r207634)
@@ -225,6 +225,10 @@ int nfs_directio_enable = 0;
SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs_directio_enable, CTLFLAG_RW,
&nfs_directio_enable, 0, "Enable NFS directio");
+static u_int negnametimeo = NFS_DEFAULT_NEGNAMETIMEO;
+SYSCTL_UINT(_vfs_nfs, OID_AUTO, negative_name_timeout, CTLFLAG_RW,
+ &negnametimeo, 0, "Negative name cache entry timeout");
+
/*
* This sysctl allows other processes to mmap a file that has been opened
* O_DIRECT by a process. In general, having processes mmap the file while
@@ -918,9 +922,12 @@ nfs_lookup(struct vop_lookup_args *ap)
* We only accept a negative hit in the cache if the
* modification time of the parent directory matches
* our cached copy. Otherwise, we discard all of the
- * negative cache entries for this directory.
+ * negative cache entries for this directory. We also
+ * only trust -ve cache entries for less than
+ * negnametimeo seconds.
*/
- if (VOP_GETATTR(dvp, &vattr, cnp->cn_cred, td) == 0 &&
+ if ((u_int)(ticks - np->n_dmtime_ticks) < (negnametimeo * hz) &&
+ VOP_GETATTR(dvp, &vattr, cnp->cn_cred, td) == 0 &&
vattr.va_mtime.tv_sec == np->n_dmtime) {
nfsstats.lookupcache_hits++;
return (ENOENT);
@@ -1063,8 +1070,10 @@ nfsmout:
*/
mtx_lock(&np->n_mtx);
if (np->n_dmtime <= dmtime) {
- if (np->n_dmtime == 0)
+ if (np->n_dmtime == 0) {
np->n_dmtime = dmtime;
+ np->n_dmtime_ticks = ticks;
+ }
mtx_unlock(&np->n_mtx);
cache_enter(dvp, NULL, cnp);
} else
Modified: stable/7/sys/nfsclient/nfsmount.h
==============================================================================
--- stable/7/sys/nfsclient/nfsmount.h Tue May 4 21:16:01 2010 (r207633)
+++ stable/7/sys/nfsclient/nfsmount.h Tue May 4 21:21:05 2010 (r207634)
@@ -114,6 +114,10 @@ struct nfsmount {
#define NFS_TPRINTF_DELAY 30
#endif
+#ifndef NFS_DEFAULT_NEGNAMETIMEO
+#define NFS_DEFAULT_NEGNAMETIMEO 60
+#endif
+
#endif
#endif
Modified: stable/7/sys/nfsclient/nfsnode.h
==============================================================================
--- stable/7/sys/nfsclient/nfsnode.h Tue May 4 21:16:01 2010 (r207633)
+++ stable/7/sys/nfsclient/nfsnode.h Tue May 4 21:21:05 2010 (r207634)
@@ -110,6 +110,7 @@ struct nfsnode {
struct timespec n_mtime; /* Prev modify time. */
time_t n_ctime; /* Prev create time. */
time_t n_dmtime; /* Prev dir modify time. */
+ int n_dmtime_ticks; /* Tick of -ve cache entry */
time_t n_expiry; /* Lease expiry time */
nfsfh_t *n_fhp; /* NFS File Handle */
struct vnode *n_vnode; /* associated vnode */
More information about the svn-src-stable-7
mailing list