afs: Refactor osi_vnhold/AFS_FAST_HOLD
[openafs.git] / src / afs / NBSD / 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  * NetBSD 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 #define RXK_LISTENER_ENV 1
23 #define AFS_DIRENT 1
24
25 #include <sys/lock.h>
26 #if defined(AFS_NBSD50_ENV)
27 #include <sys/kmem.h>
28 #include <sys/specificdata.h>
29 #include <sys/mutex.h>
30 #include <sys/rwlock.h>
31 #endif
32 #include <sys/syscall.h>
33 #include <sys/syscallargs.h>
34
35 #if defined(AFS_NBSD50_ENV)
36 # if !defined(DEF_CADDR_T)
37 typedef char * caddr_t;
38 #define DEF_CADDR_T
39 # endif
40 #endif
41
42 /* vfs */
43 #define osi_vfs         mount
44 #define osi_vfs_bsize   mnt_stat.f_bsize
45 #define osi_vfs_iosize  mnt_stat.f_iosize
46 #define osi_vfs_fsid    mnt_stat.f_fsid
47 #define vfs_vnodecovered mnt_vnodecovered
48 #define v_vfsp          v_mount
49
50 /* vnode */
51 #define VN_HOLD(vp)     (vget(vp, 0))
52 #define VN_RELE(vp)     (vrele(vp))
53
54 #define va_nodeid       va_fileid
55
56 /* syscall */
57 struct afs_sysargs {
58     syscallarg(long) syscall;
59     syscallarg(long) parm1;
60     syscallarg(long) parm2;
61     syscallarg(long) parm3;
62     syscallarg(long) parm4;
63     syscallarg(long) parm5;
64     syscallarg(long) parm6;
65 };
66
67 /* uio */
68 #define afsio_iov       uio_iov
69 #define afsio_iovcnt    uio_iovcnt
70 #define afsio_offset    uio_offset
71 #define afsio_resid     uio_resid
72 #define afsio_seg       uio_segflg
73 #define AFS_UIOSYS      UIO_SYSSPACE
74 #define AFS_UIOUSER     UIO_USERSPACE
75
76 /* proc */
77 typedef struct lwp afs_proc_t;
78 #define osi_curproc()   curlwp
79 #define getpid()        (osi_curproc())->l_proc->p_pid
80 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
81
82 typedef struct kauth_cred afs_ucred_t;
83 #define osi_curcred()   (kauth_cred_get())
84 #define afs_suser(x)    afs_osi_suser(osi_curcred())
85 #define osi_crgetruid(acred) (kauth_cred_getuid(acred))
86 #define osi_crgetrgid(acred) (kauth_cred_getgid(acred))
87 #define osi_crngroups(acred) (kauth_cred_ngroups(acred))
88 #define osi_proccred(aproc) ((aproc)->l_proc->p_cred)
89 #define osi_crgroupbyid kauth_cred_group
90 #define crdup kauth_cred_dup
91 #define crhold kauth_cred_hold
92 #define crfree kauth_cred_free
93
94 #define afs_cr_gid osi_crgetrgid
95 #define afs_cr_uid osi_crgetruid
96
97 /* time */
98 #define afs_hz          hz
99 #define osi_GetTime(x)  getmicrotime(x)
100 #define osi_Time()      time_second
101
102 /* str */
103 #define afs_strcasecmp(s1, s2)  strncasecmp((s1), (s2), 65535)
104 #define afs_strcat(s1, s2)      strcat((s1), (s2))
105
106 /* other */
107 #define afs_bufferpages bufpages
108 #ifndef iodone
109 #define iodone biodone
110 #endif
111 #define printk          printf  /* for RX version of xdr_* */
112 #define setgroups       sys_setgroups
113 #define UVM
114
115 /* This is not always in scope yet */
116 struct vcache;
117
118 extern int afs_nbsd_lookupname(const char *fnamep, enum uio_seg segflg,
119                                int followlink, struct vnode **compvpp);
120 extern void afs_nbsd_getnewvnode(struct vcache *tvc);
121
122 #undef gop_lookupname
123 #undef gop_lookupname_user
124 #define osi_lookupname_user(fnamep, segflg, followlink, compvpp) \
125         afs_nbsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
126 #define gop_lookupname_user osi_lookupname_user
127 #define gop_lookupname osi_lookupname_user
128
129 #ifdef KERNEL
130 #ifdef AFS_GLOBAL_SUNLOCK
131
132 #if defined(AFS_NBSD50_ENV)
133 extern kmutex_t afs_global_mtx;
134 #define AFS_GLOCK() \
135     do { \
136         mutex_enter(&afs_global_mtx); \
137     } while (0)
138 #define AFS_GUNLOCK() \
139     do { \
140         mutex_exit(&afs_global_mtx); \
141     } while (0)
142 #define ISAFS_GLOCK() (mutex_owned(&afs_global_mtx))
143 #define osi_InitGlock() \
144     do { \
145         mutex_init(&afs_global_mtx, MUTEX_DEFAULT, IPL_NONE); \
146     } while (0)
147 #else /* !50 */
148 extern struct lock afs_global_lock;
149 #if defined(LOCKDEBUG)
150 #define AFS_GLOCK() \
151   do { \
152       _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \
153   } while(0);
154 #define AFS_GUNLOCK() \
155   do { \
156       _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \
157   } while(0);
158 #else
159 #define AFS_GLOCK() \
160   do { \
161     lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \
162   } while(0);
163 #define AFS_GUNLOCK() \
164   do { \
165     lockmgr(&afs_global_lock, LK_RELEASE, NULL); \
166   } while(0);
167 #endif /* LOCKDEBUG */
168 #endif /* !50 */
169 #else
170 #define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE)
171 extern struct lock afs_global_lock;
172 #define AFS_GLOCKP(p)
173 #define AFS_GUNLOCKP(p)
174 #define AFS_ASSERT_GLOCK()
175 #define ISAFS_GLOCK() 1
176 #endif /* !AFS_GLOBAL_SUNLOCK */
177
178 #undef SPLVAR
179 #define SPLVAR int splvar
180 #undef NETPRI
181 #define NETPRI splvar=splnet()
182 #undef USERPRI
183 #define USERPRI splx(splvar)
184 #endif /* KERNEL */
185
186 #if     !defined(ASSEMBLER) && !defined(__LANGUAGE_ASSEMBLY__) && !defined(IGNORE_STDS_H)
187 enum vcexcl { NONEXCL, EXCL };
188
189 #ifndef MIN
190 #define MIN(A,B) ((A) < (B) ? (A) : (B))
191 #endif
192 #ifndef MAX
193 #define MAX(A,B) ((A) > (B) ? (A) : (B))
194 #endif
195
196 #endif /* ASSEMBLER */
197
198 /* vnodes */
199 extern int (**afs_vnodeop_p) __P((void *));
200 #define vType(vc)               AFSTOV(vc)->v_type
201 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
202 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
203 #define IsAfsVnode(v)      ((v)->v_op == afs_vnodeop_p)
204 #define SetAfsVnode(v)     /* nothing; done in getnewvnode() */
205
206 extern int afs_debug;
207
208 #define AFS_USE_NBSD_NAMECACHE 0
209
210 #endif /* _OSI_MACHDEP_H_ */