2798a5fbc748a2a6a05480eb8e4773c72277f4af
[openafs.git] / src / afs / OBSD / 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, int defersleep)
18 {
19     *slept = 0;
20
21     if (!VREFCOUNT_GT(avc,0)
22         && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0) {
23         /*
24          * vgone() reclaims the vnode, which calls afs_FlushVCache(),
25          * then it puts the vnode on the free list.
26          * If we don't do this we end up with a cleaned vnode that's
27          * not on the free list.
28          */
29         AFS_GUNLOCK();
30         vgone(AFSTOV(avc));
31         AFS_GLOCK();
32         return 1;
33     }
34     return 0;
35 }
36
37 struct vcache *
38 osi_NewVnode(void)
39 {
40     struct vcache *tvc;
41
42     tvc = afs_osi_Alloc(sizeof(struct vcache));
43     tvc->v = NULL; /* important to clean this, or use memset 0 */
44
45     return tvc;
46 }
47
48 void
49 osi_PrePopulateVCache(struct vcache *avc)
50 {
51     memset(avc, 0, sizeof(struct vcache));
52 }
53
54 void
55 osi_AttachVnode(struct vcache *avc, int seq)
56 {
57     ReleaseWriteLock(&afs_xvcache);
58     AFS_GUNLOCK();
59     afs_obsd_getnewvnode(avc);  /* includes one refcount */
60     AFS_GLOCK();
61     ObtainWriteLock(&afs_xvcache,337);
62     lockinit(&avc->rwlock, PINOD, "vcache", 0, 0);
63 }
64
65 void
66 osi_PostPopulateVCache(struct vcache *avc)
67 {
68     AFSTOV(avc)->v_mount = afs_globalVFS;
69     vSetType(avc, VREG);
70 }
71
72 int
73 osi_vnhold(struct vcache *avc)
74 {
75     return afs_vget(AFSTOV(avc), 0);
76 }