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