vfs_cache.c (116182) | vfs_cache.c (116201) |
---|---|
1/* 2 * Copyright (c) 1989, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Poul-Henning Kamp of the FreeBSD Project. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 23 unchanged lines hidden (view full) --- 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)vfs_cache.c 8.5 (Berkeley) 3/22/95 37 */ 38 39#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1989, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Poul-Henning Kamp of the FreeBSD Project. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 23 unchanged lines hidden (view full) --- 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)vfs_cache.c 8.5 (Berkeley) 3/22/95 37 */ 38 39#include <sys/cdefs.h> |
40__FBSDID("$FreeBSD: head/sys/kern/vfs_cache.c 116182 2003-06-11 00:56:59Z obrien $"); | 40__FBSDID("$FreeBSD: head/sys/kern/vfs_cache.c 116201 2003-06-11 07:35:56Z des $"); |
41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/kernel.h> 45#include <sys/lock.h> 46#include <sys/mutex.h> 47#include <sys/sysctl.h> 48#include <sys/mount.h> --- 84 unchanged lines hidden (view full) --- 133static u_long nummiss; STATNODE(CTLFLAG_RD, nummiss, &nummiss); 134static u_long nummisszap; STATNODE(CTLFLAG_RD, nummisszap, &nummisszap); 135static u_long numposzaps; STATNODE(CTLFLAG_RD, numposzaps, &numposzaps); 136static u_long numposhits; STATNODE(CTLFLAG_RD, numposhits, &numposhits); 137static u_long numnegzaps; STATNODE(CTLFLAG_RD, numnegzaps, &numnegzaps); 138static u_long numneghits; STATNODE(CTLFLAG_RD, numneghits, &numneghits); 139 140SYSCTL_OPAQUE(_vfs_cache, OID_AUTO, nchstats, CTLFLAG_RD, &nchstats, | 41 42#include <sys/param.h> 43#include <sys/systm.h> 44#include <sys/kernel.h> 45#include <sys/lock.h> 46#include <sys/mutex.h> 47#include <sys/sysctl.h> 48#include <sys/mount.h> --- 84 unchanged lines hidden (view full) --- 133static u_long nummiss; STATNODE(CTLFLAG_RD, nummiss, &nummiss); 134static u_long nummisszap; STATNODE(CTLFLAG_RD, nummisszap, &nummisszap); 135static u_long numposzaps; STATNODE(CTLFLAG_RD, numposzaps, &numposzaps); 136static u_long numposhits; STATNODE(CTLFLAG_RD, numposhits, &numposhits); 137static u_long numnegzaps; STATNODE(CTLFLAG_RD, numnegzaps, &numnegzaps); 138static u_long numneghits; STATNODE(CTLFLAG_RD, numneghits, &numneghits); 139 140SYSCTL_OPAQUE(_vfs_cache, OID_AUTO, nchstats, CTLFLAG_RD, &nchstats, |
141 sizeof(nchstats), "LU", "VFS cache effectiveness statistics"); | 141 sizeof(nchstats), "LU", "VFS cache effectiveness statistics"); |
142 143 144 145static void cache_zap(struct namecache *ncp); 146 147static MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries"); 148 149/* --- 103 unchanged lines hidden (view full) --- 253 numneg--; 254 } 255 numcache--; 256 free(ncp, M_VFSCACHE); 257} 258 259/* 260 * cache_leaf_test() | 142 143 144 145static void cache_zap(struct namecache *ncp); 146 147static MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries"); 148 149/* --- 103 unchanged lines hidden (view full) --- 253 numneg--; 254 } 255 numcache--; 256 free(ncp, M_VFSCACHE); 257} 258 259/* 260 * cache_leaf_test() |
261 * | 261 * |
262 * Test whether this (directory) vnode's namei cache entry contains 263 * subdirectories or not. Used to determine whether the directory is | 262 * Test whether this (directory) vnode's namei cache entry contains 263 * subdirectories or not. Used to determine whether the directory is |
264 * a leaf in the namei cache or not. Note: the directory may still | 264 * a leaf in the namei cache or not. Note: the directory may still |
265 * contain files in the namei cache. 266 * 267 * Returns 0 if the directory is a leaf, -1 if it isn't. 268 */ 269int 270cache_leaf_test(struct vnode *vp) 271{ 272 struct namecache *ncpc; --- 77 unchanged lines hidden (view full) --- 350 if ((cnp->cn_flags & MAKEENTRY) == 0) { 351 numposzaps++; 352 nchstats.ncs_badhits++; 353 cache_zap(ncp); 354 return (0); 355 } 356 357 /* We found a "positive" match, return the vnode */ | 265 * contain files in the namei cache. 266 * 267 * Returns 0 if the directory is a leaf, -1 if it isn't. 268 */ 269int 270cache_leaf_test(struct vnode *vp) 271{ 272 struct namecache *ncpc; --- 77 unchanged lines hidden (view full) --- 350 if ((cnp->cn_flags & MAKEENTRY) == 0) { 351 numposzaps++; 352 nchstats.ncs_badhits++; 353 cache_zap(ncp); 354 return (0); 355 } 356 357 /* We found a "positive" match, return the vnode */ |
358 if (ncp->nc_vp) { | 358 if (ncp->nc_vp) { |
359 numposhits++; 360 nchstats.ncs_goodhits++; 361 *vpp = ncp->nc_vp; 362 return (-1); 363 } 364 365 /* We found a negative match, and want to create it, so purge */ 366 if (cnp->cn_nameiop == CREATE) { --- 45 unchanged lines hidden (view full) --- 412 dvp->v_ddid = vp->v_id; 413 } else { 414 dvp->v_dd = dvp; 415 dvp->v_ddid = 0; 416 } 417 return; 418 } 419 } | 359 numposhits++; 360 nchstats.ncs_goodhits++; 361 *vpp = ncp->nc_vp; 362 return (-1); 363 } 364 365 /* We found a negative match, and want to create it, so purge */ 366 if (cnp->cn_nameiop == CREATE) { --- 45 unchanged lines hidden (view full) --- 412 dvp->v_ddid = vp->v_id; 413 } else { 414 dvp->v_dd = dvp; 415 dvp->v_ddid = 0; 416 } 417 return; 418 } 419 } |
420 | 420 |
421 ncp = (struct namecache *) 422 malloc(sizeof *ncp + cnp->cn_namelen, M_VFSCACHE, M_WAITOK); 423 bzero((char *)ncp, sizeof *ncp); 424 numcache++; 425 if (!vp) { 426 numneg++; 427 ncp->nc_flag = cnp->cn_flags & ISWHITEOUT ? NCF_WHITE : 0; 428 } else if (vp->v_type == VDIR) { --- 65 unchanged lines hidden (view full) --- 494 */ 495 496void 497cache_purge(vp) 498 struct vnode *vp; 499{ 500 static u_long nextid; 501 | 421 ncp = (struct namecache *) 422 malloc(sizeof *ncp + cnp->cn_namelen, M_VFSCACHE, M_WAITOK); 423 bzero((char *)ncp, sizeof *ncp); 424 numcache++; 425 if (!vp) { 426 numneg++; 427 ncp->nc_flag = cnp->cn_flags & ISWHITEOUT ? NCF_WHITE : 0; 428 } else if (vp->v_type == VDIR) { --- 65 unchanged lines hidden (view full) --- 494 */ 495 496void 497cache_purge(vp) 498 struct vnode *vp; 499{ 500 static u_long nextid; 501 |
502 while (!LIST_EMPTY(&vp->v_cache_src)) | 502 while (!LIST_EMPTY(&vp->v_cache_src)) |
503 cache_zap(LIST_FIRST(&vp->v_cache_src)); | 503 cache_zap(LIST_FIRST(&vp->v_cache_src)); |
504 while (!TAILQ_EMPTY(&vp->v_cache_dst)) | 504 while (!TAILQ_EMPTY(&vp->v_cache_dst)) |
505 cache_zap(TAILQ_FIRST(&vp->v_cache_dst)); 506 507 do 508 nextid++; 509 while (nextid == vp->v_id || !nextid); 510 vp->v_id = nextid; 511 vp->v_dd = vp; 512 vp->v_ddid = 0; --- 46 unchanged lines hidden (view full) --- 559 struct thread *td = cnp->cn_thread; 560 u_long vpid; /* capability number of vnode */ 561 562 *vpp = NULL; 563 dvp = ap->a_dvp; 564 lockparent = flags & LOCKPARENT; 565 566 if (dvp->v_type != VDIR) | 505 cache_zap(TAILQ_FIRST(&vp->v_cache_dst)); 506 507 do 508 nextid++; 509 while (nextid == vp->v_id || !nextid); 510 vp->v_id = nextid; 511 vp->v_dd = vp; 512 vp->v_ddid = 0; --- 46 unchanged lines hidden (view full) --- 559 struct thread *td = cnp->cn_thread; 560 u_long vpid; /* capability number of vnode */ 561 562 *vpp = NULL; 563 dvp = ap->a_dvp; 564 lockparent = flags & LOCKPARENT; 565 566 if (dvp->v_type != VDIR) |
567 return (ENOTDIR); | 567 return (ENOTDIR); |
568 569 if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) && 570 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) 571 return (EROFS); 572 573 error = VOP_ACCESS(dvp, VEXEC, cred, td); 574 575 if (error) --- 22 unchanged lines hidden (view full) --- 598 VOP_LOCK(*vpp, LK_EXCLUSIVE, td); 599 } 600 } else if ((flags & ISLASTCN) && (flags & LOCKSHARED)) 601 VOP_LOCK(*vpp, LK_DOWNGRADE, td); 602 } 603 return (error); 604 } 605#else | 568 569 if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) && 570 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) 571 return (EROFS); 572 573 error = VOP_ACCESS(dvp, VEXEC, cred, td); 574 575 if (error) --- 22 unchanged lines hidden (view full) --- 598 VOP_LOCK(*vpp, LK_EXCLUSIVE, td); 599 } 600 } else if ((flags & ISLASTCN) && (flags & LOCKSHARED)) 601 VOP_LOCK(*vpp, LK_DOWNGRADE, td); 602 } 603 return (error); 604 } 605#else |
606 if (!error) | 606 if (!error) |
607 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp)); 608#endif 609 610 if (error == ENOENT) 611 return (error); 612 613 vp = *vpp; 614 vpid = vp->v_id; --- 296 unchanged lines hidden (view full) --- 911 numfullpathfail4++; 912 free(buf, M_TEMP); 913 return (ENOMEM); 914 } 915 *--bp = '/'; 916 } 917 FILEDESC_UNLOCK(fdp); 918 numfullpathfound++; | 607 return (VOP_CACHEDLOOKUP(dvp, vpp, cnp)); 608#endif 609 610 if (error == ENOENT) 611 return (error); 612 613 vp = *vpp; 614 vpid = vp->v_id; --- 296 unchanged lines hidden (view full) --- 911 numfullpathfail4++; 912 free(buf, M_TEMP); 913 return (ENOMEM); 914 } 915 *--bp = '/'; 916 } 917 FILEDESC_UNLOCK(fdp); 918 numfullpathfound++; |
919 *retbuf = bp; | 919 *retbuf = bp; |
920 *freebuf = buf; 921 return (0); 922} | 920 *freebuf = buf; 921 return (0); 922} |