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