2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
13 #include "afs/sysincludes.h" /*Standard vendor system headers */
14 #include "afsincludes.h" /*AFS-based standard headers */
21 tvc = afs_osi_Alloc(sizeof(struct vcache));
25 tvc->v = NULL; /* important to clean this, or use memset 0 */
31 #if defined(AFS_DARWIN80_ENV)
33 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
37 /* we ignore defersleep, as we *always* need to sleep */
38 if (!VREFCOUNT_GT(avc, 0) && avc->opens == 0 &&
39 (avc->f.states & CUnlinkedDel) == 0) {
41 vnode_t tvp = AFSTOV(avc);
42 /* VREFCOUNT_GT only sees usecounts, not iocounts */
43 /* so this may fail to actually recycle the vnode now */
44 /* must call vnode_get to avoid races. */
45 if (vnode_get(tvp) == 0) {
47 /* must release lock, since vnode_put will immediately
48 reclaim if there are no other users */
49 ReleaseWriteLock(&afs_xvcache);
54 ObtainWriteLock(&afs_xvcache, 336);
56 /* we can't use the vnode_recycle return value to figure
57 * this out, since the iocount we have to hold makes it
59 if (AFSTOV(avc) == tvp) {
60 /* Caller will move this vcache to the head of the VLRU. */
69 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
71 if (!VREFCOUNT_GT(avc,0)
72 || ((VREFCOUNT(avc) == 1) && (UBCINFOEXISTS(AFSTOV(avc))))
73 && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0)
76 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
77 * then it puts the vnode on the free list.
78 * If we don't do this we end up with a cleaned vnode that's
79 * not on the free list.
88 #endif /* AFS_DARWIN80_ENV */
91 osi_PrePopulateVCache(struct vcache *avc)
93 memset(avc, 0, sizeof(struct vcache));
97 osi_AttachVnode(struct vcache *avc, int seq)
99 ReleaseWriteLock(&afs_xvcache);
101 afs_darwin_getnewvnode(avc); /* includes one refcount */
103 ObtainWriteLock(&afs_xvcache,338);
104 #ifdef AFS_DARWIN80_ENV
105 LOCKINIT(avc->rwlock);
107 lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
112 osi_PostPopulateVCache(struct vcache *avc)
114 #if !defined(AFS_DARWIN80_ENV)
115 avc->v->v_mount = afs_globalVFS;
123 osi_vnhold(struct vcache *avc)
125 VN_HOLD(AFSTOV(avc));