]>
Commit | Line | Data |
---|---|---|
77755a57 BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | * or http://www.opensolaris.org/os/licensing. | |
10 | * See the License for the specific language governing permissions | |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
6283f55e BB |
22 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
23 | * Use is subject to license terms. | |
77755a57 BB |
24 | */ |
25 | ||
26 | #ifndef _SYS_ZFS_CONTEXT_H | |
27 | #define _SYS_ZFS_CONTEXT_H | |
28 | ||
e37e1d30 | 29 | #ifdef __KERNEL__ |
6283f55e BB |
30 | |
31 | #include <sys/note.h> | |
32 | #include <sys/types.h> | |
33 | #include <sys/t_lock.h> | |
34 | #include <sys/atomic.h> | |
35 | #include <sys/sysmacros.h> | |
36 | #include <sys/bitmap.h> | |
37 | #include <sys/cmn_err.h> | |
38 | #include <sys/kmem.h> | |
39 | #include <sys/taskq.h> | |
40 | #include <sys/buf.h> | |
41 | #include <sys/param.h> | |
42 | #include <sys/systm.h> | |
43 | #include <sys/cpuvar.h> | |
44 | #include <sys/kobj.h> | |
45 | #include <sys/conf.h> | |
46 | #include <sys/disp.h> | |
47 | #include <sys/debug.h> | |
48 | #include <sys/random.h> | |
49 | #include <sys/byteorder.h> | |
50 | #include <sys/systm.h> | |
51 | #include <sys/list.h> | |
590329b5 | 52 | #include <sys/uio_impl.h> |
6283f55e BB |
53 | #include <sys/dirent.h> |
54 | #include <sys/time.h> | |
55 | #include <vm/seg_kmem.h> | |
56 | #include <sys/zone.h> | |
6283f55e BB |
57 | #include <sys/zfs_debug.h> |
58 | #include <sys/fm/fs/zfs.h> | |
59 | #include <sys/sunddi.h> | |
8299a1f4 | 60 | #include <linux/dcache_compat.h> |
6283f55e BB |
61 | |
62 | #else /* _KERNEL */ | |
77755a57 BB |
63 | |
64 | #define _SYS_MUTEX_H | |
65 | #define _SYS_RWLOCK_H | |
66 | #define _SYS_CONDVAR_H | |
67 | #define _SYS_SYSTM_H | |
68 | #define _SYS_DEBUG_H | |
69 | #define _SYS_T_LOCK_H | |
70 | #define _SYS_VNODE_H | |
71 | #define _SYS_VFS_H | |
72 | #define _SYS_SUNDDI_H | |
73 | #define _SYS_CALLB_H | |
74 | ||
75 | #include <stdio.h> | |
76 | #include <stdlib.h> | |
77 | #include <stddef.h> | |
78 | #include <stdarg.h> | |
79 | #include <fcntl.h> | |
80 | #include <unistd.h> | |
81 | #include <errno.h> | |
82 | #include <string.h> | |
83 | #include <strings.h> | |
1e33ac1e | 84 | #include <pthread.h> |
77755a57 BB |
85 | #include <assert.h> |
86 | #include <alloca.h> | |
87 | #include <umem.h> | |
88 | #include <limits.h> | |
89 | #include <atomic.h> | |
90 | #include <dirent.h> | |
91 | #include <time.h> | |
92 | #include <sys/note.h> | |
93 | #include <sys/types.h> | |
94 | #include <sys/cred.h> | |
95 | #include <sys/sysmacros.h> | |
96 | #include <sys/bitmap.h> | |
97 | #include <sys/resource.h> | |
98 | #include <sys/byteorder.h> | |
99 | #include <sys/list.h> | |
100 | #include <sys/uio.h> | |
101 | #include <sys/zfs_debug.h> | |
102 | #include <sys/sdt.h> | |
103 | #include <sys/kstat.h> | |
104 | #include <sys/u8_textprep.h> | |
26685276 | 105 | #include <sys/fm/fs/zfs.h> |
428870ff | 106 | #include <sys/sunddi.h> |
77755a57 | 107 | |
60948de1 BB |
108 | /* |
109 | * Stack | |
110 | */ | |
111 | ||
112 | #define noinline __attribute__((noinline)) | |
113 | ||
77755a57 BB |
114 | /* |
115 | * Debugging | |
116 | */ | |
117 | ||
118 | /* | |
119 | * Note that we are not using the debugging levels. | |
120 | */ | |
121 | ||
122 | #define CE_CONT 0 /* continuation */ | |
123 | #define CE_NOTE 1 /* notice */ | |
124 | #define CE_WARN 2 /* warning */ | |
125 | #define CE_PANIC 3 /* panic */ | |
126 | #define CE_IGNORE 4 /* print nothing */ | |
127 | ||
1e33ac1e BB |
128 | extern int aok; |
129 | ||
77755a57 BB |
130 | /* |
131 | * ZFS debugging | |
132 | */ | |
133 | ||
134 | #ifdef ZFS_DEBUG | |
135 | extern void dprintf_setup(int *argc, char **argv); | |
136 | #endif /* ZFS_DEBUG */ | |
137 | ||
138 | extern void cmn_err(int, const char *, ...); | |
139 | extern void vcmn_err(int, const char *, __va_list); | |
140 | extern void panic(const char *, ...); | |
141 | extern void vpanic(const char *, __va_list); | |
142 | ||
143 | #define fm_panic panic | |
144 | ||
77755a57 BB |
145 | /* |
146 | * DTrace SDT probes have different signatures in userland than they do in | |
147 | * kernel. If they're being used in kernel code, re-define them out of | |
148 | * existence for their counterparts in libzpool. | |
149 | */ | |
150 | ||
151 | #ifdef DTRACE_PROBE | |
152 | #undef DTRACE_PROBE | |
153 | #define DTRACE_PROBE(a) ((void)0) | |
154 | #endif /* DTRACE_PROBE */ | |
155 | ||
156 | #ifdef DTRACE_PROBE1 | |
157 | #undef DTRACE_PROBE1 | |
158 | #define DTRACE_PROBE1(a, b, c) ((void)0) | |
159 | #endif /* DTRACE_PROBE1 */ | |
160 | ||
161 | #ifdef DTRACE_PROBE2 | |
162 | #undef DTRACE_PROBE2 | |
163 | #define DTRACE_PROBE2(a, b, c, d, e) ((void)0) | |
164 | #endif /* DTRACE_PROBE2 */ | |
165 | ||
166 | #ifdef DTRACE_PROBE3 | |
167 | #undef DTRACE_PROBE3 | |
168 | #define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) | |
169 | #endif /* DTRACE_PROBE3 */ | |
170 | ||
171 | #ifdef DTRACE_PROBE4 | |
172 | #undef DTRACE_PROBE4 | |
173 | #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) | |
174 | #endif /* DTRACE_PROBE4 */ | |
175 | ||
176 | /* | |
177 | * Threads | |
178 | */ | |
1e33ac1e BB |
179 | #define TS_MAGIC 0x72f158ab4261e538ull |
180 | #define TS_RUN 0x00000002 | |
181 | #ifdef __linux__ | |
182 | #define STACK_SIZE 8192 /* Linux x86 and amd64 */ | |
183 | #else | |
184 | #define STACK_SIZE 24576 /* Solaris */ | |
185 | #endif | |
428870ff | 186 | |
1e33ac1e BB |
187 | #ifdef NPTL_GUARD_WITHIN_STACK |
188 | #define EXTRA_GUARD_BYTES PAGESIZE | |
189 | #else | |
190 | #define EXTRA_GUARD_BYTES 0 | |
191 | #endif | |
428870ff BB |
192 | |
193 | /* in libzpool, p0 exists only to have its address taken */ | |
1e33ac1e | 194 | typedef struct proc { |
428870ff | 195 | uintptr_t this_is_never_used_dont_dereference_it; |
1e33ac1e | 196 | } proc_t; |
428870ff BB |
197 | |
198 | extern struct proc p0; | |
199 | ||
1e33ac1e BB |
200 | typedef void (*thread_func_t)(void *); |
201 | typedef void (*thread_func_arg_t)(void *); | |
202 | typedef pthread_t kt_did_t; | |
203 | ||
204 | typedef struct kthread { | |
205 | kt_did_t t_tid; | |
206 | thread_func_t t_func; | |
207 | void * t_arg; | |
208 | } kthread_t; | |
77755a57 | 209 | |
1e33ac1e BB |
210 | #define tsd_get(key) pthread_getspecific(key) |
211 | #define tsd_set(key, val) pthread_setspecific(key, val) | |
212 | #define curthread zk_thread_current() | |
213 | #define thread_exit zk_thread_exit | |
214 | #define thread_create(stk, stksize, func, arg, len, pp, state, pri) \ | |
215 | zk_thread_create(stk, stksize, (thread_func_t)func, arg, \ | |
216 | len, NULL, state, pri) | |
217 | #define thread_join(t) zk_thread_join(t) | |
218 | #define newproc(f,a,cid,pri,ctp,pid) (ENOSYS) | |
219 | ||
220 | extern kthread_t *zk_thread_current(void); | |
221 | extern void zk_thread_exit(void); | |
222 | extern kthread_t *zk_thread_create(caddr_t stk, size_t stksize, | |
223 | thread_func_t func, void *arg, size_t len, | |
224 | proc_t *pp, int state, pri_t pri); | |
225 | extern void zk_thread_join(kt_did_t tid); | |
226 | ||
227 | #define PS_NONE -1 | |
77755a57 BB |
228 | |
229 | #define issig(why) (FALSE) | |
230 | #define ISSIG(thr, why) (FALSE) | |
231 | ||
232 | /* | |
233 | * Mutexes | |
234 | */ | |
1e33ac1e BB |
235 | #define MTX_MAGIC 0x9522f51362a6e326ull |
236 | #define MTX_INIT ((void *)NULL) | |
237 | #define MTX_DEST ((void *)-1UL) | |
238 | ||
77755a57 BB |
239 | typedef struct kmutex { |
240 | void *m_owner; | |
1e33ac1e BB |
241 | uint64_t m_magic; |
242 | pthread_mutex_t m_lock; | |
77755a57 BB |
243 | } kmutex_t; |
244 | ||
1e33ac1e BB |
245 | #define MUTEX_DEFAULT 0 |
246 | #define MUTEX_HELD(m) ((m)->m_owner == curthread) | |
572e2857 | 247 | #define MUTEX_NOT_HELD(m) (!MUTEX_HELD(m)) |
77755a57 | 248 | |
1e33ac1e BB |
249 | extern void mutex_init(kmutex_t *mp, char *name, int type, void *cookie); |
250 | extern void mutex_destroy(kmutex_t *mp); | |
77755a57 BB |
251 | extern void mutex_enter(kmutex_t *mp); |
252 | extern void mutex_exit(kmutex_t *mp); | |
253 | extern int mutex_tryenter(kmutex_t *mp); | |
254 | extern void *mutex_owner(kmutex_t *mp); | |
1e33ac1e | 255 | extern int mutex_held(kmutex_t *mp); |
77755a57 BB |
256 | |
257 | /* | |
258 | * RW locks | |
259 | */ | |
1e33ac1e BB |
260 | #define RW_MAGIC 0x4d31fb123648e78aull |
261 | #define RW_INIT ((void *)NULL) | |
262 | #define RW_DEST ((void *)-1UL) | |
263 | ||
77755a57 | 264 | typedef struct krwlock { |
1e33ac1e BB |
265 | void *rw_owner; |
266 | void *rw_wr_owner; | |
267 | uint64_t rw_magic; | |
268 | pthread_rwlock_t rw_lock; | |
269 | uint_t rw_readers; | |
77755a57 BB |
270 | } krwlock_t; |
271 | ||
272 | typedef int krw_t; | |
273 | ||
274 | #define RW_READER 0 | |
275 | #define RW_WRITER 1 | |
1e33ac1e | 276 | #define RW_DEFAULT RW_READER |
77755a57 | 277 | |
1e33ac1e BB |
278 | #define RW_READ_HELD(x) ((x)->rw_readers > 0) |
279 | #define RW_WRITE_HELD(x) ((x)->rw_wr_owner == curthread) | |
280 | #define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x)) | |
77755a57 BB |
281 | |
282 | extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg); | |
283 | extern void rw_destroy(krwlock_t *rwlp); | |
284 | extern void rw_enter(krwlock_t *rwlp, krw_t rw); | |
285 | extern int rw_tryenter(krwlock_t *rwlp, krw_t rw); | |
286 | extern int rw_tryupgrade(krwlock_t *rwlp); | |
287 | extern void rw_exit(krwlock_t *rwlp); | |
288 | #define rw_downgrade(rwlp) do { } while (0) | |
289 | ||
290 | extern uid_t crgetuid(cred_t *cr); | |
291 | extern gid_t crgetgid(cred_t *cr); | |
292 | extern int crgetngroups(cred_t *cr); | |
293 | extern gid_t *crgetgroups(cred_t *cr); | |
294 | ||
295 | /* | |
296 | * Condition variables | |
297 | */ | |
1e33ac1e BB |
298 | #define CV_MAGIC 0xd31ea9a83b1b30c4ull |
299 | ||
300 | typedef struct kcondvar { | |
301 | uint64_t cv_magic; | |
302 | pthread_cond_t cv; | |
303 | } kcondvar_t; | |
77755a57 | 304 | |
1e33ac1e | 305 | #define CV_DEFAULT 0 |
77755a57 BB |
306 | |
307 | extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg); | |
308 | extern void cv_destroy(kcondvar_t *cv); | |
309 | extern void cv_wait(kcondvar_t *cv, kmutex_t *mp); | |
310 | extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime); | |
311 | extern void cv_signal(kcondvar_t *cv); | |
312 | extern void cv_broadcast(kcondvar_t *cv); | |
5b63b3eb | 313 | #define cv_timedwait_interruptible(cv, mp, at) cv_timedwait(cv, mp, at); |
77755a57 BB |
314 | |
315 | /* | |
316 | * kstat creation, installation and deletion | |
317 | */ | |
318 | extern kstat_t *kstat_create(char *, int, | |
319 | char *, char *, uchar_t, ulong_t, uchar_t); | |
320 | extern void kstat_install(kstat_t *); | |
321 | extern void kstat_delete(kstat_t *); | |
322 | ||
323 | /* | |
324 | * Kernel memory | |
325 | */ | |
326 | #define KM_SLEEP UMEM_NOFAIL | |
327 | #define KM_PUSHPAGE KM_SLEEP | |
328 | #define KM_NOSLEEP UMEM_DEFAULT | |
00b46022 | 329 | #define KM_NODEBUG 0x0 |
77755a57 BB |
330 | #define KMC_NODEBUG UMC_NODEBUG |
331 | #define kmem_alloc(_s, _f) umem_alloc(_s, _f) | |
332 | #define kmem_zalloc(_s, _f) umem_zalloc(_s, _f) | |
333 | #define kmem_free(_b, _s) umem_free(_b, _s) | |
00b46022 BB |
334 | #define vmem_alloc(_s, _f) kmem_alloc(_s, _f) |
335 | #define vmem_zalloc(_s, _f) kmem_zalloc(_s, _f) | |
336 | #define vmem_free(_b, _s) kmem_free(_b, _s) | |
77755a57 BB |
337 | #define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \ |
338 | umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) | |
339 | #define kmem_cache_destroy(_c) umem_cache_destroy(_c) | |
340 | #define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f) | |
341 | #define kmem_cache_free(_c, _b) umem_cache_free(_c, _b) | |
342 | #define kmem_debugging() 0 | |
572e2857 BB |
343 | #define kmem_cache_reap_now(_c) /* nothing */ |
344 | #define kmem_cache_set_move(_c, _cb) /* nothing */ | |
345 | #define POINTER_INVALIDATE(_pp) /* nothing */ | |
346 | #define POINTER_IS_VALID(_p) 0 | |
77755a57 BB |
347 | |
348 | typedef umem_cache_t kmem_cache_t; | |
349 | ||
572e2857 BB |
350 | typedef enum kmem_cbrc { |
351 | KMEM_CBRC_YES, | |
352 | KMEM_CBRC_NO, | |
353 | KMEM_CBRC_LATER, | |
354 | KMEM_CBRC_DONT_NEED, | |
355 | KMEM_CBRC_DONT_KNOW | |
356 | } kmem_cbrc_t; | |
357 | ||
77755a57 BB |
358 | /* |
359 | * Task queues | |
360 | */ | |
361 | typedef struct taskq taskq_t; | |
362 | typedef uintptr_t taskqid_t; | |
363 | typedef void (task_func_t)(void *); | |
364 | ||
365 | #define TASKQ_PREPOPULATE 0x0001 | |
366 | #define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ | |
367 | #define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ | |
428870ff BB |
368 | #define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */ |
369 | #define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */ | |
77755a57 BB |
370 | |
371 | #define TQ_SLEEP KM_SLEEP /* Can block for memory */ | |
372 | #define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */ | |
428870ff BB |
373 | #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ |
374 | #define TQ_FRONT 0x08 /* Queue in front */ | |
77755a57 BB |
375 | |
376 | extern taskq_t *system_taskq; | |
377 | ||
378 | extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); | |
428870ff BB |
379 | #define taskq_create_proc(a, b, c, d, e, p, f) \ |
380 | (taskq_create(a, b, c, d, e, f)) | |
381 | #define taskq_create_sysdc(a, b, d, e, p, dc, f) \ | |
382 | (taskq_create(a, b, maxclsyspri, d, e, f)) | |
77755a57 BB |
383 | extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); |
384 | extern void taskq_destroy(taskq_t *); | |
385 | extern void taskq_wait(taskq_t *); | |
1e33ac1e | 386 | extern int taskq_member(taskq_t *, kthread_t *); |
77755a57 | 387 | extern void system_taskq_init(void); |
428870ff | 388 | extern void system_taskq_fini(void); |
77755a57 BB |
389 | |
390 | #define XVA_MAPSIZE 3 | |
391 | #define XVA_MAGIC 0x78766174 | |
392 | ||
393 | /* | |
394 | * vnodes | |
395 | */ | |
396 | typedef struct vnode { | |
397 | uint64_t v_size; | |
398 | int v_fd; | |
399 | char *v_path; | |
400 | } vnode_t; | |
401 | ||
428870ff | 402 | #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ |
77755a57 BB |
403 | |
404 | typedef struct xoptattr { | |
405 | timestruc_t xoa_createtime; /* Create time of file */ | |
406 | uint8_t xoa_archive; | |
407 | uint8_t xoa_system; | |
408 | uint8_t xoa_readonly; | |
409 | uint8_t xoa_hidden; | |
410 | uint8_t xoa_nounlink; | |
411 | uint8_t xoa_immutable; | |
412 | uint8_t xoa_appendonly; | |
413 | uint8_t xoa_nodump; | |
414 | uint8_t xoa_settable; | |
415 | uint8_t xoa_opaque; | |
416 | uint8_t xoa_av_quarantined; | |
417 | uint8_t xoa_av_modified; | |
428870ff BB |
418 | uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; |
419 | uint8_t xoa_reparse; | |
572e2857 BB |
420 | uint8_t xoa_offline; |
421 | uint8_t xoa_sparse; | |
77755a57 BB |
422 | } xoptattr_t; |
423 | ||
424 | typedef struct vattr { | |
425 | uint_t va_mask; /* bit-mask of attributes */ | |
426 | u_offset_t va_size; /* file size in bytes */ | |
427 | } vattr_t; | |
428 | ||
429 | ||
430 | typedef struct xvattr { | |
431 | vattr_t xva_vattr; /* Embedded vattr structure */ | |
432 | uint32_t xva_magic; /* Magic Number */ | |
433 | uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ | |
434 | uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ | |
435 | uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ | |
436 | uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ | |
437 | xoptattr_t xva_xoptattrs; /* Optional attributes */ | |
438 | } xvattr_t; | |
439 | ||
440 | typedef struct vsecattr { | |
441 | uint_t vsa_mask; /* See below */ | |
442 | int vsa_aclcnt; /* ACL entry count */ | |
443 | void *vsa_aclentp; /* pointer to ACL entries */ | |
444 | int vsa_dfaclcnt; /* default ACL entry count */ | |
445 | void *vsa_dfaclentp; /* pointer to default ACL entries */ | |
446 | size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ | |
447 | } vsecattr_t; | |
448 | ||
449 | #define AT_TYPE 0x00001 | |
450 | #define AT_MODE 0x00002 | |
451 | #define AT_UID 0x00004 | |
452 | #define AT_GID 0x00008 | |
453 | #define AT_FSID 0x00010 | |
454 | #define AT_NODEID 0x00020 | |
455 | #define AT_NLINK 0x00040 | |
456 | #define AT_SIZE 0x00080 | |
457 | #define AT_ATIME 0x00100 | |
458 | #define AT_MTIME 0x00200 | |
459 | #define AT_CTIME 0x00400 | |
460 | #define AT_RDEV 0x00800 | |
461 | #define AT_BLKSIZE 0x01000 | |
462 | #define AT_NBLOCKS 0x02000 | |
463 | #define AT_SEQ 0x08000 | |
464 | #define AT_XVATTR 0x10000 | |
465 | ||
466 | #define CRCREAT 0 | |
467 | ||
428870ff BB |
468 | extern int fop_getattr(vnode_t *vp, vattr_t *vap); |
469 | ||
77755a57 BB |
470 | #define VOP_CLOSE(vp, f, c, o, cr, ct) 0 |
471 | #define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0 | |
428870ff | 472 | #define VOP_GETATTR(vp, vap, fl, cr, ct) fop_getattr((vp), (vap)); |
77755a57 BB |
473 | |
474 | #define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd) | |
475 | ||
476 | #define VN_RELE(vp) vn_close(vp) | |
477 | ||
478 | extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp, | |
479 | int x2, int x3); | |
480 | extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp, | |
481 | int x2, int x3, vnode_t *vp, int fd); | |
482 | extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, | |
483 | offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp); | |
484 | extern void vn_close(vnode_t *vp); | |
485 | ||
486 | #define vn_remove(path, x1, x2) remove(path) | |
487 | #define vn_rename(from, to, seg) rename((from), (to)) | |
488 | #define vn_is_readonly(vp) B_FALSE | |
489 | ||
490 | extern vnode_t *rootdir; | |
491 | ||
492 | #include <sys/file.h> /* for FREAD, FWRITE, etc */ | |
493 | ||
494 | /* | |
495 | * Random stuff | |
496 | */ | |
428870ff BB |
497 | #define ddi_get_lbolt() (gethrtime() >> 23) |
498 | #define ddi_get_lbolt64() (gethrtime() >> 23) | |
77755a57 BB |
499 | #define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */ |
500 | ||
501 | extern void delay(clock_t ticks); | |
502 | ||
503 | #define gethrestime_sec() time(NULL) | |
428870ff BB |
504 | #define gethrestime(t) \ |
505 | do {\ | |
506 | (t)->tv_sec = gethrestime_sec();\ | |
507 | (t)->tv_nsec = 0;\ | |
508 | } while (0); | |
77755a57 BB |
509 | |
510 | #define max_ncpus 64 | |
511 | ||
512 | #define minclsyspri 60 | |
513 | #define maxclsyspri 99 | |
514 | ||
1e33ac1e | 515 | #define CPU_SEQID (pthread_self() & (max_ncpus - 1)) |
77755a57 BB |
516 | |
517 | #define kcred NULL | |
518 | #define CRED() NULL | |
519 | ||
520 | #define ptob(x) ((x) * PAGESIZE) | |
521 | ||
522 | extern uint64_t physmem; | |
523 | ||
524 | extern int highbit(ulong_t i); | |
525 | extern int random_get_bytes(uint8_t *ptr, size_t len); | |
526 | extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len); | |
527 | ||
528 | extern void kernel_init(int); | |
529 | extern void kernel_fini(void); | |
530 | ||
531 | struct spa; | |
532 | extern void nicenum(uint64_t num, char *buf); | |
533 | extern void show_pool_stats(struct spa *); | |
534 | ||
535 | typedef struct callb_cpr { | |
536 | kmutex_t *cc_lockp; | |
537 | } callb_cpr_t; | |
538 | ||
539 | #define CALLB_CPR_INIT(cp, lockp, func, name) { \ | |
540 | (cp)->cc_lockp = lockp; \ | |
541 | } | |
542 | ||
543 | #define CALLB_CPR_SAFE_BEGIN(cp) { \ | |
544 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
545 | } | |
546 | ||
547 | #define CALLB_CPR_SAFE_END(cp, lockp) { \ | |
548 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
549 | } | |
550 | ||
551 | #define CALLB_CPR_EXIT(cp) { \ | |
552 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
553 | mutex_exit((cp)->cc_lockp); \ | |
554 | } | |
555 | ||
556 | #define zone_dataset_visible(x, y) (1) | |
557 | #define INGLOBALZONE(z) (1) | |
558 | ||
00b46022 | 559 | extern char *kmem_vasprintf(const char *fmt, va_list adx); |
428870ff BB |
560 | extern char *kmem_asprintf(const char *fmt, ...); |
561 | #define strfree(str) kmem_free((str), strlen(str)+1) | |
562 | ||
77755a57 BB |
563 | /* |
564 | * Hostname information | |
565 | */ | |
d164b209 | 566 | extern char hw_serial[]; /* for userland-emulated hostid access */ |
77755a57 BB |
567 | extern int ddi_strtoul(const char *str, char **nptr, int base, |
568 | unsigned long *result); | |
569 | ||
428870ff BB |
570 | extern int ddi_strtoull(const char *str, char **nptr, int base, |
571 | u_longlong_t *result); | |
572 | ||
77755a57 BB |
573 | /* ZFS Boot Related stuff. */ |
574 | ||
575 | struct _buf { | |
576 | intptr_t _fd; | |
577 | }; | |
578 | ||
579 | struct bootstat { | |
580 | uint64_t st_size; | |
581 | }; | |
582 | ||
583 | typedef struct ace_object { | |
584 | uid_t a_who; | |
585 | uint32_t a_access_mask; | |
586 | uint16_t a_flags; | |
587 | uint16_t a_type; | |
588 | uint8_t a_obj_type[16]; | |
589 | uint8_t a_inherit_obj_type[16]; | |
590 | } ace_object_t; | |
591 | ||
592 | ||
593 | #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 | |
594 | #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 | |
595 | #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 | |
596 | #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 | |
597 | ||
598 | extern struct _buf *kobj_open_file(char *name); | |
599 | extern int kobj_read_file(struct _buf *file, char *buf, unsigned size, | |
600 | unsigned off); | |
601 | extern void kobj_close_file(struct _buf *file); | |
602 | extern int kobj_get_filesize(struct _buf *file, uint64_t *size); | |
603 | extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); | |
604 | extern int zfs_secpolicy_rename_perms(const char *from, const char *to, | |
605 | cred_t *cr); | |
606 | extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); | |
607 | extern zoneid_t getzoneid(void); | |
608 | ||
609 | /* SID stuff */ | |
610 | typedef struct ksiddomain { | |
611 | uint_t kd_ref; | |
612 | uint_t kd_len; | |
613 | char *kd_name; | |
614 | } ksiddomain_t; | |
615 | ||
616 | ksiddomain_t *ksid_lookupdomain(const char *); | |
617 | void ksiddomain_rele(ksiddomain_t *); | |
618 | ||
9babb374 BB |
619 | #define DDI_SLEEP KM_SLEEP |
620 | #define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \ | |
621 | sysevent_post_event(_c, _d, _b, "libzpool", _e, _f) | |
622 | ||
6283f55e | 623 | #endif /* _KERNEL */ |
77755a57 BB |
624 | |
625 | #endif /* _SYS_ZFS_CONTEXT_H */ |