venus: Remove dedebug
[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 #include <sys/mutex.h>
25 #include <sys/sx.h>
26 #include <sys/vnode.h>
27 #include <sys/priv.h>
28
29 /*
30  * Time related macros
31  */
32 #define osi_Time()      time_second
33 #define afs_hz          hz
34
35 typedef struct ucred afs_ucred_t;
36 typedef struct proc afs_proc_t;
37
38 #define afs_bufferpages bufpages
39 #ifndef iodone
40 #define iodone biodone
41 #endif
42
43 #define VSUID           S_ISUID
44 #define VSGID           S_ISGID
45
46 #define vType(vc)               AFSTOV(vc)->v_type
47 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
48 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
49 #ifdef KERNEL
50 extern struct vop_vector afs_vnodeops;
51 # define IsAfsVnode(v) ((v)->v_op == &afs_vnodeops)
52 #else
53 extern int (**afs_vnodeop_p) ();
54 # define IsAfsVnode(v)           ((v)->v_op == afs_vnodeop_p)
55 #endif
56 #define SetAfsVnode(v)          /* nothing; done in getnewvnode() */
57
58 #define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \
59   vinvalbuf((vp), (flags), (slpflag), (slptimeo))
60
61 #undef gop_lookupname
62 #define gop_lookupname osi_lookupname
63
64 #undef gop_lookupname_user
65 #define gop_lookupname_user osi_lookupname
66
67 #define afs_strcat(s1, s2)      strcat((s1), (s2))
68
69 /* malloc */
70 extern void *osi_fbsd_alloc(size_t size, int dropglobal);
71 extern void osi_fbsd_free(void *p);
72
73 #define afs_osi_Alloc_NoSleep(size) osi_fbsd_alloc((size), 0)
74
75 #define VN_RELE(vp)                             \
76   do {                                          \
77     vrele(vp);                                  \
78   } while(0);
79 #define VN_HOLD(vp)             VREF(vp)
80
81 #undef afs_suser
82 /* OpenAFS-specific privileges negotiated for FreeBSD, thanks due to
83  * Ben Kaduk */
84 #define osi_suser_client_settings(x)   (!priv_check(curthread, PRIV_AFS_ADMIN))
85 #define osi_suser_afs_daemon(x)   (!priv_check(curthread, PRIV_AFS_DAEMON))
86 #define afs_suser(x) (osi_suser_client_settings((x)) && osi_suser_afs_daemon((x)))
87
88 #undef osi_getpid
89 #define VT_AFS          "afs"
90 #define VROOT           VV_ROOT
91 #define v_flag          v_vflag
92 #define osi_curcred()   (curthread->td_ucred)
93 #define osi_curproc()   (curthread)
94 #define osi_getpid()    (curthread->td_proc->p_pid)
95 #define simple_lock(x)  mtx_lock(x)
96 #define simple_unlock(x) mtx_unlock(x)
97 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
98   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread)
99 extern struct mtx afs_global_mtx;
100 extern struct thread *afs_global_owner;
101 #define AFS_GLOCK() \
102     do { \
103         mtx_assert(&afs_global_mtx, (MA_NOTOWNED)); \
104         mtx_lock(&afs_global_mtx); \
105         mtx_assert(&afs_global_mtx, (MA_OWNED|MA_NOTRECURSED)); \
106     } while (0)
107 #define AFS_GUNLOCK() \
108     do { \
109         mtx_assert(&afs_global_mtx, (MA_OWNED|MA_NOTRECURSED)); \
110         mtx_unlock(&afs_global_mtx); \
111     } while (0)
112 #define ISAFS_GLOCK() (mtx_owned(&afs_global_mtx))
113 # ifdef WITNESS
114 #  define osi_InitGlock() \
115         do { \
116             memset(&afs_global_mtx, 0, sizeof(struct mtx)); \
117             mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); \
118             afs_global_owner = 0; \
119         } while(0)
120 # else
121 #  define osi_InitGlock() \
122     do { \
123         mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); \
124         afs_global_owner = 0; \
125     } while (0)
126 # endif
127
128 #undef SPLVAR
129 #define SPLVAR
130 #undef NETPRI
131 #define NETPRI
132 #undef USERPRI
133 #define USERPRI
134
135 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
136
137 static_inline void
138 osi_GetTime(osi_timeval32_t *atv)
139 {
140     struct timeval now;
141     microtime(&now);
142     atv->tv_sec = now.tv_sec;
143     atv->tv_usec = now.tv_usec;
144 }
145
146 #endif /* _OSI_MACHDEP_H_ */