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, int defersleep)
27 code = osi_fbsd_checkinuse(avc);
33 if ((vp->v_iflag & VI_DOOMED) != 0) {
41 ReleaseWriteLock(&afs_xvcache);
46 if (vn_lock(vp, LK_INTERLOCK|LK_EXCLUSIVE|LK_NOWAIT) == 0) {
48 * vrecycle() will vgone() only if its usecount is 0. If someone grabbed a
49 * new usecount ref just now, the vgone() will be skipped, and vrecycle
52 if (vrecycle(vp) != 0) {
62 ObtainWriteLock(&afs_xvcache, 340);
72 tvc = afs_osi_Alloc(sizeof(struct vcache));
73 tvc->v = NULL; /* important to clean this, or use memset 0 */
79 osi_PrePopulateVCache(struct vcache *avc)
81 memset(avc, 0, sizeof(struct vcache));
85 osi_AttachVnode(struct vcache *avc, int seq)
89 ReleaseWriteLock(&afs_xvcache);
91 if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
92 panic("afs getnewvnode"); /* can't happen */
93 /* XXX verified on 80--TODO check on 7x */
95 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* !glocked */
96 insmntque(vp, afs_globalVFS);
100 ObtainWriteLock(&afs_xvcache,339);
101 if (avc->v != NULL) {
102 /* I'd like to know if this ever happens...
103 * We don't drop global for the rest of this function,
104 * so if we do lose the race, the other thread should
105 * have found the same vnode and finished initializing
106 * the vcache entry. Is it conceivable that this vcache
107 * entry could be recycled during this interval? If so,
108 * then there probably needs to be some sort of additional
109 * mutual exclusion (an Embryonic flag would suffice).
111 afs_warn("afs_NewVCache: lost the race\n");
115 avc->v->v_data = avc;
116 lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
120 osi_PostPopulateVCache(struct vcache *avc)
122 avc->v->v_mount = afs_globalVFS;
127 osi_vnhold(struct vcache *avc)
129 struct vnode *vp = AFSTOV(avc);
132 if ((vp->v_iflag & VI_DOOMED) != 0) {