cache_lookup_linked(): We can't use the name to decide how to lock the dir,

since the name refers to the child (found object) not the parent (the thing
that's being locked).

Fix it by always doing rw_tryenter().  There's not much to be won by
optimising for the contended case, and were this routine doing lockless
lookups (the eventual goal) it wouldn't be hanging around waiting for
changes either.
This commit is contained in:
ad 2020-04-23 22:58:36 +00:00
parent f6da483c1a
commit 2d6f5a05b2
1 changed files with 4 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_cache.c,v 1.140 2020/04/22 21:35:52 ad Exp $ */
/* $NetBSD: vfs_cache.c,v 1.141 2020/04/23 22:58:36 ad Exp $ */
/*-
* Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@ -172,7 +172,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.140 2020/04/22 21:35:52 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.141 2020/04/23 22:58:36 ad Exp $");
#define __NAMECACHE_PRIVATE
#ifdef _KERNEL_OPT
@ -668,12 +668,8 @@ cache_lookup_linked(struct vnode *dvp, const char *name, size_t namelen,
* on the lock as child -> parent is the wrong direction.
*/
if (*plock != &dvi->vi_nc_lock) {
if (namelen == 2 && name[0] == '.' && name[1] == '.') {
if (!rw_tryenter(&dvi->vi_nc_lock, RW_READER)) {
return false;
}
} else {
rw_enter(&dvi->vi_nc_lock, RW_READER);
if (!rw_tryenter(&dvi->vi_nc_lock, RW_READER)) {
return false;
}
if (*plock != NULL) {
rw_exit(*plock);