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 */
17 osi_TryEvictVCache(struct vcache *avc, int *slept) {
18 struct vnode *vp = AFSTOV(avc);
20 if (!VREFCOUNT_GT(avc,0)
21 && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0) {
23 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
24 * then it puts the vnode on the free list.
25 * If we don't do this we end up with a cleaned vnode that's
26 * not on the free list.
27 * XXX assume FreeBSD is the same for now.
30 * We only have one caller (afs_ShakeLooseVCaches), which already
31 * holds the write lock. vgonel() sometimes calls VOP_CLOSE(),
32 * so we must drop the write lock around our call to vgone().
34 ReleaseWriteLock(&afs_xvcache);
38 #if defined(AFS_FBSD80_ENV)
39 /* vgone() is correct, but v_usecount is assumed not
40 * to be 0, and I suspect that currently our usage ensures that
42 if (vrefcnt(vp) < 1) {
45 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* !glocked */
49 #if defined(AFS_FBSD80_ENV)
54 ObtainWriteLock(&afs_xvcache, 340);
64 tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
65 tvc->v = NULL; /* important to clean this, or use memset 0 */
71 osi_PrePopulateVCache(struct vcache *avc) {
72 memset(avc, 0, sizeof(struct vcache));
76 osi_AttachVnode(struct vcache *avc, int seq) {
79 ReleaseWriteLock(&afs_xvcache);
81 #if defined(AFS_FBSD60_ENV)
82 if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
84 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
86 panic("afs getnewvnode"); /* can't happen */
88 /* XXX verified on 80--TODO check on 7x */
90 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* !glocked */
91 insmntque(vp, afs_globalVFS);
96 ObtainWriteLock(&afs_xvcache,339);
98 /* I'd like to know if this ever happens...
99 * We don't drop global for the rest of this function,
100 * so if we do lose the race, the other thread should
101 * have found the same vnode and finished initializing
102 * the vcache entry. Is it conceivable that this vcache
103 * entry could be recycled during this interval? If so,
104 * then there probably needs to be some sort of additional
105 * mutual exclusion (an Embryonic flag would suffice).
107 afs_warn("afs_NewVCache: lost the race\n");
111 avc->v->v_data = avc;
112 lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
116 osi_PostPopulateVCache(struct vcache *avc) {
117 avc->v->v_mount = afs_globalVFS;