Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / IRIX / osi_machdep.h
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 /*
11 * IRIX OSI header file. Extends afs_osi.h.
12 *
13 * afs_osi.h includes this file, which is the only way this file should
14 * be included in a source file. This file can redefine macros declared in
15 * afs_osi.h.
16 */
17 #ifndef _OSI_MACHDEP_H_
18 #define _OSI_MACHDEP_H_
19
20 #include <sys/sema.h>
21 #include <sys/pda.h>
22 extern kmutex_t afs_global_lock;
23
24
25 #undef osi_Time
26 extern time_t time;
27 #define osi_Time() (time)
28
29 /* This gets redefined from ucred to cred in osi_vfs.h, just do it right */
30 typedef struct cred afs_ucred_t;
31 typedef struct proc afs_proc_t;
32
33 #undef gop_lookupname
34 #define gop_lookupname(fnamep,segflg,followlink,compvpp) lookupname((fnamep),(segflg),(followlink),NULL,(compvpp), NULL)
35
36 #undef gop_lookupname_user
37 #define gop_lookupname_user(fnamep,segflg,followlink,compvpp) lookupname((fnamep),(segflg),(followlink),NULL,(compvpp), NULL)
38
39 #define osi_vnhold(avc, r) do { VN_HOLD(AFSTOV(avc)); } while(0)
40
41 #ifdef AFS_SGI64_ENV
42 #include <sys/flock.h>
43 extern flid_t osi_flid;
44 #define v_op v_bh.bh_first->bd_ops
45 #define v_data v_bh.bh_first->bd_pdata
46 #define vfs_data vfs_bh.bh_first->bd_pdata
47 #endif /* AFS_SGI64_ENV */
48
49 /*
50 * Global lock, semaphore, mutex and state vector support.
51 */
52 #define SV_INIT(cv, nm, t, c) cv_init(cv, nm, t, c)
53 /* Spinlock macros */
54 #define SV_TYPE sv_t
55 #define SV_SIGNAL(cv) sv_signal(cv)
56 #define SPINLOCK_INIT(l, nm) spinlock_init((l),(nm))
57 #define SPLOCK(l) mp_mutex_spinlock(&(l))
58 #define SPUNLOCK(l,s) mp_mutex_spinunlock(&(l),s)
59 #define SP_WAIT(l, s, cv, p) mp_sv_wait_sig(cv, p, (void*)(&(l)), s)
60 #ifdef AFS_SGI64_ENV
61 #ifdef AFS_SGI65_ENV
62 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
63 #define AFSD_PRI() ((kt_basepri(curthreadp) == PTIME_SHARE) ? PZERO : (PZERO|PLTWAIT))
64 #undef AFS_MUTEX_ENTER
65 #define AFS_MUTEX_ENTER(mp) \
66 MACRO_BEGIN \
67 struct kthread *_kthreadP; \
68 while(mutex_tryenter(mp) == 0) { \
69 _kthreadP = (struct kthread*)mutex_owner(mp); \
70 if (_kthreadP != NULL && _kthreadP->k_sonproc == CPU_NONE) { \
71 mutex_lock(mp, AFSD_PRI()); \
72 break; \
73 } \
74 } \
75 MACRO_END
76
77 #else /* AFS_SGI65_ENV */
78 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
79 #define AFSD_PRI() ((curprocp && curprocp->p_rss==0) ? (PZERO|PLTWAIT) : PZERO)
80
81 #define AFS_MUTEX_ENTER(mp) \
82 MACRO_BEGIN \
83 kthread_t *kt; \
84 while(mutex_tryenter(mp) == 0) { \
85 kt = mutex_owner(mp); \
86 if (kt != NULL && kt->k_sonproc == CPU_NONE) { \
87 mutex_lock(mp, AFSD_PRI()); \
88 break; \
89 } \
90 } \
91 MACRO_END
92 #endif /* AFS_SGI65_ENV */
93
94 #define cv_timedwait(cv, l, t) { \
95 sv_timedwait(cv, AFSD_PRI(), l, 0, 0, &(t), \
96 (struct timespec*)0); \
97 AFS_MUTEX_ENTER(l); \
98 }
99 #ifdef cv_wait
100 #undef cv_wait
101 #endif
102 #define cv_wait(cv, l) { \
103 sv_wait(cv, AFSD_PRI(), l, 0); \
104 AFS_MUTEX_ENTER(l); \
105 }
106 #else /* AFS_SGI64_ENV */
107 #ifdef AFS_SGI62_ENV
108
109 #define AFS_MUTEX_ENTER(mp) \
110 MACRO_BEGIN \
111 struct proc *_procP; \
112 while(mutex_tryenter(mp) == 0) { \
113 _procP = mutex_owner(mp); \
114 if (_procP != NULL && _procP->p_sonproc == CPU_NONE) { \
115 mutex_enter(mp); \
116 break; \
117 } \
118 } \
119 MACRO_END
120
121 #else /* AFS_SGI62_ENV */
122
123 #define AFS_MUTEX_ENTER(mp) mutex_enter(mp)
124
125 #endif /* AFS_SGI62_ENV */
126
127 #define cv_timedwait(cv, l, t) { \
128 sv_timedwait(cv, l, t); \
129 AFS_GLOCK(); \
130 }
131 #endif /* AFS_SGI64_ENV */
132
133 #if defined(KERNEL)
134 #if defined(MP)
135 #define _MP_NETLOCKS /* to get sblock to work right */
136
137 /* On SGI mutex_owned doesn't work, so simulate this by remembering the owning
138 * thread explicitly. This is only used for debugging so could be disabled for
139 * production builds.
140 *
141 * CAUTION -- The ISAFS_(RX)?GLOCK macros are not safe to use when the lock is
142 * not held if the test may be made at interrupt level as the code may
143 * appear to be running as the process that is (or last was) running at
144 * non-interrupt level. Worse yet, the interrupt may occur just as the
145 * process is exiting, in which case, the pid may change from the start
146 * of the interrupt to the end, since the u area has been changed. So,
147 * at interrupt level, I'm using the base of the current interrupt stack.
148 * Note that afs_osinet.c also modifies afs_global_owner for osi_Sleep and
149 * afs_osi_Wakeup. Changes made here should be reflected there as well.
150 * NOTE - As of 6.2, we can no longer use mutexes in interrupts, so the above
151 * concern no longer exists.
152 */
153
154 #ifdef AFS_SGI64_ENV
155 #ifdef AFS_SGI65_ENV
156 /* Irix does not check for deadlocks unless it's a debug kernel. */
157 #define AFS_ASSERT_GNOTME() \
158 (!ISAFS_GLOCK() || (panic("afs global lock held be me"), 0))
159 #define AFS_GLOCK() \
160 { AFS_ASSERT_GNOTME(); AFS_MUTEX_ENTER(&afs_global_lock); }
161 #else
162 #define AFS_GLOCK() AFS_MUTEX_ENTER(&afs_global_lock)
163 #endif
164 #define AFS_GUNLOCK() { AFS_ASSERT_GLOCK(); mutex_exit(&afs_global_lock); }
165 #define ISAFS_GLOCK() mutex_mine(&afs_global_lock)
166 #else
167 extern long afs_global_owner;
168 #define AFS_GLOCK() \
169 MACRO_BEGIN \
170 AFS_MUTEX_ENTER(&afs_global_lock) ; \
171 afs_global_owner = osi_ThreadUnique(); \
172 MACRO_END
173 #define AFS_GUNLOCK() \
174 { AFS_ASSERT_GLOCK(); afs_global_owner = 0; mutex_exit(&afs_global_lock); }
175 #define ISAFS_GLOCK() (osi_ThreadUnique() == afs_global_owner)
176 #endif /* AFS_SGI64_ENV */
177 #else /* MP */
178 #define AFS_GLOCK()
179 #define AFS_GUNLOCK()
180 #define ISAFS_GLOCK() 1
181
182 #define SPLVAR int splvar
183 #define NETPRI splvar=splnet()
184 #define USERPRI splx(splvar)
185
186
187 #endif /* MP */
188
189 #endif /* KERNEL */
190
191 #if defined(AFS_SGI62_ENV)
192 # define osi_InitGlock() \
193 mutex_init(&afs_global_lock, MUTEX_DEFAULT, "afs_global_lock");
194 #else
195 # define osi_InitGlock() \
196 mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL);
197 #endif
198
199 #ifdef AFS_SGI64_ENV
200 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
201 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr),\
202 (int *)(aresid), &osi_flid)
203 #else
204 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
205 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr), \
206 (int *)(aresid))
207 #endif
208
209 #ifdef AFS_SGI64_ENV
210 #undef suser
211 #define suser() cap_able(CAP_DEVICE_MGT)
212 #endif
213 #define afs_suser(x) suser()
214
215 #define afs_hz HZ
216
217 #ifdef AFS_SGI64_ENV
218 #undef setuerror
219 #undef getuerror
220 #endif
221
222
223 /* OS independent user structure stuff */
224 /*
225 * OSI_GET_CURRENT_PID
226 */
227 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
228 #define OSI_GET_CURRENT_PID() (u.u_procp->p_pid)
229 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
230
231 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
232 #define OSI_GET_CURRENT_PID() current_pid()
233 #endif /* AFS_SGI64_ENV */
234
235 #if defined(AFS_SGI65_ENV)
236 #define OSI_GET_CURRENT_PID() proc_pid(curproc())
237 #endif
238
239 #define getpid() OSI_GET_CURRENT_PID()
240
241 /*
242 * OSI_GET_CURRENT_PROCP
243 */
244 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
245 #define OSI_GET_CURRENT_PROCP() (u.u_procp)
246 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
247
248 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
249 #define OSI_GET_CURRENT_PROCP() curprocp
250 #endif /* AFS_SGI64_ENV */
251
252 #if defined(AFS_SGI65_ENV)
253 #define OSI_GET_CURRENT_PROCP() UT_TO_PROC(curuthread)
254 #endif
255
256
257 /*
258 * OSI_GET_LOCKID
259 *
260 * Prior to IRIX 6.4, pid sufficed, now we need kthread.
261 */
262 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
263 #define OSI_GET_LOCKID() (u.u_procp->p_pid)
264 #define OSI_NO_LOCKID (-1)
265 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
266
267 #if defined(AFS_SGI64_ENV)
268 /* IRIX returns k_id, but this way, we've got the thread address for debugging. */
269 #define OSI_GET_LOCKID() \
270 (private.p_curkthread ? (uint64_t)private.p_curkthread : (uint64_t)0)
271 #define OSI_NO_LOCKID ((uint64_t)-1)
272 #endif /* AFS_SGI64_ENV */
273
274 /*
275 * OSI_GET_CURRENT_CRED
276 */
277 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
278 #define OSI_GET_CURRENT_CRED() (u.u_cred)
279 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
280
281 #if defined(AFS_SGI64_ENV)
282 #define OSI_GET_CURRENT_CRED() get_current_cred()
283 #endif /* AFS_SGI64_ENV */
284
285 #define osi_curcred() OSI_GET_CURRENT_CRED()
286
287 /*
288 * OSI_SET_CURRENT_CRED
289 */
290 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
291 #define OSI_SET_CURRENT_CRED(x) u.u_cred=x
292 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
293
294 #if defined(AFS_SGI64_ENV)
295 #define OSI_SET_CURRENT_CRED(C) set_current_cred((C))
296 #endif /* AFS_SGI64_ENV */
297
298 /*
299 * OSI_GET_CURRENT_ABI
300 */
301 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
302 #define OSI_GET_CURRENT_ABI() (u.u_procp->p_abi)
303 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
304
305 #if defined(AFS_SGI64_ENV)
306 #define OSI_GET_CURRENT_ABI() get_current_abi()
307 #endif /* AFS_SGI64_ENV */
308
309 /*
310 * OSI_GET_CURRENT_SYSID
311 */
312 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
313 #define OSI_GET_CURRENT_SYSID() (u.u_procp->p_sysid)
314 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
315
316 #if defined(AFS_SGI64_ENV)
317 #define OSI_GET_CURRENT_SYSID() (curprocp->p_flid.fl_sysid)
318 #endif /* AFS_SGI64_ENV */
319
320 /*
321 * OSI_GET_CURRENT_COMM
322 */
323 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
324 #define OSI_GET_CURRENT_COMM() (u.u_comm)
325 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
326
327 #if defined(AFS_SGI64_ENV)
328 #define OSI_GET_CURRENT_COMM() (curprocp->p_comm)
329 #endif /* AFS_SGI64_ENV */
330
331 /*
332 * OSI_GET_CURRENT_CDIR
333 */
334 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
335 #define OSI_GET_CURRENT_CDIR() (u.u_cdir)
336 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
337
338 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
339 #define OSI_GET_CURRENT_CDIR() (curprocp->p_cdir)
340 #endif /* AFS_SGI64_ENV */
341
342 #if defined(AFS_SGI65_ENV)
343 #define OSI_GET_CURRENT_CDIR() (curuthread->ut_cdir)
344 #endif /* AFS_SGI65_ENV */
345
346
347 /*
348 * OSI_GET_CURRENT_RDIR
349 */
350 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
351 #define OSI_GET_CURRENT_RDIR() (u.u_rdir)
352 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
353
354 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
355 #define OSI_GET_CURRENT_RDIR() (curprocp->p_rdir)
356 #endif /* AFS_SGI64_ENV */
357
358 #if defined(AFS_SGI65_ENV)
359 #define OSI_GET_CURRENT_RDIR() (curuthread->ut_rdir)
360 #endif /* AFS_SGI65_ENV */
361
362
363
364 /* Macros for vcache/vnode and vfs arguments to vnode and vfs ops.
365 *
366 * Note that the _CONVERT routines get the ";" here so that argument lists
367 * can have arguments after the OSI_x_CONVERT macro is called.
368 */
369 #ifdef AFS_SGI64_ENV
370 #undef OSI_VN_ARG
371 #define OSI_VN_ARG(V) bhv_##V
372 #undef OSI_VN_DECL
373 #define OSI_VN_DECL(V) bhv_desc_t *bhv_##V
374 #undef OSI_VN_CONVERT
375 #define OSI_VN_CONVERT(V) struct vnode * V = (struct vnode*)BHV_TO_VNODE(bhv_##V)
376 #undef OSI_VC_ARG
377 #define OSI_VC_ARG(V) bhv_##V
378 #undef OSI_VC_DECL
379 #define OSI_VC_DECL(V) bhv_desc_t *bhv_##V
380 #undef OSI_VC_CONVERT
381 #define OSI_VC_CONVERT(V) struct vcache * V = VTOAFS(BHV_TO_VNODE(bhv_##V))
382 #undef OSI_VFS_ARG
383 #define OSI_VFS_ARG(V) bhv_##V
384 #undef OSI_VFS_DECL
385 #define OSI_VFS_DECL(V) bhv_desc_t *bhv_##V
386 #undef OSI_VFS_CONVERT
387 #define OSI_VFS_CONVERT(V) struct vfs * V = (struct vfs*)bhvtovfs(bhv_##V)
388 #endif /* AFS_SGI64_ENV */
389
390 #define osi_procname(procname, size) strncpy(procname, proc_name(curproc()), size)
391
392
393 #endif /* _OSI_MACHDEP_H_ */