2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * IRIX OSI header file. Extends afs_osi.h.
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
17 #ifndef _OSI_MACHDEP_H_
18 #define _OSI_MACHDEP_H_
22 extern kmutex_t afs_global_lock;
27 #define osi_Time() (time)
29 /* This gets redefined from ucred to cred in osi_vfs.h, just do it right */
30 #define AFS_UCRED struct cred
32 #define AFS_PROC struct proc
35 #define gop_lookupname(fnamep,segflg,followlink,compvpp) lookupname((fnamep),(segflg),(followlink),NULL,(compvpp), NULL)
37 #undef gop_lookupname_user
38 #define gop_lookupname_user(fnamep,segflg,followlink,compvpp) lookupname((fnamep),(segflg),(followlink),NULL,(compvpp), NULL)
40 #define osi_vnhold(avc, r) do { VN_HOLD(AFSTOV(avc)); } while(0)
42 #undef afs_osi_Alloc_NoSleep
43 extern void *afs_osi_Alloc_NoSleep(size_t size);
47 #include <sys/flock.h>
48 extern flid_t osi_flid;
49 #define v_op v_bh.bh_first->bd_ops
50 #define v_data v_bh.bh_first->bd_pdata
51 #define vfs_data vfs_bh.bh_first->bd_pdata
52 #endif /* AFS_SGI64_ENV */
54 #define ifnet_flags(x) (x?(x)->if_flags:0)
57 * Global lock, semaphore, mutex and state vector support.
59 #define SV_INIT(cv, nm, t, c) cv_init(cv, nm, t, c)
62 #define SV_SIGNAL(cv) sv_signal(cv)
63 #define SPINLOCK_INIT(l, nm) spinlock_init((l),(nm))
64 #define SPLOCK(l) mp_mutex_spinlock(&(l))
65 #define SPUNLOCK(l,s) mp_mutex_spinunlock(&(l),s)
66 #define SP_WAIT(l, s, cv, p) mp_sv_wait_sig(cv, p, (void*)(&(l)), s)
69 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
70 #define AFSD_PRI() ((kt_basepri(curthreadp) == PTIME_SHARE) ? PZERO : (PZERO|PLTWAIT))
71 #undef AFS_MUTEX_ENTER
72 #define AFS_MUTEX_ENTER(mp) \
74 register struct kthread *_kthreadP; \
75 while(mutex_tryenter(mp) == 0) { \
76 _kthreadP = (struct kthread*)mutex_owner(mp); \
77 if (_kthreadP != NULL && _kthreadP->k_sonproc == CPU_NONE) { \
78 mutex_lock(mp, AFSD_PRI()); \
84 #else /* AFS_SGI65_ENV */
85 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
86 #define AFSD_PRI() ((curprocp && curprocp->p_rss==0) ? (PZERO|PLTWAIT) : PZERO)
88 #define AFS_MUTEX_ENTER(mp) \
91 while(mutex_tryenter(mp) == 0) { \
92 kt = mutex_owner(mp); \
93 if (kt != NULL && kt->k_sonproc == CPU_NONE) { \
94 mutex_lock(mp, AFSD_PRI()); \
99 #endif /* AFS_SGI65_ENV */
101 #define cv_timedwait(cv, l, t) { \
102 sv_timedwait(cv, AFSD_PRI(), l, 0, 0, &(t), \
103 (struct timespec*)0); \
104 AFS_MUTEX_ENTER(l); \
109 #define cv_wait(cv, l) { \
110 sv_wait(cv, AFSD_PRI(), l, 0); \
111 AFS_MUTEX_ENTER(l); \
113 #else /* AFS_SGI64_ENV */
116 #define AFS_MUTEX_ENTER(mp) \
118 register struct proc *_procP; \
119 while(mutex_tryenter(mp) == 0) { \
120 _procP = mutex_owner(mp); \
121 if (_procP != NULL && _procP->p_sonproc == CPU_NONE) { \
128 #else /* AFS_SGI62_ENV */
130 #define AFS_MUTEX_ENTER(mp) mutex_enter(mp)
132 #endif /* AFS_SGI62_ENV */
134 #define cv_timedwait(cv, l, t) { \
135 sv_timedwait(cv, l, t); \
138 #endif /* AFS_SGI64_ENV */
142 #define _MP_NETLOCKS /* to get sblock to work right */
144 /* On SGI mutex_owned doesn't work, so simulate this by remembering the owning
145 * thread explicitly. This is only used for debugging so could be disabled for
148 * CAUTION -- The ISAFS_(RX)?GLOCK macros are not safe to use when the lock is
149 * not held if the test may be made at interrupt level as the code may
150 * appear to be running as the process that is (or last was) running at
151 * non-interrupt level. Worse yet, the interrupt may occur just as the
152 * process is exiting, in which case, the pid may change from the start
153 * of the interrupt to the end, since the u area has been changed. So,
154 * at interrupt level, I'm using the base of the current interrupt stack.
155 * Note that afs_osinet.c also modifies afs_global_owner for osi_Sleep and
156 * afs_osi_Wakeup. Changes made here should be reflected there as well.
157 * NOTE - As of 6.2, we can no longer use mutexes in interrupts, so the above
158 * concern no longer exists.
163 /* Irix does not check for deadlocks unless it's a debug kernel. */
164 #define AFS_ASSERT_GNOTME() \
165 (!ISAFS_GLOCK() || (panic("afs global lock held be me"), 0))
166 #define AFS_GLOCK() \
167 { AFS_ASSERT_GNOTME(); AFS_MUTEX_ENTER(&afs_global_lock); }
169 #define AFS_GLOCK() AFS_MUTEX_ENTER(&afs_global_lock)
171 #define AFS_GUNLOCK() { AFS_ASSERT_GLOCK(); mutex_exit(&afs_global_lock); }
172 #define ISAFS_GLOCK() mutex_mine(&afs_global_lock)
174 extern long afs_global_owner;
175 #define AFS_GLOCK() \
177 AFS_MUTEX_ENTER(&afs_global_lock) ; \
178 afs_global_owner = osi_ThreadUnique(); \
180 #define AFS_GUNLOCK() \
181 { AFS_ASSERT_GLOCK(); afs_global_owner = 0; mutex_exit(&afs_global_lock); }
182 #define ISAFS_GLOCK() (osi_ThreadUnique() == afs_global_owner)
183 #endif /* AFS_SGI64_ENV */
186 #define AFS_GUNLOCK()
187 #define ISAFS_GLOCK() 1
189 #define SPLVAR register int splvar
190 #define NETPRI splvar=splnet()
191 #define USERPRI splx(splvar)
201 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
202 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr),\
203 (int *)(aresid), &osi_flid)
205 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
206 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr), \
212 #define suser() cap_able(CAP_DEVICE_MGT)
214 #define afs_suser(x) suser()
224 /* OS independent user structure stuff */
226 * OSI_GET_CURRENT_PID
228 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
229 #define OSI_GET_CURRENT_PID() (u.u_procp->p_pid)
230 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
232 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
233 #define OSI_GET_CURRENT_PID() current_pid()
234 #endif /* AFS_SGI64_ENV */
236 #if defined(AFS_SGI65_ENV)
237 #define OSI_GET_CURRENT_PID() proc_pid(curproc())
240 #define getpid() OSI_GET_CURRENT_PID()
243 * OSI_GET_CURRENT_PROCP
245 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
246 #define OSI_GET_CURRENT_PROCP() (u.u_procp)
247 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
249 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
250 #define OSI_GET_CURRENT_PROCP() curprocp
251 #endif /* AFS_SGI64_ENV */
253 #if defined(AFS_SGI65_ENV)
254 #define OSI_GET_CURRENT_PROCP() UT_TO_PROC(curuthread)
261 * Prior to IRIX 6.4, pid sufficed, now we need kthread.
263 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
264 #define OSI_GET_LOCKID() (u.u_procp->p_pid)
265 #define OSI_NO_LOCKID (-1)
266 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
268 #if defined(AFS_SGI64_ENV)
269 /* IRIX returns k_id, but this way, we've got the thread address for debugging. */
270 #define OSI_GET_LOCKID() \
271 (private.p_curkthread ? (uint64_t)private.p_curkthread : (uint64_t)0)
272 #define OSI_NO_LOCKID ((uint64_t)-1)
273 #endif /* AFS_SGI64_ENV */
276 * OSI_GET_CURRENT_CRED
278 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
279 #define OSI_GET_CURRENT_CRED() (u.u_cred)
280 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
282 #if defined(AFS_SGI64_ENV)
283 #define OSI_GET_CURRENT_CRED() get_current_cred()
284 #endif /* AFS_SGI64_ENV */
286 #define osi_curcred() OSI_GET_CURRENT_CRED()
289 * OSI_SET_CURRENT_CRED
291 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
292 #define OSI_SET_CURRENT_CRED(x) u.u_cred=x
293 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
295 #if defined(AFS_SGI64_ENV)
296 #define OSI_SET_CURRENT_CRED(C) set_current_cred((C))
297 #endif /* AFS_SGI64_ENV */
300 * OSI_GET_CURRENT_ABI
302 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
303 #define OSI_GET_CURRENT_ABI() (u.u_procp->p_abi)
304 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
306 #if defined(AFS_SGI64_ENV)
307 #define OSI_GET_CURRENT_ABI() get_current_abi()
308 #endif /* AFS_SGI64_ENV */
311 * OSI_GET_CURRENT_SYSID
313 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
314 #define OSI_GET_CURRENT_SYSID() (u.u_procp->p_sysid)
315 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
317 #if defined(AFS_SGI64_ENV)
318 #define OSI_GET_CURRENT_SYSID() (curprocp->p_flid.fl_sysid)
319 #endif /* AFS_SGI64_ENV */
322 * OSI_GET_CURRENT_COMM
324 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
325 #define OSI_GET_CURRENT_COMM() (u.u_comm)
326 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
328 #if defined(AFS_SGI64_ENV)
329 #define OSI_GET_CURRENT_COMM() (curprocp->p_comm)
330 #endif /* AFS_SGI64_ENV */
333 * OSI_GET_CURRENT_CDIR
335 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
336 #define OSI_GET_CURRENT_CDIR() (u.u_cdir)
337 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
339 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
340 #define OSI_GET_CURRENT_CDIR() (curprocp->p_cdir)
341 #endif /* AFS_SGI64_ENV */
343 #if defined(AFS_SGI65_ENV)
344 #define OSI_GET_CURRENT_CDIR() (curuthread->ut_cdir)
345 #endif /* AFS_SGI65_ENV */
349 * OSI_GET_CURRENT_RDIR
351 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
352 #define OSI_GET_CURRENT_RDIR() (u.u_rdir)
353 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
355 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
356 #define OSI_GET_CURRENT_RDIR() (curprocp->p_rdir)
357 #endif /* AFS_SGI64_ENV */
359 #if defined(AFS_SGI65_ENV)
360 #define OSI_GET_CURRENT_RDIR() (curuthread->ut_rdir)
361 #endif /* AFS_SGI65_ENV */
365 /* Macros for vcache/vnode and vfs arguments to vnode and vfs ops.
367 * Note that the _CONVERT routines get the ";" here so that argument lists
368 * can have arguments after the OSI_x_CONVERT macro is called.
372 #define OSI_VN_ARG(V) bhv_##V
374 #define OSI_VN_DECL(V) bhv_desc_t *bhv_##V
375 #undef OSI_VN_CONVERT
376 #define OSI_VN_CONVERT(V) struct vnode * V = (struct vnode*)BHV_TO_VNODE(bhv_##V)
378 #define OSI_VC_ARG(V) bhv_##V
380 #define OSI_VC_DECL(V) bhv_desc_t *bhv_##V
381 #undef OSI_VC_CONVERT
382 #define OSI_VC_CONVERT(V) struct vcache * V = VTOAFS(BHV_TO_VNODE(bhv_##V))
384 #define OSI_VFS_ARG(V) bhv_##V
386 #define OSI_VFS_DECL(V) bhv_desc_t *bhv_##V
387 #undef OSI_VFS_CONVERT
388 #define OSI_VFS_CONVERT(V) struct vfs * V = (struct vfs*)bhvtovfs(bhv_##V)
389 #endif /* AFS_SGI64_ENV */
394 #endif /* _OSI_MACHDEP_H_ */