kill-rxglock-20050413
[openafs.git] / src / afs / FBSD / 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  *
12  * FBSD OSI header file. Extends afs_osi.h.
13  *
14  * afs_osi.h includes this file, which is the only way this file should
15  * be included in a source file. This file can redefine macros declared in
16  * afs_osi.h.
17  */
18
19 #ifndef _OSI_MACHDEP_H_
20 #define _OSI_MACHDEP_H_
21
22 #include <sys/lock.h>
23 #include <sys/time.h>
24 #if defined(AFS_FBSD50_ENV)
25 #include <sys/mutex.h>
26 #endif
27
28 extern struct simplelock afs_rxglobal_lock;
29
30 /* 
31  * Time related macros
32  */
33 #define osi_Time()      time_second
34 #define afs_hz          hz
35
36 #define PAGESIZE 8192
37
38 #define AFS_UCRED       ucred
39 #define AFS_PROC        struct proc
40
41 #define afs_bufferpages bufpages
42 #ifndef iodone
43 #define iodone biodone
44 #endif
45
46 #define osi_vnhold(avc,r)       vref(AFSTOV(avc))
47 #undef vSetVfsp
48 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
49 #undef vSetType
50 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
51 #undef vType
52 #define vType(vc)               AFSTOV(vc)->v_type
53
54 #undef gop_lookupname
55 #define gop_lookupname osi_lookupname
56
57 #undef afs_suser
58
59 #define afs_strcat(s1, s2)      strcat((s1), (s2))
60
61 #ifdef KERNEL
62
63 #undef afs_osi_Alloc_NoSleep
64 #define afs_osi_Alloc_NoSleep(size) osi_fbsd_alloc((size), 0)
65
66 #define VN_RELE(vp)             vrele(vp)
67 #define VN_HOLD(vp)             VREF(vp)
68
69 #if defined(AFS_FBSD50_ENV)
70 #define VT_AFS          "afs"
71 #define VROOT           VV_ROOT
72 #define v_flag          v_vflag
73 #define osi_curcred()   (curthread->td_ucred)
74 #define afs_suser(x)    (!suser(curthread))
75 #define simple_lock(x)  mtx_lock(x)
76 #define simple_unlock(x) mtx_unlock(x)
77 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
78   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread)
79 extern struct mtx afs_global_mtx;
80 #define AFS_GLOCK() mtx_lock(&afs_global_mtx)
81 #define AFS_GUNLOCK() mtx_unlock(&afs_global_mtx)
82 #define ISAFS_GLOCK() (mtx_owned(&afs_global_mtx))
83
84 #else /* FBSD50 */
85 extern struct lock afs_global_lock;
86
87 #define osi_curcred()   (curproc->p_cred->pc_ucred)
88 #define afs_suser(x)    (!suser(curproc))
89 #define getpid()        curproc
90 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
91   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc)
92 extern struct proc *afs_global_owner;
93 #define AFS_GLOCK() \
94     do { \
95         osi_Assert(curproc); \
96         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
97         osi_Assert(afs_global_owner == 0); \
98         afs_global_owner = curproc; \
99     } while (0)
100 #define AFS_GUNLOCK() \
101     do { \
102         osi_Assert(curproc); \
103         osi_Assert(afs_global_owner == curproc); \
104         afs_global_owner = 0; \
105         lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
106     } while(0)
107 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
108 #endif /* FBSD50 */
109
110 #undef SPLVAR
111 #define SPLVAR int splvar
112 #undef NETPRI
113 #define NETPRI splvar=splnet()
114 #undef USERPRI
115 #define USERPRI splx(splvar)
116 #endif /* KERNEL */
117
118 #endif /* _OSI_MACHDEP_H_ */