From c3ce5f02ead5992c12c70975ea4c368b64cece7d Mon Sep 17 00:00:00 2001 From: fvdl Date: Sun, 12 Oct 1997 23:13:35 +0000 Subject: [PATCH] Do negative lookup caching. Use a timestamp of the oldest negative cache entry, so it can be checked against directory modification time for validity. --- sys/nfs/nfs_vnops.c | 27 ++++++++++++++++++++++++--- sys/nfs/nfsnode.h | 3 ++- sys/nfs/nfsproto.h | 4 ++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index 589842e658bc..925bf12f4fe3 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_vnops.c,v 1.81 1997/10/10 01:53:30 fvdl Exp $ */ +/* $NetBSD: nfs_vnops.c,v 1.82 1997/10/12 23:13:35 fvdl Exp $ */ /* * Copyright (c) 1989, 1993 @@ -810,10 +810,20 @@ nfs_lookup(v) wantparent = flags & (LOCKPARENT|WANTPARENT); nmp = VFSTONFS(dvp->v_mount); np = VTONFS(dvp); - if ((error = cache_lookup(dvp, vpp, cnp)) != 0 && error != ENOENT) { + if ((error = cache_lookup(dvp, vpp, cnp)) != 0) { struct vattr vattr; int vpid; + if (error == ENOENT) { + if (!VOP_GETATTR(dvp, &vattr, cnp->cn_cred, + cnp->cn_proc) && vattr.va_mtime.tv_sec == + VTONFS(dvp)->n_nctime) + return (ENOENT); + cache_purge(dvp); + np->n_nctime = 0; + goto dorpc; + } + newvp = *vpp; vpid = newvp->v_id; /* @@ -845,6 +855,7 @@ nfs_lookup(v) } *vpp = NULLVP; } +dorpc: error = 0; newvp = NULLVP; nfsstats.lookupcache_misses++; @@ -913,6 +924,13 @@ nfs_lookup(v) *vpp = newvp; nfsm_reqdone; if (error) { + if (error == ENOENT && (cnp->cn_flags & MAKEENTRY) && + cnp->cn_nameiop != CREATE) { + if (VTONFS(dvp)->n_nctime == 0) + VTONFS(dvp)->n_nctime = + VTONFS(dvp)->n_vattr.va_mtime.tv_sec; + cache_enter(dvp, NULL, cnp); + } if (newvp != NULLVP) vrele(newvp); if ((cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME) && @@ -1861,8 +1879,11 @@ nfs_mkdir(v) if (error) { if (newvp) vrele(newvp); - } else + } else { + if (cnp->cn_flags & MAKEENTRY) + cache_enter(dvp, newvp, cnp); *ap->a_vpp = newvp; + } FREE(cnp->cn_pnbuf, M_NAMEI); vrele(dvp); return (error); diff --git a/sys/nfs/nfsnode.h b/sys/nfs/nfsnode.h index dbe8236f4a62..425554254ccf 100644 --- a/sys/nfs/nfsnode.h +++ b/sys/nfs/nfsnode.h @@ -1,4 +1,4 @@ -/* $NetBSD: nfsnode.h,v 1.21 1997/10/10 01:53:32 fvdl Exp $ */ +/* $NetBSD: nfsnode.h,v 1.22 1997/10/12 23:13:38 fvdl Exp $ */ /* * Copyright (c) 1989, 1993 @@ -109,6 +109,7 @@ struct nfsnode { time_t n_attrstamp; /* Attr. cache timestamp */ time_t n_mtime; /* Prev modify time. */ time_t n_ctime; /* Prev create time. */ + time_t n_nctime; /* Last neg cache entry (dir) */ time_t n_expiry; /* Lease expiry time */ nfsfh_t *n_fhp; /* NFS File Handle */ struct vnode *n_vnode; /* associated vnode */ diff --git a/sys/nfs/nfsproto.h b/sys/nfs/nfsproto.h index ffc31533ab77..5813d7d9cf15 100644 --- a/sys/nfs/nfsproto.h +++ b/sys/nfs/nfsproto.h @@ -1,4 +1,4 @@ -/* $NetBSD: nfsproto.h,v 1.3 1997/10/10 01:53:33 fvdl Exp $ */ +/* $NetBSD: nfsproto.h,v 1.4 1997/10/12 23:13:39 fvdl Exp $ */ /* * Copyright (c) 1989, 1993 @@ -252,7 +252,7 @@ typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5, * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4. */ #ifndef NFS_SMALLFH -#define NFS_SMALLFH 48 +#define NFS_SMALLFH 44 #endif union nfsfh { fhandle_t fh_generic;