From 8d615f3e1892eff0d48dda09cb848dfa6953a529 Mon Sep 17 00:00:00 2001 From: yamt Date: Thu, 6 May 2004 22:02:02 +0000 Subject: [PATCH] cache_enter: when we found a duplicate entry, simply overwrite it rather than leaving a stale entry. --- sys/kern/vfs_cache.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 54d62efc3ee7..bb99aa97d3bd 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_cache.c,v 1.57 2004/05/02 12:00:34 pk Exp $ */ +/* $NetBSD: vfs_cache.c,v 1.58 2004/05/06 22:02:02 yamt Exp $ */ /* * Copyright (c) 1989, 1993 @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.57 2004/05/02 12:00:34 pk Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.58 2004/05/06 22:02:02 yamt Exp $"); #include "opt_ddb.h" #include "opt_revcache.h" @@ -418,7 +418,16 @@ cache_enter(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) * Free the cache slot at head of lru chain. */ simple_lock(&namecache_slock); - if (numcache < numvnodes) { + + /* + * Concurrent lookups in the same directory may race for a + * cache entry. if there's a duplicated entry, overwrite it. + */ + ncp = cache_lookup_entry(dvp, cnp); + if (ncp) { + cache_remove(ncp); + KASSERT(cache_lookup_entry(dvp, cnp) == NULL); + } else if (numcache < numvnodes) { numcache++; simple_unlock(&namecache_slock); ncp = pool_get(&namecache_pool, PR_WAITOK); @@ -431,16 +440,6 @@ cache_enter(struct vnode *dvp, struct vnode *vp, struct componentname *cnp) return; } - /* - * Concurrent lookups in the same directory may race for a - * cache entry. If we loose, free our tentative entry and return. - */ - if (cache_lookup_entry(dvp, cnp) != NULL) { - cache_free(ncp); - simple_unlock(&namecache_slock); - return; - } - /* Grab the vnode we just found. */ ncp->nc_vp = vp; if (vp == NULL) {