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));
22 osi_Assert(tvc != NULL);
23 tvc->v = NULL; /* important to clean this, or use memset 0 */
29 #if defined(AFS_DARWIN80_ENV)
31 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
35 /* we ignore defersleep, as we *always* need to sleep */
36 if (!VREFCOUNT_GT(avc, 0) && avc->opens == 0 &&
37 (avc->f.states & CUnlinkedDel) == 0) {
39 vnode_t tvp = AFSTOV(avc);
40 /* VREFCOUNT_GT only sees usecounts, not iocounts */
41 /* so this may fail to actually recycle the vnode now */
42 /* must call vnode_get to avoid races. */
43 if (vnode_get(tvp) == 0) {
45 /* must release lock, since vnode_put will immediately
46 reclaim if there are no other users */
47 ReleaseWriteLock(&afs_xvcache);
52 ObtainWriteLock(&afs_xvcache, 336);
54 /* we can't use the vnode_recycle return value to figure
55 * this out, since the iocount we have to hold makes it
57 if (AFSTOV(avc) == tvp) {
58 /* Caller will move this vcache to the head of the VLRU. */
67 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
69 if (!VREFCOUNT_GT(avc,0)
70 || ((VREFCOUNT(avc) == 1) && (UBCINFOEXISTS(AFSTOV(avc))))
71 && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0)
74 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
75 * then it puts the vnode on the free list.
76 * If we don't do this we end up with a cleaned vnode that's
77 * not on the free list.
86 #endif /* AFS_DARWIN80_ENV */
89 osi_PrePopulateVCache(struct vcache *avc)
91 memset(avc, 0, sizeof(struct vcache));
95 osi_AttachVnode(struct vcache *avc, int seq)
97 ReleaseWriteLock(&afs_xvcache);
99 afs_darwin_getnewvnode(avc); /* includes one refcount */
101 ObtainWriteLock(&afs_xvcache,338);
102 #ifdef AFS_DARWIN80_ENV
103 LOCKINIT(avc->rwlock);
105 lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
110 osi_PostPopulateVCache(struct vcache *avc)
112 #if !defined(AFS_DARWIN80_ENV)
113 avc->v->v_mount = afs_globalVFS;
121 osi_vnhold(struct vcache *avc)
123 VN_HOLD(AFSTOV(avc));