Uncut&paste cache_lookup().

This unifies several times in theory indentical 50 lines of code.

The filesystems have a new method: vop_cachedlookup, which is the
meat of the lookup, and use vfs_cache_lookup() for their vop_lookup
method.  vfs_cache_lookup() will check the namecache and pass on
to the vop_cachedlookup method in case of a miss.

It's still the task of the individual filesystems to populate the
namecache with cache_enter().

Filesystems that do not use the namecache will just provide the
vop_lookup method as usual.
This commit is contained in:
Poul-Henning Kamp 1997-08-26 07:32:51 +00:00
parent a3bfefd3be
commit 0fa2443f0e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28787
25 changed files with 139 additions and 505 deletions

View File

@ -38,7 +38,7 @@
* from: @(#)ufs_lookup.c 7.33 (Berkeley) 5/19/91
*
* @(#)cd9660_lookup.c 8.2 (Berkeley) 1/23/94
* $Id: cd9660_lookup.c,v 1.15 1997/03/08 16:09:38 bde Exp $
* $Id: cd9660_lookup.c,v 1.16 1997/08/02 14:31:18 bde Exp $
*/
#include <sys/param.h>
@ -89,7 +89,7 @@
*/
int
cd9660_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
@ -146,59 +146,7 @@ cd9660_lookup(ap)
/*
* We now have a segment name to search for, and a directory to search.
*
* Before tediously performing a linear scan of the directory,
* check the name cache to see if the directory/name pair
* we are looking for is known already.
*/
if ((error = cache_lookup(vdp, vpp, cnp))) {
u_long vpid; /* capability number of vnode */
if (error == ENOENT)
return (error);
#ifdef PARANOID
if ((vdp->v_flag & VROOT) && (flags & ISDOTDOT))
panic("cd9660_lookup: .. through root");
#endif
/*
* Get the next vnode in the path.
* See comment below starting `Step through' for
* an explaination of the locking protocol.
*/
pdp = vdp;
dp = VTOI(*vpp);
vdp = *vpp;
vpid = vdp->v_id;
if (pdp == vdp) {
VREF(vdp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(pdp, 0, p);
error = vget(vdp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(pdp, LK_EXCLUSIVE, p);
} else {
error = vget(vdp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
/*
* Check that the capability number did not change
* while we were waiting for the lock.
*/
if (!error) {
if (vpid == vdp->v_id)
return (0);
vput(vdp);
if (lockparent && pdp != vdp && (flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
if (error = vn_lock(pdp, LK_EXCLUSIVE, p))
return (error);
vdp = pdp;
dp = VTOI(pdp);
*vpp = NULL;
}
len = cnp->cn_namelen;
name = cnp->cn_nameptr;

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)cd9660_node.h 8.6 (Berkeley) 5/14/95
* $Id: cd9660_node.h,v 1.10 1997/02/22 09:38:49 peter Exp $
* $Id: cd9660_node.h,v 1.11 1997/04/14 18:15:45 phk Exp $
*/
/*
@ -95,7 +95,7 @@ struct iso_node {
/*
* Prototypes for ISOFS vnode operations
*/
int cd9660_lookup __P((struct vop_lookup_args *));
int cd9660_lookup __P((struct vop_cachedlookup_args *));
int cd9660_inactive __P((struct vop_inactive_args *));
int cd9660_reclaim __P((struct vop_reclaim_args *));
int cd9660_bmap __P((struct vop_bmap_args *));

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95
* $Id: cd9660_vnops.c,v 1.35 1997/04/15 08:05:08 bde Exp $
* $Id: cd9660_vnops.c,v 1.36 1997/08/25 10:26:18 kato Exp $
*/
#include <sys/param.h>
@ -1031,7 +1031,8 @@ vop_t **cd9660_vnodeop_p;
struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)cd9660_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup }, /* lookup */
{ &vop_cachedlookup_desc, (vop_t *)cd9660_lookup }, /* lookup */
{ &vop_create_desc, (vop_t *)cd9660_create }, /* create */
{ &vop_mknod_desc, (vop_t *)cd9660_mknod }, /* mknod */
{ &vop_open_desc, (vop_t *)cd9660_open }, /* open */

View File

@ -1,4 +1,4 @@
/* $Id: denode.h,v 1.11 1997/02/22 09:40:44 peter Exp $ */
/* $Id: denode.h,v 1.12 1997/02/26 14:23:09 bde Exp $ */
/* $NetBSD: denode.h,v 1.8 1994/08/21 18:43:49 ws Exp $ */
/*-
@ -226,7 +226,7 @@ struct defid {
extern vop_t **msdosfs_vnodeop_p;
int msdosfs_lookup __P((struct vop_lookup_args *));
int msdosfs_lookup __P((struct vop_cachedlookup_args *));
int msdosfs_inactive __P((struct vop_inactive_args *));
int msdosfs_reclaim __P((struct vop_reclaim_args *));

View File

@ -1,4 +1,4 @@
/* $Id: msdosfs_lookup.c,v 1.10 1997/02/22 09:40:47 peter Exp $ */
/* $Id: msdosfs_lookup.c,v 1.11 1997/02/26 14:23:13 bde Exp $ */
/* $NetBSD: msdosfs_lookup.c,v 1.14 1994/08/21 18:44:07 ws Exp $ */
/*-
@ -82,7 +82,7 @@ static int markdeleted __P((struct msdosfsmount *pmp, u_long dirclust,
*/
int
msdosfs_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
@ -140,61 +140,6 @@ msdosfs_lookup(ap)
if ((dp->de_Attributes & ATTR_DIRECTORY) == 0)
return ENOTDIR;
/*
* See if the component of the pathname we are looking for is in
* the directory cache. If so then do a few things and return.
*/
error = cache_lookup(vdp, vpp, cnp);
if (error) {
int vpid;
if (error == ENOENT)
return error;
pdp = vdp;
vdp = *vpp;
dp = VTODE(vdp);
vpid = vdp->v_id;
if (pdp == vdp) {
VREF(vdp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(pdp, 0, p);
error = vget(vdp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(pdp, LK_EXCLUSIVE, p);
} else {
error = vget(vdp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
if (!error) {
if (vpid == vdp->v_id) {
#ifdef MSDOSFS_DEBUG
printf("msdosfs_lookup(): cache hit, vnode %08x, file %s\n",
vdp, dp->de_Name);
#endif
#ifdef PC98
/*
* 1024 byte/sector support
*/
if (pmp->pm_BytesPerSec == 1024)
vdp->v_flag |= 0x10000;
#endif
return 0;
}
vput(vdp);
if (lockparent && pdp != vdp && (flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
error = vn_lock(pdp, LK_EXCLUSIVE, p);
if (error)
return error;
vdp = pdp;
dp = VTODE(vdp);
*vpp = NULL;
}
/*
* If they are going after the . or .. entry in the root directory,
* they won't find it. DOS filesystems don't have them in the root

View File

@ -1,4 +1,4 @@
/* $Id: msdosfs_vnops.c,v 1.41 1997/04/10 14:56:49 bde Exp $ */
/* $Id: msdosfs_vnops.c,v 1.42 1997/05/17 18:32:40 phk Exp $ */
/* $NetBSD: msdosfs_vnops.c,v 1.20 1994/08/21 18:44:13 ws Exp $ */
/*-
@ -1987,7 +1987,8 @@ msdosfs_pathconf(ap)
vop_t **msdosfs_vnodeop_p;
static struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)msdosfs_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup }, /* lookup */
{ &vop_cachedlookup_desc, (vop_t *)msdosfs_lookup }, /* lookup */
{ &vop_create_desc, (vop_t *)msdosfs_create }, /* create */
{ &vop_mknod_desc, (vop_t *)msdosfs_mknod }, /* mknod */
{ &vop_open_desc, (vop_t *)msdosfs_open }, /* open */

View File

@ -78,7 +78,7 @@ int ext2_truncate __P((struct vop_truncate_args *));
int ext2_update __P((struct vop_update_args *));
int ext2_valloc __P((struct vop_valloc_args *));
int ext2_vfree __P((struct vop_vfree_args *));
int ext2_lookup __P((struct vop_lookup_args *));
int ext2_lookup __P((struct vop_cachedlookup_args *));
int ext2_readdir __P((struct vop_readdir_args *));
void ext2_print_dinode __P((struct dinode *));
void ext2_print_inode __P((struct inode *));

View File

@ -268,7 +268,7 @@ printf("ext2_readdir called uio->uio_offset %d uio->uio_resid %d count %d \n",
*/
int
ext2_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
@ -321,55 +321,7 @@ ext2_lookup(ap)
/*
* We now have a segment name to search for, and a directory to search.
*
* Before tediously performing a linear scan of the directory,
* check the name cache to see if the directory/name pair
* we are looking for is known already.
*/
if (error = cache_lookup(vdp, vpp, cnp)) {
int vpid; /* capability number of vnode */
if (error == ENOENT)
return (error);
/*
* Get the next vnode in the path.
* See comment below starting `Step through' for
* an explaination of the locking protocol.
*/
pdp = vdp;
dp = VTOI(*vpp);
vdp = *vpp;
vpid = vdp->v_id;
if (pdp == vdp) { /* lookup on "." */
VREF(vdp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(pdp, 0, p);
error = vget(vdp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(pdp, LK_EXCLUSIVE, p);
} else {
error = vget(vdp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
/*
* Check that the capability number did not change
* while we were waiting for the lock.
*/
if (!error) {
if (vpid == vdp->v_id)
return (0);
vput(vdp);
if (lockparent && pdp != vdp && (flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
if (error = vn_lock(pdp, LK_EXCLUSIVE, p))
return (error);
vdp = pdp;
dp = VTOI(pdp);
*vpp = NULL;
}
/*
* Suppress search for slots unless creating

View File

@ -84,7 +84,8 @@ static int ext2_write __P((struct vop_write_args *));
vop_t **ext2_vnodeop_p;
static struct vnodeopv_entry_desc ext2_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)ext2_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup }, /* lookup */
{ &vop_cachedlookup_desc, (vop_t *)ext2_lookup }, /* lookup */
{ &vop_create_desc, (vop_t *)ufs_create }, /* create */
{ &vop_mknod_desc, (vop_t *)ufs_mknod }, /* mknod */
{ &vop_open_desc, (vop_t *)ufs_open }, /* open */

View File

@ -78,7 +78,7 @@ int ext2_truncate __P((struct vop_truncate_args *));
int ext2_update __P((struct vop_update_args *));
int ext2_valloc __P((struct vop_valloc_args *));
int ext2_vfree __P((struct vop_vfree_args *));
int ext2_lookup __P((struct vop_lookup_args *));
int ext2_lookup __P((struct vop_cachedlookup_args *));
int ext2_readdir __P((struct vop_readdir_args *));
void ext2_print_dinode __P((struct dinode *));
void ext2_print_inode __P((struct inode *));

View File

@ -268,7 +268,7 @@ printf("ext2_readdir called uio->uio_offset %d uio->uio_resid %d count %d \n",
*/
int
ext2_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
@ -321,55 +321,7 @@ ext2_lookup(ap)
/*
* We now have a segment name to search for, and a directory to search.
*
* Before tediously performing a linear scan of the directory,
* check the name cache to see if the directory/name pair
* we are looking for is known already.
*/
if (error = cache_lookup(vdp, vpp, cnp)) {
int vpid; /* capability number of vnode */
if (error == ENOENT)
return (error);
/*
* Get the next vnode in the path.
* See comment below starting `Step through' for
* an explaination of the locking protocol.
*/
pdp = vdp;
dp = VTOI(*vpp);
vdp = *vpp;
vpid = vdp->v_id;
if (pdp == vdp) { /* lookup on "." */
VREF(vdp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(pdp, 0, p);
error = vget(vdp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(pdp, LK_EXCLUSIVE, p);
} else {
error = vget(vdp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
/*
* Check that the capability number did not change
* while we were waiting for the lock.
*/
if (!error) {
if (vpid == vdp->v_id)
return (0);
vput(vdp);
if (lockparent && pdp != vdp && (flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
if (error = vn_lock(pdp, LK_EXCLUSIVE, p))
return (error);
vdp = pdp;
dp = VTOI(pdp);
*vpp = NULL;
}
/*
* Suppress search for slots unless creating

View File

@ -84,7 +84,8 @@ static int ext2_write __P((struct vop_write_args *));
vop_t **ext2_vnodeop_p;
static struct vnodeopv_entry_desc ext2_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)ext2_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup }, /* lookup */
{ &vop_cachedlookup_desc, (vop_t *)ext2_lookup }, /* lookup */
{ &vop_create_desc, (vop_t *)ufs_create }, /* create */
{ &vop_mknod_desc, (vop_t *)ufs_mknod }, /* mknod */
{ &vop_open_desc, (vop_t *)ufs_open }, /* open */

View File

@ -38,7 +38,7 @@
* from: @(#)ufs_lookup.c 7.33 (Berkeley) 5/19/91
*
* @(#)cd9660_lookup.c 8.2 (Berkeley) 1/23/94
* $Id: cd9660_lookup.c,v 1.15 1997/03/08 16:09:38 bde Exp $
* $Id: cd9660_lookup.c,v 1.16 1997/08/02 14:31:18 bde Exp $
*/
#include <sys/param.h>
@ -89,7 +89,7 @@
*/
int
cd9660_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
@ -146,59 +146,7 @@ cd9660_lookup(ap)
/*
* We now have a segment name to search for, and a directory to search.
*
* Before tediously performing a linear scan of the directory,
* check the name cache to see if the directory/name pair
* we are looking for is known already.
*/
if ((error = cache_lookup(vdp, vpp, cnp))) {
u_long vpid; /* capability number of vnode */
if (error == ENOENT)
return (error);
#ifdef PARANOID
if ((vdp->v_flag & VROOT) && (flags & ISDOTDOT))
panic("cd9660_lookup: .. through root");
#endif
/*
* Get the next vnode in the path.
* See comment below starting `Step through' for
* an explaination of the locking protocol.
*/
pdp = vdp;
dp = VTOI(*vpp);
vdp = *vpp;
vpid = vdp->v_id;
if (pdp == vdp) {
VREF(vdp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(pdp, 0, p);
error = vget(vdp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(pdp, LK_EXCLUSIVE, p);
} else {
error = vget(vdp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
/*
* Check that the capability number did not change
* while we were waiting for the lock.
*/
if (!error) {
if (vpid == vdp->v_id)
return (0);
vput(vdp);
if (lockparent && pdp != vdp && (flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
if (error = vn_lock(pdp, LK_EXCLUSIVE, p))
return (error);
vdp = pdp;
dp = VTOI(pdp);
*vpp = NULL;
}
len = cnp->cn_namelen;
name = cnp->cn_nameptr;

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)cd9660_node.h 8.6 (Berkeley) 5/14/95
* $Id: cd9660_node.h,v 1.10 1997/02/22 09:38:49 peter Exp $
* $Id: cd9660_node.h,v 1.11 1997/04/14 18:15:45 phk Exp $
*/
/*
@ -95,7 +95,7 @@ struct iso_node {
/*
* Prototypes for ISOFS vnode operations
*/
int cd9660_lookup __P((struct vop_lookup_args *));
int cd9660_lookup __P((struct vop_cachedlookup_args *));
int cd9660_inactive __P((struct vop_inactive_args *));
int cd9660_reclaim __P((struct vop_reclaim_args *));
int cd9660_bmap __P((struct vop_bmap_args *));

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95
* $Id: cd9660_vnops.c,v 1.35 1997/04/15 08:05:08 bde Exp $
* $Id: cd9660_vnops.c,v 1.36 1997/08/25 10:26:18 kato Exp $
*/
#include <sys/param.h>
@ -1031,7 +1031,8 @@ vop_t **cd9660_vnodeop_p;
struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)cd9660_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup }, /* lookup */
{ &vop_cachedlookup_desc, (vop_t *)cd9660_lookup }, /* lookup */
{ &vop_create_desc, (vop_t *)cd9660_create }, /* create */
{ &vop_mknod_desc, (vop_t *)cd9660_mknod }, /* mknod */
{ &vop_open_desc, (vop_t *)cd9660_open }, /* open */

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_cache.c 8.5 (Berkeley) 3/22/95
* $Id: vfs_cache.c,v 1.25 1997/05/04 09:17:28 phk Exp $
* $Id: vfs_cache.c,v 1.26 1997/08/04 07:31:36 phk Exp $
*/
#include <sys/param.h>
@ -336,3 +336,86 @@ cache_purgevfs(mp)
}
}
}
/*
* Perform canonical checks and cache lookup and pass on to filesystem
* through the vop_cachedlookup only if needed.
*/
int
vfs_cache_lookup(ap)
struct vop_lookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
} */ *ap;
{
struct vnode *vdp;
struct vnode *pdp;
int lockparent;
int error;
struct vnode **vpp = ap->a_vpp;
struct componentname *cnp = ap->a_cnp;
struct ucred *cred = cnp->cn_cred;
int flags = cnp->cn_flags;
struct proc *p = cnp->cn_proc;
u_long vpid; /* capability number of vnode */
*vpp = NULL;
vdp = ap->a_dvp;
lockparent = flags & LOCKPARENT;
if (vdp->v_type != VDIR)
return (ENOTDIR);
if ((flags & ISLASTCN) && (vdp->v_mount->mnt_flag & MNT_RDONLY) &&
(cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
return (EROFS);
error = VOP_ACCESS(vdp, VEXEC, cred, cnp->cn_proc);
if (error)
return (error);
error = cache_lookup(vdp, vpp, cnp);
if (!error)
return (VCALL(vdp, VOFFSET(vop_cachedlookup),
(struct vop_cachedlookup_args *)ap));
if (error == ENOENT)
return (error);
pdp = vdp;
vdp = *vpp;
vpid = vdp->v_id;
if (pdp == vdp) { /* lookup on "." */
VREF(vdp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(pdp, 0, p);
error = vget(vdp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(pdp, LK_EXCLUSIVE, p);
} else {
error = vget(vdp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
/*
* Check that the capability number did not change
* while we were waiting for the lock.
*/
if (!error) {
if (vpid == vdp->v_id)
return (0);
vput(vdp);
if (lockparent && pdp != vdp && (flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
error = vn_lock(pdp, LK_EXCLUSIVE, p);
if (error)
return (error);
return (VCALL(vdp, VOFFSET(vop_cachedlookup),
(struct vop_cachedlookup_args *)ap));
}

View File

@ -1,4 +1,4 @@
/* $Id: denode.h,v 1.11 1997/02/22 09:40:44 peter Exp $ */
/* $Id: denode.h,v 1.12 1997/02/26 14:23:09 bde Exp $ */
/* $NetBSD: denode.h,v 1.8 1994/08/21 18:43:49 ws Exp $ */
/*-
@ -226,7 +226,7 @@ struct defid {
extern vop_t **msdosfs_vnodeop_p;
int msdosfs_lookup __P((struct vop_lookup_args *));
int msdosfs_lookup __P((struct vop_cachedlookup_args *));
int msdosfs_inactive __P((struct vop_inactive_args *));
int msdosfs_reclaim __P((struct vop_reclaim_args *));

View File

@ -1,4 +1,4 @@
/* $Id: msdosfs_lookup.c,v 1.10 1997/02/22 09:40:47 peter Exp $ */
/* $Id: msdosfs_lookup.c,v 1.11 1997/02/26 14:23:13 bde Exp $ */
/* $NetBSD: msdosfs_lookup.c,v 1.14 1994/08/21 18:44:07 ws Exp $ */
/*-
@ -82,7 +82,7 @@ static int markdeleted __P((struct msdosfsmount *pmp, u_long dirclust,
*/
int
msdosfs_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
@ -140,61 +140,6 @@ msdosfs_lookup(ap)
if ((dp->de_Attributes & ATTR_DIRECTORY) == 0)
return ENOTDIR;
/*
* See if the component of the pathname we are looking for is in
* the directory cache. If so then do a few things and return.
*/
error = cache_lookup(vdp, vpp, cnp);
if (error) {
int vpid;
if (error == ENOENT)
return error;
pdp = vdp;
vdp = *vpp;
dp = VTODE(vdp);
vpid = vdp->v_id;
if (pdp == vdp) {
VREF(vdp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(pdp, 0, p);
error = vget(vdp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(pdp, LK_EXCLUSIVE, p);
} else {
error = vget(vdp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
if (!error) {
if (vpid == vdp->v_id) {
#ifdef MSDOSFS_DEBUG
printf("msdosfs_lookup(): cache hit, vnode %08x, file %s\n",
vdp, dp->de_Name);
#endif
#ifdef PC98
/*
* 1024 byte/sector support
*/
if (pmp->pm_BytesPerSec == 1024)
vdp->v_flag |= 0x10000;
#endif
return 0;
}
vput(vdp);
if (lockparent && pdp != vdp && (flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
error = vn_lock(pdp, LK_EXCLUSIVE, p);
if (error)
return error;
vdp = pdp;
dp = VTODE(vdp);
*vpp = NULL;
}
/*
* If they are going after the . or .. entry in the root directory,
* they won't find it. DOS filesystems don't have them in the root

View File

@ -1,4 +1,4 @@
/* $Id: msdosfs_vnops.c,v 1.41 1997/04/10 14:56:49 bde Exp $ */
/* $Id: msdosfs_vnops.c,v 1.42 1997/05/17 18:32:40 phk Exp $ */
/* $NetBSD: msdosfs_vnops.c,v 1.20 1994/08/21 18:44:13 ws Exp $ */
/*-
@ -1987,7 +1987,8 @@ msdosfs_pathconf(ap)
vop_t **msdosfs_vnodeop_p;
static struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)msdosfs_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup }, /* lookup */
{ &vop_cachedlookup_desc, (vop_t *)msdosfs_lookup }, /* lookup */
{ &vop_create_desc, (vop_t *)msdosfs_create }, /* create */
{ &vop_mknod_desc, (vop_t *)msdosfs_mknod }, /* mknod */
{ &vop_open_desc, (vop_t *)msdosfs_open }, /* open */

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs_vnops.c 8.16 (Berkeley) 5/27/95
* $Id: nfs_vnops.c,v 1.54 1997/06/16 00:23:40 dyson Exp $
* $Id: nfs_vnops.c,v 1.55 1997/06/25 08:32:33 dfr Exp $
*/
@ -102,7 +102,7 @@ static int nfs_ioctl __P((struct vop_ioctl_args *));
static int nfs_select __P((struct vop_select_args *));
static int nfs_flush __P((struct vnode *,struct ucred *,int,struct proc *,int));
static int nfs_setattrrpc __P((struct vnode *,struct vattr *,struct ucred *,struct proc *));
static int nfs_lookup __P((struct vop_lookup_args *));
static int nfs_lookup __P((struct vop_cachedlookup_args *));
static int nfs_create __P((struct vop_create_args *));
static int nfs_mknod __P((struct vop_mknod_args *));
static int nfs_open __P((struct vop_open_args *));
@ -141,7 +141,8 @@ static int nfs_update __P((struct vop_update_args *));
vop_t **nfsv2_vnodeop_p;
static struct vnodeopv_entry_desc nfsv2_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)nfs_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup }, /* lookup */
{ &vop_cachedlookup_desc, (vop_t *)nfs_lookup }, /* lookup */
{ &vop_create_desc, (vop_t *)nfs_create }, /* create */
{ &vop_mknod_desc, (vop_t *)nfs_mknod }, /* mknod */
{ &vop_open_desc, (vop_t *)nfs_open }, /* open */
@ -837,7 +838,7 @@ nfs_setattrrpc(vp, vap, cred, procp)
*/
static int
nfs_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnodeop_desc *a_desc;
struct vnode *a_dvp;
struct vnode **a_vpp;
@ -872,55 +873,6 @@ nfs_lookup(ap)
wantparent = flags & (LOCKPARENT|WANTPARENT);
nmp = VFSTONFS(dvp->v_mount);
np = VTONFS(dvp);
if ((error = cache_lookup(dvp, vpp, cnp)) && error != ENOENT) {
struct vattr vattr;
int vpid;
if (error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, p)) {
*vpp = NULLVP;
return (error);
}
newvp = *vpp;
vpid = newvp->v_id;
/*
* See the comment starting `Step through' in ufs/ufs_lookup.c
* for an explanation of the locking protocol
*/
if (dvp == newvp) {
VREF(newvp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(dvp, 0, p);
error = vget(newvp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(dvp, LK_EXCLUSIVE, p);
} else {
error = vget(newvp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(dvp, 0, p);
}
if (!error) {
if (vpid == newvp->v_id) {
if (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred, p)
&& vattr.va_ctime.tv_sec == VTONFS(newvp)->n_ctime) {
nfsstats.lookupcache_hits++;
if (cnp->cn_nameiop != LOOKUP &&
(flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
return (0);
}
cache_purge(newvp);
}
vput(newvp);
if (lockparent && dvp != newvp && (flags & ISLASTCN))
VOP_UNLOCK(dvp, 0, p);
}
error = vn_lock(dvp, LK_EXCLUSIVE, p);
*vpp = NULLVP;
if (error)
return (error);
}
error = 0;
newvp = NULLVP;
nfsstats.lookupcache_misses++;

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs_vnops.c 8.16 (Berkeley) 5/27/95
* $Id: nfs_vnops.c,v 1.54 1997/06/16 00:23:40 dyson Exp $
* $Id: nfs_vnops.c,v 1.55 1997/06/25 08:32:33 dfr Exp $
*/
@ -102,7 +102,7 @@ static int nfs_ioctl __P((struct vop_ioctl_args *));
static int nfs_select __P((struct vop_select_args *));
static int nfs_flush __P((struct vnode *,struct ucred *,int,struct proc *,int));
static int nfs_setattrrpc __P((struct vnode *,struct vattr *,struct ucred *,struct proc *));
static int nfs_lookup __P((struct vop_lookup_args *));
static int nfs_lookup __P((struct vop_cachedlookup_args *));
static int nfs_create __P((struct vop_create_args *));
static int nfs_mknod __P((struct vop_mknod_args *));
static int nfs_open __P((struct vop_open_args *));
@ -141,7 +141,8 @@ static int nfs_update __P((struct vop_update_args *));
vop_t **nfsv2_vnodeop_p;
static struct vnodeopv_entry_desc nfsv2_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)nfs_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup }, /* lookup */
{ &vop_cachedlookup_desc, (vop_t *)nfs_lookup }, /* lookup */
{ &vop_create_desc, (vop_t *)nfs_create }, /* create */
{ &vop_mknod_desc, (vop_t *)nfs_mknod }, /* mknod */
{ &vop_open_desc, (vop_t *)nfs_open }, /* open */
@ -837,7 +838,7 @@ nfs_setattrrpc(vp, vap, cred, procp)
*/
static int
nfs_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnodeop_desc *a_desc;
struct vnode *a_dvp;
struct vnode **a_vpp;
@ -872,55 +873,6 @@ nfs_lookup(ap)
wantparent = flags & (LOCKPARENT|WANTPARENT);
nmp = VFSTONFS(dvp->v_mount);
np = VTONFS(dvp);
if ((error = cache_lookup(dvp, vpp, cnp)) && error != ENOENT) {
struct vattr vattr;
int vpid;
if (error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, p)) {
*vpp = NULLVP;
return (error);
}
newvp = *vpp;
vpid = newvp->v_id;
/*
* See the comment starting `Step through' in ufs/ufs_lookup.c
* for an explanation of the locking protocol
*/
if (dvp == newvp) {
VREF(newvp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(dvp, 0, p);
error = vget(newvp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(dvp, LK_EXCLUSIVE, p);
} else {
error = vget(newvp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(dvp, 0, p);
}
if (!error) {
if (vpid == newvp->v_id) {
if (!VOP_GETATTR(newvp, &vattr, cnp->cn_cred, p)
&& vattr.va_ctime.tv_sec == VTONFS(newvp)->n_ctime) {
nfsstats.lookupcache_hits++;
if (cnp->cn_nameiop != LOOKUP &&
(flags & ISLASTCN))
cnp->cn_flags |= SAVENAME;
return (0);
}
cache_purge(newvp);
}
vput(newvp);
if (lockparent && dvp != newvp && (flags & ISLASTCN))
VOP_UNLOCK(dvp, 0, p);
}
error = vn_lock(dvp, LK_EXCLUSIVE, p);
*vpp = NULLVP;
if (error)
return (error);
}
error = 0;
newvp = NULLVP;
nfsstats.lookupcache_misses++;

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)vnode.h 8.7 (Berkeley) 2/4/94
* $Id: vnode.h,v 1.44 1997/05/04 09:17:38 phk Exp $
* $Id: vnode.h,v 1.45 1997/08/18 03:29:08 fsmp Exp $
*/
#ifndef _SYS_VNODE_H_
@ -502,6 +502,7 @@ int vn_rdwr __P((enum uio_rw rw, struct vnode *vp, caddr_t base,
int len, off_t offset, enum uio_seg segflg, int ioflg,
struct ucred *cred, int *aresid, struct proc *p));
int vn_stat __P((struct vnode *vp, struct stat *sb, struct proc *p));
int vfs_cache_lookup __P((struct vop_lookup_args *ap));
int vfs_object_create __P((struct vnode *vp, struct proc *p,
struct ucred *cred, int waslocked));
int vn_writechk __P((struct vnode *vp));

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
* $Id: ffs_vnops.c,v 1.25 1997/03/22 06:53:30 bde Exp $
* $Id: ffs_vnops.c,v 1.26 1997/08/25 08:18:23 kato Exp $
*/
#include <sys/param.h>
@ -78,7 +78,8 @@ static int ffs_write __P((struct vop_write_args *));
vop_t **ffs_vnodeop_p;
static struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
{ &vop_default_desc, (vop_t *)vn_default_error },
{ &vop_lookup_desc, (vop_t *)ufs_lookup }, /* lookup */
{ &vop_lookup_desc, (vop_t *)vfs_cache_lookup },/* lookup */
{ &vop_cachedlookup_desc, (vop_t *)ufs_lookup },/* cachedlookup */
{ &vop_create_desc, (vop_t *)ufs_create }, /* create */
{ &vop_whiteout_desc, (vop_t *)ufs_whiteout }, /* whiteout */
{ &vop_mknod_desc, (vop_t *)ufs_mknod }, /* mknod */

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)ufs_extern.h 8.10 (Berkeley) 5/14/95
* $Id: ufs_extern.h,v 1.14 1997/02/22 09:47:46 peter Exp $
* $Id: ufs_extern.h,v 1.15 1997/08/16 19:16:26 wollman Exp $
*/
#ifndef _UFS_UFS_EXTERN_H_
@ -93,7 +93,7 @@ int ufs_islocked __P((struct vop_islocked_args *));
#endif
int ufs_link __P((struct vop_link_args *));
int ufs_lock __P((struct vop_lock_args *));
int ufs_lookup __P((struct vop_lookup_args *));
int ufs_lookup __P((struct vop_cachedlookup_args *));
int ufs_makeinode __P((int mode, struct vnode *, struct vnode **, struct componentname *));
int ufs_mkdir __P((struct vop_mkdir_args *));
int ufs_mknod __P((struct vop_mknod_args *));

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)ufs_lookup.c 8.15 (Berkeley) 6/16/95
* $Id: ufs_lookup.c,v 1.13 1997/03/09 06:10:33 mpp Exp $
* $Id: ufs_lookup.c,v 1.14 1997/03/31 12:02:49 peter Exp $
*/
#include <sys/param.h>
@ -97,7 +97,7 @@ int dirchk = 0;
*/
int
ufs_lookup(ap)
struct vop_lookup_args /* {
struct vop_cachedlookup_args /* {
struct vnode *a_dvp;
struct vnode **a_vpp;
struct componentname *a_cnp;
@ -153,57 +153,6 @@ ufs_lookup(ap)
/*
* We now have a segment name to search for, and a directory to search.
*
* Before tediously performing a linear scan of the directory,
* check the name cache to see if the directory/name pair
* we are looking for is known already.
*/
error = cache_lookup(vdp, vpp, cnp);
if (error) {
int vpid; /* capability number of vnode */
if (error == ENOENT)
return (error);
/*
* Get the next vnode in the path.
* See comment below starting `Step through' for
* an explaination of the locking protocol.
*/
pdp = vdp;
dp = VTOI(*vpp);
vdp = *vpp;
vpid = vdp->v_id;
if (pdp == vdp) { /* lookup on "." */
VREF(vdp);
error = 0;
} else if (flags & ISDOTDOT) {
VOP_UNLOCK(pdp, 0, p);
error = vget(vdp, LK_EXCLUSIVE, p);
if (!error && lockparent && (flags & ISLASTCN))
error = vn_lock(pdp, LK_EXCLUSIVE, p);
} else {
error = vget(vdp, LK_EXCLUSIVE, p);
if (!lockparent || error || !(flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
/*
* Check that the capability number did not change
* while we were waiting for the lock.
*/
if (!error) {
if (vpid == vdp->v_id)
return (0);
vput(vdp);
if (lockparent && pdp != vdp && (flags & ISLASTCN))
VOP_UNLOCK(pdp, 0, p);
}
if (error = vn_lock(pdp, LK_EXCLUSIVE, p))
return (error);
vdp = pdp;
dp = VTOI(pdp);
*vpp = NULL;
}
/*
* Suppress search for slots unless creating
* file and at end of pathname, in which case
* we watch for a place to put the new file in