522e8b5c7b8fce90e8505adf9b48a171225ef2bd
[openafs.git] / src / afs / IRIX / 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      /* we can't control whether we sleep */
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 extern char *makesname();
31
32 struct vcache *
33 osi_NewVnode(void)
34 {
35     struct vcache *avc;
36     char name[METER_NAMSZ];
37
38     avc = afs_osi_Alloc(sizeof(struct vcache));
39
40     memset(avc, 0, sizeof(struct vcache));
41     avc->v.v_number = ++afsvnumbers;
42     avc->vc_rwlockid = OSI_NO_LOCKID;
43     initnsema(&avc->vc_rwlock, 1,
44               makesname(name, "vrw", avc->v.v_number));
45 #ifndef AFS_SGI53_ENV
46     initnsema(&avc->v.v_sync, 0,
47               makesname(name, "vsy", avc->v.v_number));
48 #endif
49 #ifndef AFS_SGI62_ENV
50     initnlock(&avc->v.v_lock,
51               makesname(name, "vlk", avc->v.v_number));
52 #endif
53     return avc;
54 }
55
56 void
57 osi_PrePopulateVCache(struct vcache *avc)
58 {
59     avc->uncred = 0;
60     memset(&(avc->f), 0, sizeof(struct fvcache));
61 }
62
63 void
64 osi_AttachVnode(struct vcache *avc, int seq)
65 {
66 }
67
68 void
69 osi_PostPopulateVCache(struct vcache *avc)
70 {
71     memset(&(avc->vc_bhv_desc), 0, sizeof(avc->vc_bhv_desc));
72     bhv_desc_init(&(avc->vc_bhv_desc), avc, avc, &Afs_vnodeops);
73
74 #if defined(AFS_SGI65_ENV)
75     vn_bhv_head_init(&(avc->v.v_bh), "afsvp");
76     vn_bhv_insert_initial(&(avc->v.v_bh), &(avc->vc_bhv_desc));
77     avc->v.v_mreg = avc->v.v_mregb = (struct pregion *)avc;
78 # if defined(VNODE_TRACING)
79     avc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
80 # endif
81     init_bitlock(&avc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
82                  avc->v.v_number);
83     init_mutex(&avc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)avc);
84     init_mutex(&avc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)avc);
85 #else
86     bhv_head_init(&(avc->v.v_bh));
87     bhv_insert_initial(&(avc->v.v_bh), &(avc->vc_bhv_desc));
88 #endif
89
90     vnode_pcache_init(&avc->v);
91
92 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
93     /* Above define is never true execpt in SGI test kernels. */
94     init_bitlock(&avc->v.v_flag, VLOCK, "vnode", avc->v.v_number);
95 #endif
96
97 #ifdef INTR_KTHREADS
98     AFS_VN_INIT_BUF_LOCK(&(avc->v));
99 #endif
100
101     vSetVfsp(avc, afs_globalVFS);
102     vSetType(avc, VREG);
103
104     VN_SET_DPAGES(&(avc->v), NULL);
105     osi_Assert((avc->v.v_flag & VINACT) == 0);
106     avc->v.v_flag = 0;
107     osi_Assert(VN_GET_PGCNT(&(avc->v)) == 0);
108     osi_Assert(avc->mapcnt == 0 && avc->vc_locktrips == 0);
109     osi_Assert(avc->vc_rwlockid == OSI_NO_LOCKID);
110     osi_Assert(avc->v.v_filocks == NULL);
111 # if !defined(AFS_SGI65_ENV)
112     osi_Assert(avc->v.v_filocksem == NULL);
113 # endif
114     osi_Assert(avc->cred == NULL);
115 # if defined(AFS_SGI64_ENV)
116     vnode_pcache_reinit(&avc->v);
117     avc->v.v_rdev = NODEV;
118 # endif
119     vn_initlist((struct vnlist *)&avc->v);
120     avc->lastr = 0;
121 }
122
123 int
124 osi_vnhold(struct vcache *avc)
125 {
126     VN_HOLD(AFSTOV(avc));
127     return 0;
128 }