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 */
16 #if defined(AFS_FBSD80_ENV)
17 #define ma_vn_lock(vp, flags, p) (vn_lock(vp, flags))
18 #define MA_VOP_LOCK(vp, flags, p) (VOP_LOCK(vp, flags))
19 #define MA_VOP_UNLOCK(vp, flags, p) (VOP_UNLOCK(vp, flags))
21 #define ma_vn_lock(vp, flags, p) (vn_lock(vp, flags, p))
22 #define MA_VOP_LOCK(vp, flags, p) (VOP_LOCK(vp, flags, p))
23 #define MA_VOP_UNLOCK(vp, flags, p) (VOP_UNLOCK(vp, flags, p))
27 osi_TryEvictVCache(struct vcache *avc, int *slept, int defersleep)
36 code = osi_fbsd_checkinuse(avc);
42 if ((vp->v_iflag & VI_DOOMED) != 0) {
47 /* must hold the vnode before calling vgone()
48 * This code largely copied from vfs_subr.c:vlrureclaim() */
52 /* use the interlock while locking, so no one else can DOOM this */
53 ma_vn_lock(vp, LK_INTERLOCK|LK_EXCLUSIVE|LK_RETRY, curthread);
55 MA_VOP_UNLOCK(vp, 0, curthread);
66 tvc = afs_osi_Alloc(sizeof(struct vcache));
67 tvc->v = NULL; /* important to clean this, or use memset 0 */
73 osi_PrePopulateVCache(struct vcache *avc) {
74 memset(avc, 0, sizeof(struct vcache));
78 osi_AttachVnode(struct vcache *avc, int seq) {
80 struct thread *p = curthread;
82 ReleaseWriteLock(&afs_xvcache);
84 #if defined(AFS_FBSD60_ENV)
85 if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
87 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
89 panic("afs getnewvnode"); /* can't happen */
91 /* XXX verified on 80--TODO check on 7x */
93 ma_vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); /* !glocked */
94 insmntque(vp, afs_globalVFS);
95 MA_VOP_UNLOCK(vp, 0, p);
99 ObtainWriteLock(&afs_xvcache,339);
100 if (avc->v != NULL) {
101 /* I'd like to know if this ever happens...
102 * We don't drop global for the rest of this function,
103 * so if we do lose the race, the other thread should
104 * have found the same vnode and finished initializing
105 * the vcache entry. Is it conceivable that this vcache
106 * entry could be recycled during this interval? If so,
107 * then there probably needs to be some sort of additional
108 * mutual exclusion (an Embryonic flag would suffice).
110 afs_warn("afs_NewVCache: lost the race\n");
114 avc->v->v_data = avc;
115 lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
119 osi_PostPopulateVCache(struct vcache *avc) {
120 avc->v->v_mount = afs_globalVFS;