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 if (!VREFCOUNT_GT(avc,0)
19 && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0) {
21 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
22 * then it puts the vnode on the free list.
23 * If we don't do this we end up with a cleaned vnode that's
24 * not on the free list.
25 * XXX assume FreeBSD is the same for now.
29 #if defined(AFS_FBSD80_ENV)
30 /* vgone() is correct, but v_usecount is assumed not
31 * to be 0, and I suspect that currently our usage ensures that
33 if (vrefcnt(AFSTOV(avc)) < 1) {
36 vn_lock(AFSTOV(avc), LK_EXCLUSIVE | LK_RETRY); /* !glocked */
40 #if defined(AFS_FBSD80_ENV)
41 VOP_UNLOCK(AFSTOV(avc), 0);
54 tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
55 tvc->v = NULL; /* important to clean this, or use memset 0 */
61 osi_PrePopulateVCache(struct vcache *avc) {
62 memset(avc, 0, sizeof(struct vcache));
66 osi_AttachVnode(struct vcache *avc, int seq) {
69 ReleaseWriteLock(&afs_xvcache);
71 #if defined(AFS_FBSD60_ENV)
72 if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
74 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
76 panic("afs getnewvnode"); /* can't happen */
78 /* XXX verified on 80--TODO check on 7x */
80 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* !glocked */
81 insmntque(vp, afs_globalVFS);
86 ObtainWriteLock(&afs_xvcache,339);
88 /* I'd like to know if this ever happens...
89 * We don't drop global for the rest of this function,
90 * so if we do lose the race, the other thread should
91 * have found the same vnode and finished initializing
92 * the vcache entry. Is it conceivable that this vcache
93 * entry could be recycled during this interval? If so,
94 * then there probably needs to be some sort of additional
95 * mutual exclusion (an Embryonic flag would suffice).
97 afs_warn("afs_NewVCache: lost the race\n");
101 avc->v->v_data = avc;
102 lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
106 osi_PostPopulateVCache(struct vcache *avc) {
107 avc->v->v_mount = afs_globalVFS;