venus: Remove dedebug
[openafs.git] / src / afs / SOLARIS / 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     int code;
20
21     if (!VREFCOUNT_GT(avc,0)
22          && avc->opens == 0 && (avc->f.states & CUnlinkedDel) == 0) {
23         code = afs_FlushVCache(avc, slept);
24         if (code == 0)
25             return 1;
26     }
27     return 0;
28 }
29
30 struct vcache *
31 osi_NewVnode(void)
32 {
33     struct vcache *avc;
34
35     avc = afs_osi_Alloc(sizeof(struct vcache));
36     if (avc == NULL) {
37         return NULL;
38     }
39     return avc;
40 }
41
42 void
43 osi_PrePopulateVCache(struct vcache *avc)
44 {
45     memset(avc, 0, sizeof(struct vcache));
46
47     QInit(&avc->multiPage);
48
49     AFS_RWLOCK_INIT(&avc->vlock, "vcache vlock");
50
51     rw_init(&avc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
52
53 #ifndef AFS_SUN511_ENV
54     /* This is required if the kaio (kernel aynchronous io)
55      ** module is installed. Inside the kernel, the function
56      ** check_vp( common/os/aio.c) checks to see if the kernel has
57      ** to provide asynchronous io for this vnode. This
58      ** function extracts the device number by following the
59      ** v_data field of the vnode. If we do not set this field
60      ** then the system panics. The  value of the v_data field
61      ** is not really important for AFS vnodes because the kernel
62      ** does not do asynchronous io for regular files. Hence,
63      ** for the time being, we fill up the v_data field with the
64      ** vnode pointer itself. */
65     avc->v.v_data = (char *)avc;
66 #endif /* !AFS_SUN511_ENV */
67 }
68
69 void
70 osi_AttachVnode(struct vcache *avc, int seq)
71 {
72 #ifdef AFS_SUN511_ENV
73     struct vnode *vp;
74
75     osi_Assert(AFSTOV(avc) == NULL);
76
77     vp = vn_alloc(KM_SLEEP);
78     osi_Assert(vp != NULL);
79
80     vp->v_data = avc;
81     AFSTOV(avc) = vp;
82 #endif
83 }
84
85 void
86 osi_PostPopulateVCache(struct vcache *avc)
87 {
88     AFSTOV(avc)->v_op = afs_ops;
89     AFSTOV(avc)->v_vfsp = afs_globalVFS;
90     vSetType(avc, VREG);
91
92     /* Normally we do this in osi_vnhold when we notice the ref count went from
93      * 0 -> 1. But if we just setup or reused a vcache, we set the refcount to
94      * 1 directly. So, we must explicitly VFS_HOLD here. */
95     VFS_HOLD(afs_globalVFS);
96 }
97
98 int
99 osi_vnhold(struct vcache *avc)
100 {
101     struct vnode *vp = AFSTOV(avc);
102     uint_t prevcount;
103
104     mutex_enter(&vp->v_lock);
105     prevcount = vp->v_count++;
106     mutex_exit(&vp->v_lock);
107
108     if (prevcount == 0) {
109         VFS_HOLD(afs_globalVFS);
110     }
111     return 0;
112 }