4c048840a67f0b30f01556ae213564e8e8bb26ab
[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 #include <sys/vnode.h>
28 #if defined(AFS_FBSD80_ENV)
29 #include <sys/priv.h>
30 #endif
31
32 /* 
33  * Time related macros
34  */
35 #define osi_Time()      time_second
36 #define afs_hz          hz
37
38 typedef struct ucred afs_ucred_t;
39 typedef struct proc afs_proc_t;
40
41 #define afs_bufferpages bufpages
42 #ifndef iodone
43 #define iodone biodone
44 #endif
45
46 #define VSUID           S_ISUID
47 #define VSGID           S_ISGID
48
49 #define osi_vnhold(avc,r)       vref(AFSTOV(avc))
50
51 #define vType(vc)               AFSTOV(vc)->v_type
52 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
53 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
54 #if defined(AFS_FBSD60_ENV) && defined(KERNEL)
55 extern struct vop_vector afs_vnodeops;
56 # define IsAfsVnode(v) ((v)->v_op == &afs_vnodeops)
57 #else
58 extern int (**afs_vnodeop_p) ();
59 # define IsAfsVnode(v)           ((v)->v_op == afs_vnodeop_p)
60 #endif
61 #define SetAfsVnode(v)          /* nothing; done in getnewvnode() */
62
63 #if defined(AFS_FBSD80_ENV)
64 #define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \
65   vinvalbuf((vp), (flags), (slpflag), (slptimeo))
66 #else
67 #define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \
68   vinvalbuf((vp), (flags), (curthread), (slpflag), (slptimeo))
69 #endif
70
71 #undef gop_lookupname
72 #define gop_lookupname osi_lookupname
73
74 #undef gop_lookupname_user
75 #define gop_lookupname_user osi_lookupname
76
77 #define afs_strcat(s1, s2)      strcat((s1), (s2))
78
79 #undef afs_osi_Alloc_NoSleep
80 #define afs_osi_Alloc_NoSleep(size) osi_fbsd_alloc((size), 0)
81
82 #ifdef AFS_FBSD80_ENV
83 #define VN_RELE(vp)                             \
84   do {                                          \
85     vrele(vp);                                  \
86   } while(0);
87 #else
88 #define VN_RELE(vp)             vrele(vp)
89 #endif
90 #define VN_HOLD(vp)             VREF(vp)
91
92 #undef afs_suser
93 #if defined(AFS_FBSD80_ENV)
94 /* OpenAFS-specific privileges negotiated for FreeBSD, thanks due to
95  * Ben Kaduk */
96 #define osi_suser_client_settings(x)   (!priv_check(curthread, PRIV_AFS_ADMIN))
97 #define osi_suser_afs_daemon(x)   (!priv_check(curthread, PRIV_AFS_DAEMON))
98 #define afs_suser(x) (osi_suser_client_settings((x)) && osi_suser_afs_daemon((x)))
99 #elif defined(AFS_FBSD50_ENV)
100 #define afs_suser(x)    (!suser(curthread))
101 #else
102 #define afs_suser(x)    (!suser(curproc))
103 #endif
104
105 #undef osi_getpid
106 #if defined(AFS_FBSD50_ENV)
107 #define VT_AFS          "afs"
108 #define VROOT           VV_ROOT
109 #define v_flag          v_vflag
110 #define osi_curcred()   (curthread->td_ucred)
111 #define osi_getpid()    (curthread->td_proc->p_pid)
112 #define simple_lock(x)  mtx_lock(x)
113 #define simple_unlock(x) mtx_unlock(x)
114 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
115   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread)
116 extern struct mtx afs_global_mtx;
117 extern struct thread *afs_global_owner;
118 #define AFS_GLOCK() mtx_lock(&afs_global_mtx)
119 #define AFS_GUNLOCK() mtx_unlock(&afs_global_mtx)
120 #define ISAFS_GLOCK() (mtx_owned(&afs_global_mtx))
121 # if defined(AFS_FBSD80_ENV) && defined(WITNESS)
122 #  define osi_InitGlock() \
123         do { \
124             memset(&afs_global_mtx, 0, sizeof(struct mtx)); \
125             mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); \
126             afs_global_owner = 0; \
127         } while(0)
128 # else
129 #  define osi_InitGlock() \
130     do { \
131         mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); \
132         afs_global_owner = 0; \
133     } while (0)
134 # endif
135 #else /* FBSD50 */
136 extern struct lock afs_global_lock;
137 #define osi_curcred()   (curproc->p_cred->pc_ucred)
138 #define osi_getpid()    (curproc->p_pid)
139 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
140   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc)
141 extern struct proc *afs_global_owner;
142 #define AFS_GLOCK() \
143     do { \
144         osi_Assert(curproc); \
145         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
146         osi_Assert(afs_global_owner == 0); \
147         afs_global_owner = curproc; \
148     } while (0)
149 #define AFS_GUNLOCK() \
150     do { \
151         osi_Assert(curproc); \
152         osi_Assert(afs_global_owner == curproc); \
153         afs_global_owner = 0; \
154         lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
155     } while(0)
156 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
157 #define osi_InitGlock() \
158     do { \
159         lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); \
160         afs_global_owner = 0; \
161     } while (0)
162 #endif /* FBSD50 */
163
164 #undef SPLVAR
165 #define SPLVAR int splvar
166 #undef NETPRI
167 #define NETPRI splvar=splnet()
168 #undef USERPRI
169 #define USERPRI splx(splvar)
170
171 #endif /* _OSI_MACHDEP_H_ */