OpenAFS
OpenAFS distributed network file system
|
00001 /* 00002 * Copyright 2000, International Business Machines Corporation and others. 00003 * All Rights Reserved. 00004 * 00005 * This software has been released under the terms of the IBM Public 00006 * License. For details, see the LICENSE file in the top-level source 00007 * directory or online at http://www.openafs.org/dl/license10.html 00008 */ 00009 00010 /* 00011 * IRIX OSI header file. Extends afs_osi.h. 00012 * 00013 * afs_osi.h includes this file, which is the only way this file should 00014 * be included in a source file. This file can redefine macros declared in 00015 * afs_osi.h. 00016 */ 00017 #ifndef _OSI_MACHDEP_H_ 00018 #define _OSI_MACHDEP_H_ 00019 00020 #include <sys/sema.h> 00021 #include <sys/pda.h> 00022 extern kmutex_t afs_global_lock; 00023 00024 00025 #undef osi_Time 00026 extern time_t time; 00027 #define osi_Time() (time) 00028 00029 /* This gets redefined from ucred to cred in osi_vfs.h, just do it right */ 00030 typedef struct cred afs_ucred_t; 00031 typedef struct proc afs_proc_t; 00032 00033 #undef gop_lookupname 00034 #define gop_lookupname(fnamep,segflg,followlink,compvpp) lookupname((fnamep),(segflg),(followlink),NULL,(compvpp), NULL) 00035 00036 #undef gop_lookupname_user 00037 #define gop_lookupname_user(fnamep,segflg,followlink,compvpp) lookupname((fnamep),(segflg),(followlink),NULL,(compvpp), NULL) 00038 00039 #define osi_vnhold(avc, r) do { VN_HOLD(AFSTOV(avc)); } while(0) 00040 00041 #ifdef AFS_SGI64_ENV 00042 #include <sys/flock.h> 00043 extern flid_t osi_flid; 00044 #define v_op v_bh.bh_first->bd_ops 00045 #define v_data v_bh.bh_first->bd_pdata 00046 #define vfs_data vfs_bh.bh_first->bd_pdata 00047 #endif /* AFS_SGI64_ENV */ 00048 00049 /* 00050 * Global lock, semaphore, mutex and state vector support. 00051 */ 00052 #define SV_INIT(cv, nm, t, c) cv_init(cv, nm, t, c) 00053 /* Spinlock macros */ 00054 #define SV_TYPE sv_t 00055 #define SV_SIGNAL(cv) sv_signal(cv) 00056 #define SPINLOCK_INIT(l, nm) spinlock_init((l),(nm)) 00057 #define SPLOCK(l) mp_mutex_spinlock(&(l)) 00058 #define SPUNLOCK(l,s) mp_mutex_spinunlock(&(l),s) 00059 #define SP_WAIT(l, s, cv, p) mp_sv_wait_sig(cv, p, (void*)(&(l)), s) 00060 #ifdef AFS_SGI64_ENV 00061 #ifdef AFS_SGI65_ENV 00062 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */ 00063 #define AFSD_PRI() ((kt_basepri(curthreadp) == PTIME_SHARE) ? PZERO : (PZERO|PLTWAIT)) 00064 #undef AFS_MUTEX_ENTER 00065 #define AFS_MUTEX_ENTER(mp) \ 00066 MACRO_BEGIN \ 00067 struct kthread *_kthreadP; \ 00068 while(mutex_tryenter(mp) == 0) { \ 00069 _kthreadP = (struct kthread*)mutex_owner(mp); \ 00070 if (_kthreadP != NULL && _kthreadP->k_sonproc == CPU_NONE) { \ 00071 mutex_lock(mp, AFSD_PRI()); \ 00072 break; \ 00073 } \ 00074 } \ 00075 MACRO_END 00076 00077 #else /* AFS_SGI65_ENV */ 00078 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */ 00079 #define AFSD_PRI() ((curprocp && curprocp->p_rss==0) ? (PZERO|PLTWAIT) : PZERO) 00080 00081 #define AFS_MUTEX_ENTER(mp) \ 00082 MACRO_BEGIN \ 00083 kthread_t *kt; \ 00084 while(mutex_tryenter(mp) == 0) { \ 00085 kt = mutex_owner(mp); \ 00086 if (kt != NULL && kt->k_sonproc == CPU_NONE) { \ 00087 mutex_lock(mp, AFSD_PRI()); \ 00088 break; \ 00089 } \ 00090 } \ 00091 MACRO_END 00092 #endif /* AFS_SGI65_ENV */ 00093 00094 #define cv_timedwait(cv, l, t) { \ 00095 sv_timedwait(cv, AFSD_PRI(), l, 0, 0, &(t), \ 00096 (struct timespec*)0); \ 00097 AFS_MUTEX_ENTER(l); \ 00098 } 00099 #ifdef cv_wait 00100 #undef cv_wait 00101 #endif 00102 #define cv_wait(cv, l) { \ 00103 sv_wait(cv, AFSD_PRI(), l, 0); \ 00104 AFS_MUTEX_ENTER(l); \ 00105 } 00106 #else /* AFS_SGI64_ENV */ 00107 #ifdef AFS_SGI62_ENV 00108 00109 #define AFS_MUTEX_ENTER(mp) \ 00110 MACRO_BEGIN \ 00111 struct proc *_procP; \ 00112 while(mutex_tryenter(mp) == 0) { \ 00113 _procP = mutex_owner(mp); \ 00114 if (_procP != NULL && _procP->p_sonproc == CPU_NONE) { \ 00115 mutex_enter(mp); \ 00116 break; \ 00117 } \ 00118 } \ 00119 MACRO_END 00120 00121 #else /* AFS_SGI62_ENV */ 00122 00123 #define AFS_MUTEX_ENTER(mp) mutex_enter(mp) 00124 00125 #endif /* AFS_SGI62_ENV */ 00126 00127 #define cv_timedwait(cv, l, t) { \ 00128 sv_timedwait(cv, l, t); \ 00129 AFS_GLOCK(); \ 00130 } 00131 #endif /* AFS_SGI64_ENV */ 00132 00133 #if defined(KERNEL) 00134 #if defined(MP) 00135 #define _MP_NETLOCKS /* to get sblock to work right */ 00136 00137 /* On SGI mutex_owned doesn't work, so simulate this by remembering the owning 00138 * thread explicitly. This is only used for debugging so could be disabled for 00139 * production builds. 00140 * 00141 * CAUTION -- The ISAFS_(RX)?GLOCK macros are not safe to use when the lock is 00142 * not held if the test may be made at interrupt level as the code may 00143 * appear to be running as the process that is (or last was) running at 00144 * non-interrupt level. Worse yet, the interrupt may occur just as the 00145 * process is exiting, in which case, the pid may change from the start 00146 * of the interrupt to the end, since the u area has been changed. So, 00147 * at interrupt level, I'm using the base of the current interrupt stack. 00148 * Note that afs_osinet.c also modifies afs_global_owner for osi_Sleep and 00149 * afs_osi_Wakeup. Changes made here should be reflected there as well. 00150 * NOTE - As of 6.2, we can no longer use mutexes in interrupts, so the above 00151 * concern no longer exists. 00152 */ 00153 00154 #ifdef AFS_SGI64_ENV 00155 #ifdef AFS_SGI65_ENV 00156 /* Irix does not check for deadlocks unless it's a debug kernel. */ 00157 #define AFS_ASSERT_GNOTME() \ 00158 (!ISAFS_GLOCK() || (panic("afs global lock held be me"), 0)) 00159 #define AFS_GLOCK() \ 00160 { AFS_ASSERT_GNOTME(); AFS_MUTEX_ENTER(&afs_global_lock); } 00161 #else 00162 #define AFS_GLOCK() AFS_MUTEX_ENTER(&afs_global_lock) 00163 #endif 00164 #define AFS_GUNLOCK() { AFS_ASSERT_GLOCK(); mutex_exit(&afs_global_lock); } 00165 #define ISAFS_GLOCK() mutex_mine(&afs_global_lock) 00166 #else 00167 extern long afs_global_owner; 00168 #define AFS_GLOCK() \ 00169 MACRO_BEGIN \ 00170 AFS_MUTEX_ENTER(&afs_global_lock) ; \ 00171 afs_global_owner = osi_ThreadUnique(); \ 00172 MACRO_END 00173 #define AFS_GUNLOCK() \ 00174 { AFS_ASSERT_GLOCK(); afs_global_owner = 0; mutex_exit(&afs_global_lock); } 00175 #define ISAFS_GLOCK() (osi_ThreadUnique() == afs_global_owner) 00176 #endif /* AFS_SGI64_ENV */ 00177 #else /* MP */ 00178 #define AFS_GLOCK() 00179 #define AFS_GUNLOCK() 00180 #define ISAFS_GLOCK() 1 00181 00182 #define SPLVAR int splvar 00183 #define NETPRI splvar=splnet() 00184 #define USERPRI splx(splvar) 00185 00186 00187 #endif /* MP */ 00188 00189 #endif /* KERNEL */ 00190 00191 #if defined(AFS_SGI62_ENV) 00192 # define osi_InitGlock() \ 00193 mutex_init(&afs_global_lock, MUTEX_DEFAULT, "afs_global_lock"); 00194 #else 00195 # define osi_InitGlock() \ 00196 mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL); 00197 #endif 00198 00199 #ifdef AFS_SGI64_ENV 00200 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \ 00201 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr),\ 00202 (int *)(aresid), &osi_flid) 00203 #else 00204 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \ 00205 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr), \ 00206 (int *)(aresid)) 00207 #endif 00208 00209 #ifdef AFS_SGI64_ENV 00210 #undef suser 00211 #define suser() cap_able(CAP_DEVICE_MGT) 00212 #endif 00213 #define afs_suser(x) suser() 00214 00215 #define afs_hz HZ 00216 00217 #ifdef AFS_SGI64_ENV 00218 #undef setuerror 00219 #undef getuerror 00220 #endif 00221 00222 00223 /* OS independent user structure stuff */ 00224 /* 00225 * OSI_GET_CURRENT_PID 00226 */ 00227 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00228 #define OSI_GET_CURRENT_PID() (u.u_procp->p_pid) 00229 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00230 00231 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV) 00232 #define OSI_GET_CURRENT_PID() current_pid() 00233 #endif /* AFS_SGI64_ENV */ 00234 00235 #if defined(AFS_SGI65_ENV) 00236 #define OSI_GET_CURRENT_PID() proc_pid(curproc()) 00237 #endif 00238 00239 #define getpid() OSI_GET_CURRENT_PID() 00240 00241 /* 00242 * OSI_GET_CURRENT_PROCP 00243 */ 00244 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00245 #define OSI_GET_CURRENT_PROCP() (u.u_procp) 00246 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00247 00248 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV) 00249 #define OSI_GET_CURRENT_PROCP() curprocp 00250 #endif /* AFS_SGI64_ENV */ 00251 00252 #if defined(AFS_SGI65_ENV) 00253 #define OSI_GET_CURRENT_PROCP() UT_TO_PROC(curuthread) 00254 #endif 00255 00256 00257 /* 00258 * OSI_GET_LOCKID 00259 * 00260 * Prior to IRIX 6.4, pid sufficed, now we need kthread. 00261 */ 00262 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00263 #define OSI_GET_LOCKID() (u.u_procp->p_pid) 00264 #define OSI_NO_LOCKID (-1) 00265 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00266 00267 #if defined(AFS_SGI64_ENV) 00268 /* IRIX returns k_id, but this way, we've got the thread address for debugging. */ 00269 #define OSI_GET_LOCKID() \ 00270 (private.p_curkthread ? (uint64_t)private.p_curkthread : (uint64_t)0) 00271 #define OSI_NO_LOCKID ((uint64_t)-1) 00272 #endif /* AFS_SGI64_ENV */ 00273 00274 /* 00275 * OSI_GET_CURRENT_CRED 00276 */ 00277 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00278 #define OSI_GET_CURRENT_CRED() (u.u_cred) 00279 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00280 00281 #if defined(AFS_SGI64_ENV) 00282 #define OSI_GET_CURRENT_CRED() get_current_cred() 00283 #endif /* AFS_SGI64_ENV */ 00284 00285 #define osi_curcred() OSI_GET_CURRENT_CRED() 00286 00287 /* 00288 * OSI_SET_CURRENT_CRED 00289 */ 00290 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00291 #define OSI_SET_CURRENT_CRED(x) u.u_cred=x 00292 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00293 00294 #if defined(AFS_SGI64_ENV) 00295 #define OSI_SET_CURRENT_CRED(C) set_current_cred((C)) 00296 #endif /* AFS_SGI64_ENV */ 00297 00298 /* 00299 * OSI_GET_CURRENT_ABI 00300 */ 00301 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00302 #define OSI_GET_CURRENT_ABI() (u.u_procp->p_abi) 00303 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00304 00305 #if defined(AFS_SGI64_ENV) 00306 #define OSI_GET_CURRENT_ABI() get_current_abi() 00307 #endif /* AFS_SGI64_ENV */ 00308 00309 /* 00310 * OSI_GET_CURRENT_SYSID 00311 */ 00312 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00313 #define OSI_GET_CURRENT_SYSID() (u.u_procp->p_sysid) 00314 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00315 00316 #if defined(AFS_SGI64_ENV) 00317 #define OSI_GET_CURRENT_SYSID() (curprocp->p_flid.fl_sysid) 00318 #endif /* AFS_SGI64_ENV */ 00319 00320 /* 00321 * OSI_GET_CURRENT_COMM 00322 */ 00323 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00324 #define OSI_GET_CURRENT_COMM() (u.u_comm) 00325 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00326 00327 #if defined(AFS_SGI64_ENV) 00328 #define OSI_GET_CURRENT_COMM() (curprocp->p_comm) 00329 #endif /* AFS_SGI64_ENV */ 00330 00331 /* 00332 * OSI_GET_CURRENT_CDIR 00333 */ 00334 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00335 #define OSI_GET_CURRENT_CDIR() (u.u_cdir) 00336 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00337 00338 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV) 00339 #define OSI_GET_CURRENT_CDIR() (curprocp->p_cdir) 00340 #endif /* AFS_SGI64_ENV */ 00341 00342 #if defined(AFS_SGI65_ENV) 00343 #define OSI_GET_CURRENT_CDIR() (curuthread->ut_cdir) 00344 #endif /* AFS_SGI65_ENV */ 00345 00346 00347 /* 00348 * OSI_GET_CURRENT_RDIR 00349 */ 00350 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV) 00351 #define OSI_GET_CURRENT_RDIR() (u.u_rdir) 00352 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */ 00353 00354 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV) 00355 #define OSI_GET_CURRENT_RDIR() (curprocp->p_rdir) 00356 #endif /* AFS_SGI64_ENV */ 00357 00358 #if defined(AFS_SGI65_ENV) 00359 #define OSI_GET_CURRENT_RDIR() (curuthread->ut_rdir) 00360 #endif /* AFS_SGI65_ENV */ 00361 00362 00363 00364 /* Macros for vcache/vnode and vfs arguments to vnode and vfs ops. 00365 * 00366 * Note that the _CONVERT routines get the ";" here so that argument lists 00367 * can have arguments after the OSI_x_CONVERT macro is called. 00368 */ 00369 #ifdef AFS_SGI64_ENV 00370 #undef OSI_VN_ARG 00371 #define OSI_VN_ARG(V) bhv_##V 00372 #undef OSI_VN_DECL 00373 #define OSI_VN_DECL(V) bhv_desc_t *bhv_##V 00374 #undef OSI_VN_CONVERT 00375 #define OSI_VN_CONVERT(V) struct vnode * V = (struct vnode*)BHV_TO_VNODE(bhv_##V) 00376 #undef OSI_VC_ARG 00377 #define OSI_VC_ARG(V) bhv_##V 00378 #undef OSI_VC_DECL 00379 #define OSI_VC_DECL(V) bhv_desc_t *bhv_##V 00380 #undef OSI_VC_CONVERT 00381 #define OSI_VC_CONVERT(V) struct vcache * V = VTOAFS(BHV_TO_VNODE(bhv_##V)) 00382 #undef OSI_VFS_ARG 00383 #define OSI_VFS_ARG(V) bhv_##V 00384 #undef OSI_VFS_DECL 00385 #define OSI_VFS_DECL(V) bhv_desc_t *bhv_##V 00386 #undef OSI_VFS_CONVERT 00387 #define OSI_VFS_CONVERT(V) struct vfs * V = (struct vfs*)bhvtovfs(bhv_##V) 00388 #endif /* AFS_SGI64_ENV */ 00389 00390 #define osi_procname(procname, size) strncpy(procname, proc_name(curproc()), size) 00391 00392 00393 #endif /* _OSI_MACHDEP_H_ */