FBSD: warning cleanups
[openafs.git] / src / afs / FBSD / osi_vcache.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 #include <afsconfig.h>
11 #include "afs/param.h"
12
13 #include "afs/sysincludes.h"    /*Standard vendor system headers */
14 #include "afsincludes.h"        /*AFS-based standard headers */
15
16 int
17 osi_TryEvictVCache(struct vcache *avc, int *slept) {
18
19     /*
20      * essentially all we want to do here is check that the
21      * vcache is not in use, then call vgone() (which will call
22      * inactive and reclaim as needed).  This requires some
23      * kind of complicated locking, which we already need to implement
24      * for FlushVCache, so just call that routine here and check
25      * its return value for whether the vcache was evict-able.
26      */
27     if (osi_VM_FlushVCache(avc, slept) != 0)
28         return 0;
29     else
30         return 1;
31 }
32
33 struct vcache *
34 osi_NewVnode(void) {
35     struct vcache *tvc;
36
37     tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
38     tvc->v = NULL; /* important to clean this, or use memset 0 */
39
40     return tvc;
41 }
42
43 void
44 osi_PrePopulateVCache(struct vcache *avc) {
45     memset(avc, 0, sizeof(struct vcache));
46 }
47
48 void
49 osi_AttachVnode(struct vcache *avc, int seq) {
50     struct vnode *vp;
51
52     ReleaseWriteLock(&afs_xvcache);
53     AFS_GUNLOCK();
54 #if defined(AFS_FBSD60_ENV)
55     if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
56 #else
57     if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
58 #endif
59         panic("afs getnewvnode");       /* can't happen */
60 #ifdef AFS_FBSD70_ENV
61     /* XXX verified on 80--TODO check on 7x */
62     if (!vp->v_mount) {
63         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* !glocked */
64         insmntque(vp, afs_globalVFS);
65         VOP_UNLOCK(vp, 0);
66     }
67 #endif
68     AFS_GLOCK();
69     ObtainWriteLock(&afs_xvcache,339);
70     if (avc->v != NULL) {
71         /* I'd like to know if this ever happens...
72          * We don't drop global for the rest of this function,
73          * so if we do lose the race, the other thread should
74          * have found the same vnode and finished initializing
75          * the vcache entry.  Is it conceivable that this vcache
76          * entry could be recycled during this interval?  If so,
77          * then there probably needs to be some sort of additional
78          * mutual exclusion (an Embryonic flag would suffice).
79          * -GAW */
80         afs_warn("afs_NewVCache: lost the race\n");
81         return;
82     }
83     avc->v = vp;
84     avc->v->v_data = avc;
85     lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
86 }
87
88 void
89 osi_PostPopulateVCache(struct vcache *avc) {
90     avc->v->v_mount = afs_globalVFS;
91     vSetType(avc, VREG);
92 }
93