]>
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 | /* | |
ed828c0c GM |
22 | * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
23 | * Copyright 2011 Nexenta Systems, Inc. All rights reserved. | |
24 | * Copyright (c) 2012, 2016 by Delphix. All rights reserved. | |
37abac6d | 25 | * Copyright (c) 2012, Joyent, Inc. All rights reserved. |
a38718a6 | 26 | */ |
77755a57 BB |
27 | |
28 | #ifndef _SYS_ZFS_CONTEXT_H | |
29 | #define _SYS_ZFS_CONTEXT_H | |
30 | ||
e37e1d30 | 31 | #ifdef __KERNEL__ |
6283f55e BB |
32 | |
33 | #include <sys/note.h> | |
34 | #include <sys/types.h> | |
35 | #include <sys/t_lock.h> | |
36 | #include <sys/atomic.h> | |
37 | #include <sys/sysmacros.h> | |
38 | #include <sys/bitmap.h> | |
39 | #include <sys/cmn_err.h> | |
40 | #include <sys/kmem.h> | |
60e1eda9 | 41 | #include <sys/kmem_cache.h> |
efcd79a8 | 42 | #include <sys/vmem.h> |
6283f55e BB |
43 | #include <sys/taskq.h> |
44 | #include <sys/buf.h> | |
45 | #include <sys/param.h> | |
46 | #include <sys/systm.h> | |
47 | #include <sys/cpuvar.h> | |
48 | #include <sys/kobj.h> | |
49 | #include <sys/conf.h> | |
50 | #include <sys/disp.h> | |
51 | #include <sys/debug.h> | |
52 | #include <sys/random.h> | |
53 | #include <sys/byteorder.h> | |
54 | #include <sys/systm.h> | |
55 | #include <sys/list.h> | |
590329b5 | 56 | #include <sys/uio_impl.h> |
6283f55e BB |
57 | #include <sys/dirent.h> |
58 | #include <sys/time.h> | |
59 | #include <vm/seg_kmem.h> | |
60 | #include <sys/zone.h> | |
2e528b49 | 61 | #include <sys/sdt.h> |
0b04990a | 62 | #include <sys/kstat.h> |
6283f55e | 63 | #include <sys/zfs_debug.h> |
fb390aaf HR |
64 | #include <sys/sysevent.h> |
65 | #include <sys/sysevent/eventdefs.h> | |
e8b96c60 | 66 | #include <sys/zfs_delay.h> |
6283f55e | 67 | #include <sys/sunddi.h> |
d96eb2b1 | 68 | #include <sys/ctype.h> |
15a9e033 | 69 | #include <sys/disp.h> |
0b39b9f9 | 70 | #include <sys/trace.h> |
8299a1f4 | 71 | #include <linux/dcache_compat.h> |
f0e324f2 | 72 | #include <linux/utsname_compat.h> |
6283f55e BB |
73 | |
74 | #else /* _KERNEL */ | |
77755a57 BB |
75 | |
76 | #define _SYS_MUTEX_H | |
77 | #define _SYS_RWLOCK_H | |
78 | #define _SYS_CONDVAR_H | |
79 | #define _SYS_SYSTM_H | |
77755a57 BB |
80 | #define _SYS_T_LOCK_H |
81 | #define _SYS_VNODE_H | |
82 | #define _SYS_VFS_H | |
83 | #define _SYS_SUNDDI_H | |
84 | #define _SYS_CALLB_H | |
85 | ||
86 | #include <stdio.h> | |
87 | #include <stdlib.h> | |
88 | #include <stddef.h> | |
89 | #include <stdarg.h> | |
90 | #include <fcntl.h> | |
91 | #include <unistd.h> | |
92 | #include <errno.h> | |
93 | #include <string.h> | |
94 | #include <strings.h> | |
1e33ac1e | 95 | #include <pthread.h> |
d99a0153 | 96 | #include <setjmp.h> |
3af3df90 | 97 | #include <synch.h> |
77755a57 BB |
98 | #include <assert.h> |
99 | #include <alloca.h> | |
100 | #include <umem.h> | |
101 | #include <limits.h> | |
102 | #include <atomic.h> | |
103 | #include <dirent.h> | |
104 | #include <time.h> | |
d96eb2b1 | 105 | #include <ctype.h> |
498877ba MA |
106 | #include <signal.h> |
107 | #include <sys/mman.h> | |
77755a57 BB |
108 | #include <sys/note.h> |
109 | #include <sys/types.h> | |
110 | #include <sys/cred.h> | |
111 | #include <sys/sysmacros.h> | |
112 | #include <sys/bitmap.h> | |
113 | #include <sys/resource.h> | |
114 | #include <sys/byteorder.h> | |
115 | #include <sys/list.h> | |
116 | #include <sys/uio.h> | |
117 | #include <sys/zfs_debug.h> | |
118 | #include <sys/sdt.h> | |
119 | #include <sys/kstat.h> | |
120 | #include <sys/u8_textprep.h> | |
fb390aaf HR |
121 | #include <sys/sysevent.h> |
122 | #include <sys/sysevent/eventdefs.h> | |
428870ff | 123 | #include <sys/sunddi.h> |
c99c9001 | 124 | #include <sys/debug.h> |
f0e324f2 | 125 | #include <sys/utsname.h> |
77755a57 | 126 | |
60948de1 BB |
127 | /* |
128 | * Stack | |
129 | */ | |
130 | ||
2e528b49 | 131 | #define noinline __attribute__((noinline)) |
ee36c709 | 132 | #define likely(x) __builtin_expect((x), 1) |
60948de1 | 133 | |
77755a57 BB |
134 | /* |
135 | * Debugging | |
136 | */ | |
137 | ||
138 | /* | |
139 | * Note that we are not using the debugging levels. | |
140 | */ | |
141 | ||
142 | #define CE_CONT 0 /* continuation */ | |
143 | #define CE_NOTE 1 /* notice */ | |
144 | #define CE_WARN 2 /* warning */ | |
145 | #define CE_PANIC 3 /* panic */ | |
146 | #define CE_IGNORE 4 /* print nothing */ | |
147 | ||
148 | /* | |
149 | * ZFS debugging | |
150 | */ | |
151 | ||
77755a57 | 152 | extern void dprintf_setup(int *argc, char **argv); |
0b39b9f9 | 153 | |
77755a57 | 154 | extern void cmn_err(int, const char *, ...); |
22a11a5b | 155 | extern void vcmn_err(int, const char *, va_list); |
d99a0153 CW |
156 | extern void panic(const char *, ...) __NORETURN; |
157 | extern void vpanic(const char *, va_list) __NORETURN; | |
77755a57 BB |
158 | |
159 | #define fm_panic panic | |
160 | ||
0b39b9f9 PS |
161 | extern int aok; |
162 | ||
77755a57 BB |
163 | /* |
164 | * DTrace SDT probes have different signatures in userland than they do in | |
fcff0f35 | 165 | * the kernel. If they're being used in kernel code, re-define them out of |
77755a57 | 166 | * existence for their counterparts in libzpool. |
fcff0f35 PD |
167 | * |
168 | * Here's an example of how to use the set-error probes in userland: | |
169 | * zfs$target:::set-error /arg0 == EBUSY/ {stack();} | |
170 | * | |
171 | * Here's an example of how to use DTRACE_PROBE probes in userland: | |
172 | * If there is a probe declared as follows: | |
173 | * DTRACE_PROBE2(zfs__probe_name, uint64_t, blkid, dnode_t *, dn); | |
174 | * Then you can use it as follows: | |
175 | * zfs$target:::probe2 /copyinstr(arg0) == "zfs__probe_name"/ | |
176 | * {printf("%u %p\n", arg1, arg2);} | |
77755a57 BB |
177 | */ |
178 | ||
179 | #ifdef DTRACE_PROBE | |
180 | #undef DTRACE_PROBE | |
77755a57 | 181 | #endif /* DTRACE_PROBE */ |
2e528b49 MA |
182 | #define DTRACE_PROBE(a) \ |
183 | ZFS_PROBE0(#a) | |
77755a57 BB |
184 | |
185 | #ifdef DTRACE_PROBE1 | |
186 | #undef DTRACE_PROBE1 | |
77755a57 | 187 | #endif /* DTRACE_PROBE1 */ |
2e528b49 MA |
188 | #define DTRACE_PROBE1(a, b, c) \ |
189 | ZFS_PROBE1(#a, (unsigned long)c) | |
77755a57 BB |
190 | |
191 | #ifdef DTRACE_PROBE2 | |
192 | #undef DTRACE_PROBE2 | |
77755a57 | 193 | #endif /* DTRACE_PROBE2 */ |
2e528b49 MA |
194 | #define DTRACE_PROBE2(a, b, c, d, e) \ |
195 | ZFS_PROBE2(#a, (unsigned long)c, (unsigned long)e) | |
77755a57 BB |
196 | |
197 | #ifdef DTRACE_PROBE3 | |
198 | #undef DTRACE_PROBE3 | |
77755a57 | 199 | #endif /* DTRACE_PROBE3 */ |
2e528b49 MA |
200 | #define DTRACE_PROBE3(a, b, c, d, e, f, g) \ |
201 | ZFS_PROBE3(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g) | |
77755a57 BB |
202 | |
203 | #ifdef DTRACE_PROBE4 | |
204 | #undef DTRACE_PROBE4 | |
77755a57 | 205 | #endif /* DTRACE_PROBE4 */ |
2e528b49 MA |
206 | #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) \ |
207 | ZFS_PROBE4(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g, \ | |
208 | (unsigned long)i) | |
77755a57 BB |
209 | |
210 | /* | |
c25b8f99 | 211 | * Threads. |
77755a57 | 212 | */ |
c25b8f99 BB |
213 | typedef pthread_t kthread_t; |
214 | ||
215 | #define TS_RUN 0x00000002 | |
216 | #define TS_JOINABLE 0x00000004 | |
217 | ||
218 | #define curthread ((void *)(uintptr_t)pthread_self()) | |
219 | #define kpreempt(x) yield() | |
220 | #define getcomm() "unknown" | |
221 | ||
222 | #define thread_create(stk, stksize, func, arg, len, pp, state, pri) \ | |
223 | zk_thread_create(func, arg, stksize, state) | |
224 | #define thread_exit() pthread_exit(NULL) | |
225 | #define thread_join(t) pthread_join((pthread_t)(t), NULL) | |
226 | ||
227 | #define newproc(f, a, cid, pri, ctp, pid) (ENOSYS) | |
428870ff | 228 | |
428870ff | 229 | /* in libzpool, p0 exists only to have its address taken */ |
1e33ac1e | 230 | typedef struct proc { |
428870ff | 231 | uintptr_t this_is_never_used_dont_dereference_it; |
1e33ac1e | 232 | } proc_t; |
428870ff BB |
233 | |
234 | extern struct proc p0; | |
37abac6d | 235 | #define curproc (&p0) |
428870ff | 236 | |
c25b8f99 | 237 | #define PS_NONE -1 |
77755a57 | 238 | |
c25b8f99 BB |
239 | extern kthread_t *zk_thread_create(void (*func)(void *), void *arg, |
240 | size_t stksize, int state); | |
1e33ac1e | 241 | |
c25b8f99 BB |
242 | #define issig(why) (FALSE) |
243 | #define ISSIG(thr, why) (FALSE) | |
1e33ac1e | 244 | |
15a9e033 PS |
245 | #define kpreempt_disable() ((void)0) |
246 | #define kpreempt_enable() ((void)0) | |
247 | ||
77755a57 BB |
248 | /* |
249 | * Mutexes | |
250 | */ | |
251 | typedef struct kmutex { | |
c25b8f99 BB |
252 | pthread_mutex_t m_lock; |
253 | pthread_t m_owner; | |
77755a57 BB |
254 | } kmutex_t; |
255 | ||
c25b8f99 BB |
256 | #define MUTEX_DEFAULT 0 |
257 | #define MUTEX_NOLOCKDEP MUTEX_DEFAULT | |
258 | #define MUTEX_HELD(mp) pthread_equal((mp)->m_owner, pthread_self()) | |
259 | #define MUTEX_NOT_HELD(mp) !MUTEX_HELD(mp) | |
77755a57 | 260 | |
1e33ac1e BB |
261 | extern void mutex_init(kmutex_t *mp, char *name, int type, void *cookie); |
262 | extern void mutex_destroy(kmutex_t *mp); | |
77755a57 BB |
263 | extern void mutex_enter(kmutex_t *mp); |
264 | extern void mutex_exit(kmutex_t *mp); | |
265 | extern int mutex_tryenter(kmutex_t *mp); | |
77755a57 BB |
266 | |
267 | /* | |
268 | * RW locks | |
269 | */ | |
270 | typedef struct krwlock { | |
1e33ac1e | 271 | pthread_rwlock_t rw_lock; |
c25b8f99 | 272 | pthread_t rw_owner; |
1e33ac1e | 273 | uint_t rw_readers; |
77755a57 BB |
274 | } krwlock_t; |
275 | ||
276 | typedef int krw_t; | |
277 | ||
c25b8f99 BB |
278 | #define RW_READER 0 |
279 | #define RW_WRITER 1 | |
280 | #define RW_DEFAULT RW_READER | |
281 | #define RW_NOLOCKDEP RW_READER | |
77755a57 | 282 | |
c25b8f99 BB |
283 | #define RW_READ_HELD(rw) ((rw)->rw_readers > 0) |
284 | #define RW_WRITE_HELD(rw) pthread_equal((rw)->rw_owner, pthread_self()) | |
285 | #define RW_LOCK_HELD(rw) (RW_READ_HELD(rw) || RW_WRITE_HELD(rw)) | |
13fe0198 | 286 | |
77755a57 BB |
287 | extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg); |
288 | extern void rw_destroy(krwlock_t *rwlp); | |
289 | extern void rw_enter(krwlock_t *rwlp, krw_t rw); | |
290 | extern int rw_tryenter(krwlock_t *rwlp, krw_t rw); | |
291 | extern int rw_tryupgrade(krwlock_t *rwlp); | |
292 | extern void rw_exit(krwlock_t *rwlp); | |
293 | #define rw_downgrade(rwlp) do { } while (0) | |
294 | ||
c25b8f99 BB |
295 | /* |
296 | * Credentials | |
297 | */ | |
77755a57 | 298 | extern uid_t crgetuid(cred_t *cr); |
6f1ffb06 | 299 | extern uid_t crgetruid(cred_t *cr); |
77755a57 BB |
300 | extern gid_t crgetgid(cred_t *cr); |
301 | extern int crgetngroups(cred_t *cr); | |
302 | extern gid_t *crgetgroups(cred_t *cr); | |
303 | ||
304 | /* | |
305 | * Condition variables | |
306 | */ | |
c25b8f99 | 307 | typedef pthread_cond_t kcondvar_t; |
77755a57 | 308 | |
c25b8f99 | 309 | #define CV_DEFAULT 0 |
206971d2 | 310 | #define CALLOUT_FLAG_ABSOLUTE 0x2 |
77755a57 BB |
311 | |
312 | extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg); | |
313 | extern void cv_destroy(kcondvar_t *cv); | |
314 | extern void cv_wait(kcondvar_t *cv, kmutex_t *mp); | |
315 | extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime); | |
63fd3c6c AL |
316 | extern clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim, |
317 | hrtime_t res, int flag); | |
77755a57 BB |
318 | extern void cv_signal(kcondvar_t *cv); |
319 | extern void cv_broadcast(kcondvar_t *cv); | |
c25b8f99 | 320 | |
8fb1ede1 | 321 | #define cv_timedwait_io(cv, mp, at) cv_timedwait(cv, mp, at) |
b64ccd6c BB |
322 | #define cv_timedwait_sig(cv, mp, at) cv_timedwait(cv, mp, at) |
323 | #define cv_wait_sig(cv, mp) cv_wait(cv, mp) | |
2e528b49 | 324 | #define cv_wait_io(cv, mp) cv_wait(cv, mp) |
a9bb2b68 CC |
325 | #define cv_timedwait_sig_hires(cv, mp, t, r, f) \ |
326 | cv_timedwait_hires(cv, mp, t, r, f) | |
77755a57 | 327 | |
13fe0198 MA |
328 | /* |
329 | * Thread-specific data | |
330 | */ | |
331 | #define tsd_get(k) pthread_getspecific(k) | |
332 | #define tsd_set(k, v) pthread_setspecific(k, v) | |
333 | #define tsd_create(kp, d) pthread_key_create(kp, d) | |
334 | #define tsd_destroy(kp) /* nothing */ | |
335 | ||
336 | /* | |
337 | * Thread-specific data | |
338 | */ | |
339 | #define tsd_get(k) pthread_getspecific(k) | |
340 | #define tsd_set(k, v) pthread_setspecific(k, v) | |
341 | #define tsd_create(kp, d) pthread_key_create(kp, d) | |
342 | #define tsd_destroy(kp) /* nothing */ | |
343 | ||
77755a57 BB |
344 | /* |
345 | * kstat creation, installation and deletion | |
346 | */ | |
330847ff MA |
347 | extern kstat_t *kstat_create(const char *, int, |
348 | const char *, const char *, uchar_t, ulong_t, uchar_t); | |
4e21fd06 | 349 | extern void kstat_named_init(kstat_named_t *, const char *, uchar_t); |
77755a57 BB |
350 | extern void kstat_install(kstat_t *); |
351 | extern void kstat_delete(kstat_t *); | |
330847ff MA |
352 | extern void kstat_waitq_enter(kstat_io_t *); |
353 | extern void kstat_waitq_exit(kstat_io_t *); | |
354 | extern void kstat_runq_enter(kstat_io_t *); | |
355 | extern void kstat_runq_exit(kstat_io_t *); | |
356 | extern void kstat_waitq_to_runq(kstat_io_t *); | |
357 | extern void kstat_runq_back_to_waitq(kstat_io_t *); | |
1421c891 PS |
358 | extern void kstat_set_raw_ops(kstat_t *ksp, |
359 | int (*headers)(char *buf, size_t size), | |
360 | int (*data)(char *buf, size_t size, void *data), | |
361 | void *(*addr)(kstat_t *ksp, loff_t index)); | |
77755a57 BB |
362 | |
363 | /* | |
364 | * Kernel memory | |
365 | */ | |
366 | #define KM_SLEEP UMEM_NOFAIL | |
367 | #define KM_PUSHPAGE KM_SLEEP | |
368 | #define KM_NOSLEEP UMEM_DEFAULT | |
d99a0153 | 369 | #define KM_NORMALPRI 0 /* not needed with UMEM_DEFAULT */ |
77755a57 | 370 | #define KMC_NODEBUG UMC_NODEBUG |
ae6ba3db BB |
371 | #define KMC_KMEM 0x0 |
372 | #define KMC_VMEM 0x0 | |
77755a57 BB |
373 | #define kmem_alloc(_s, _f) umem_alloc(_s, _f) |
374 | #define kmem_zalloc(_s, _f) umem_zalloc(_s, _f) | |
375 | #define kmem_free(_b, _s) umem_free(_b, _s) | |
00b46022 BB |
376 | #define vmem_alloc(_s, _f) kmem_alloc(_s, _f) |
377 | #define vmem_zalloc(_s, _f) kmem_zalloc(_s, _f) | |
378 | #define vmem_free(_b, _s) kmem_free(_b, _s) | |
77755a57 BB |
379 | #define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \ |
380 | umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) | |
381 | #define kmem_cache_destroy(_c) umem_cache_destroy(_c) | |
382 | #define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f) | |
383 | #define kmem_cache_free(_c, _b) umem_cache_free(_c, _b) | |
384 | #define kmem_debugging() 0 | |
669dedb3 | 385 | #define kmem_cache_reap_now(_c) umem_cache_reap_now(_c); |
572e2857 | 386 | #define kmem_cache_set_move(_c, _cb) /* nothing */ |
ca67b33a | 387 | #define vmem_qcache_reap(_v) /* nothing */ |
572e2857 BB |
388 | #define POINTER_INVALIDATE(_pp) /* nothing */ |
389 | #define POINTER_IS_VALID(_p) 0 | |
77755a57 | 390 | |
ca67b33a MA |
391 | extern vmem_t *zio_arena; |
392 | ||
77755a57 BB |
393 | typedef umem_cache_t kmem_cache_t; |
394 | ||
572e2857 BB |
395 | typedef enum kmem_cbrc { |
396 | KMEM_CBRC_YES, | |
397 | KMEM_CBRC_NO, | |
398 | KMEM_CBRC_LATER, | |
399 | KMEM_CBRC_DONT_NEED, | |
400 | KMEM_CBRC_DONT_KNOW | |
401 | } kmem_cbrc_t; | |
402 | ||
77755a57 BB |
403 | /* |
404 | * Task queues | |
405 | */ | |
0b04990a TC |
406 | |
407 | #define TASKQ_NAMELEN 31 | |
408 | ||
77755a57 BB |
409 | typedef uintptr_t taskqid_t; |
410 | typedef void (task_func_t)(void *); | |
411 | ||
a38718a6 GA |
412 | typedef struct taskq_ent { |
413 | struct taskq_ent *tqent_next; | |
414 | struct taskq_ent *tqent_prev; | |
415 | task_func_t *tqent_func; | |
416 | void *tqent_arg; | |
417 | uintptr_t tqent_flags; | |
418 | } taskq_ent_t; | |
419 | ||
0b04990a TC |
420 | typedef struct taskq { |
421 | char tq_name[TASKQ_NAMELEN + 1]; | |
422 | kmutex_t tq_lock; | |
423 | krwlock_t tq_threadlock; | |
424 | kcondvar_t tq_dispatch_cv; | |
425 | kcondvar_t tq_wait_cv; | |
426 | kthread_t **tq_threadlist; | |
427 | int tq_flags; | |
428 | int tq_active; | |
429 | int tq_nthreads; | |
430 | int tq_nalloc; | |
431 | int tq_minalloc; | |
432 | int tq_maxalloc; | |
433 | kcondvar_t tq_maxalloc_cv; | |
434 | int tq_maxalloc_wait; | |
435 | taskq_ent_t *tq_freelist; | |
436 | taskq_ent_t tq_task; | |
437 | } taskq_t; | |
438 | ||
a38718a6 GA |
439 | #define TQENT_FLAG_PREALLOC 0x1 /* taskq_dispatch_ent used */ |
440 | ||
77755a57 BB |
441 | #define TASKQ_PREPOPULATE 0x0001 |
442 | #define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ | |
443 | #define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ | |
428870ff BB |
444 | #define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */ |
445 | #define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */ | |
77755a57 BB |
446 | |
447 | #define TQ_SLEEP KM_SLEEP /* Can block for memory */ | |
448 | #define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */ | |
428870ff BB |
449 | #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ |
450 | #define TQ_FRONT 0x08 /* Queue in front */ | |
77755a57 | 451 | |
48d3eb40 BB |
452 | #define TASKQID_INVALID ((taskqid_t)0) |
453 | ||
77755a57 | 454 | extern taskq_t *system_taskq; |
57ddcda1 | 455 | extern taskq_t *system_delay_taskq; |
77755a57 BB |
456 | |
457 | extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); | |
428870ff BB |
458 | #define taskq_create_proc(a, b, c, d, e, p, f) \ |
459 | (taskq_create(a, b, c, d, e, f)) | |
460 | #define taskq_create_sysdc(a, b, d, e, p, dc, f) \ | |
461 | (taskq_create(a, b, maxclsyspri, d, e, f)) | |
77755a57 | 462 | extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); |
cc92e9d0 GW |
463 | extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *, uint_t, |
464 | clock_t); | |
a38718a6 GA |
465 | extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, |
466 | taskq_ent_t *); | |
467 | extern int taskq_empty_ent(taskq_ent_t *); | |
468 | extern void taskq_init_ent(taskq_ent_t *); | |
77755a57 BB |
469 | extern void taskq_destroy(taskq_t *); |
470 | extern void taskq_wait(taskq_t *); | |
044baf00 | 471 | extern void taskq_wait_id(taskq_t *, taskqid_t); |
4f34bd97 | 472 | extern void taskq_wait_outstanding(taskq_t *, taskqid_t); |
1e33ac1e | 473 | extern int taskq_member(taskq_t *, kthread_t *); |
cc92e9d0 | 474 | extern int taskq_cancel_id(taskq_t *, taskqid_t); |
77755a57 | 475 | extern void system_taskq_init(void); |
428870ff | 476 | extern void system_taskq_fini(void); |
77755a57 BB |
477 | |
478 | #define XVA_MAPSIZE 3 | |
479 | #define XVA_MAGIC 0x78766174 | |
480 | ||
481 | /* | |
482 | * vnodes | |
483 | */ | |
484 | typedef struct vnode { | |
485 | uint64_t v_size; | |
486 | int v_fd; | |
487 | char *v_path; | |
9867e8be | 488 | int v_dump_fd; |
77755a57 BB |
489 | } vnode_t; |
490 | ||
9867e8be | 491 | extern char *vn_dumpdir; |
428870ff | 492 | #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ |
77755a57 BB |
493 | |
494 | typedef struct xoptattr { | |
495 | timestruc_t xoa_createtime; /* Create time of file */ | |
496 | uint8_t xoa_archive; | |
497 | uint8_t xoa_system; | |
498 | uint8_t xoa_readonly; | |
499 | uint8_t xoa_hidden; | |
500 | uint8_t xoa_nounlink; | |
501 | uint8_t xoa_immutable; | |
502 | uint8_t xoa_appendonly; | |
503 | uint8_t xoa_nodump; | |
504 | uint8_t xoa_settable; | |
505 | uint8_t xoa_opaque; | |
506 | uint8_t xoa_av_quarantined; | |
507 | uint8_t xoa_av_modified; | |
428870ff BB |
508 | uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; |
509 | uint8_t xoa_reparse; | |
572e2857 BB |
510 | uint8_t xoa_offline; |
511 | uint8_t xoa_sparse; | |
77755a57 BB |
512 | } xoptattr_t; |
513 | ||
514 | typedef struct vattr { | |
515 | uint_t va_mask; /* bit-mask of attributes */ | |
516 | u_offset_t va_size; /* file size in bytes */ | |
517 | } vattr_t; | |
518 | ||
519 | ||
520 | typedef struct xvattr { | |
521 | vattr_t xva_vattr; /* Embedded vattr structure */ | |
522 | uint32_t xva_magic; /* Magic Number */ | |
523 | uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ | |
524 | uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ | |
525 | uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ | |
526 | uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ | |
527 | xoptattr_t xva_xoptattrs; /* Optional attributes */ | |
528 | } xvattr_t; | |
529 | ||
530 | typedef struct vsecattr { | |
531 | uint_t vsa_mask; /* See below */ | |
532 | int vsa_aclcnt; /* ACL entry count */ | |
533 | void *vsa_aclentp; /* pointer to ACL entries */ | |
534 | int vsa_dfaclcnt; /* default ACL entry count */ | |
535 | void *vsa_dfaclentp; /* pointer to default ACL entries */ | |
536 | size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ | |
537 | } vsecattr_t; | |
538 | ||
539 | #define AT_TYPE 0x00001 | |
540 | #define AT_MODE 0x00002 | |
541 | #define AT_UID 0x00004 | |
542 | #define AT_GID 0x00008 | |
543 | #define AT_FSID 0x00010 | |
544 | #define AT_NODEID 0x00020 | |
545 | #define AT_NLINK 0x00040 | |
546 | #define AT_SIZE 0x00080 | |
547 | #define AT_ATIME 0x00100 | |
548 | #define AT_MTIME 0x00200 | |
549 | #define AT_CTIME 0x00400 | |
550 | #define AT_RDEV 0x00800 | |
551 | #define AT_BLKSIZE 0x01000 | |
552 | #define AT_NBLOCKS 0x02000 | |
553 | #define AT_SEQ 0x08000 | |
554 | #define AT_XVATTR 0x10000 | |
555 | ||
556 | #define CRCREAT 0 | |
557 | ||
428870ff BB |
558 | extern int fop_getattr(vnode_t *vp, vattr_t *vap); |
559 | ||
274091c0 | 560 | #define VOP_CLOSE(vp, f, c, o, cr, ct) vn_close(vp) |
77755a57 | 561 | #define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0 |
428870ff | 562 | #define VOP_GETATTR(vp, vap, fl, cr, ct) fop_getattr((vp), (vap)); |
77755a57 BB |
563 | |
564 | #define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd) | |
565 | ||
566 | #define VN_RELE(vp) vn_close(vp) | |
567 | ||
568 | extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp, | |
569 | int x2, int x3); | |
570 | extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp, | |
571 | int x2, int x3, vnode_t *vp, int fd); | |
572 | extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, | |
573 | offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp); | |
574 | extern void vn_close(vnode_t *vp); | |
575 | ||
576 | #define vn_remove(path, x1, x2) remove(path) | |
577 | #define vn_rename(from, to, seg) rename((from), (to)) | |
578 | #define vn_is_readonly(vp) B_FALSE | |
579 | ||
580 | extern vnode_t *rootdir; | |
581 | ||
582 | #include <sys/file.h> /* for FREAD, FWRITE, etc */ | |
583 | ||
584 | /* | |
585 | * Random stuff | |
586 | */ | |
428870ff BB |
587 | #define ddi_get_lbolt() (gethrtime() >> 23) |
588 | #define ddi_get_lbolt64() (gethrtime() >> 23) | |
77755a57 BB |
589 | #define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */ |
590 | ||
0b75bdb3 CC |
591 | #define ddi_time_before(a, b) (a < b) |
592 | #define ddi_time_after(a, b) ddi_time_before(b, a) | |
593 | #define ddi_time_before_eq(a, b) (!ddi_time_after(a, b)) | |
594 | #define ddi_time_after_eq(a, b) ddi_time_before_eq(b, a) | |
595 | ||
596 | #define ddi_time_before64(a, b) (a < b) | |
597 | #define ddi_time_after64(a, b) ddi_time_before64(b, a) | |
598 | #define ddi_time_before_eq64(a, b) (!ddi_time_after64(a, b)) | |
599 | #define ddi_time_after_eq64(a, b) ddi_time_before_eq64(b, a) | |
600 | ||
77755a57 BB |
601 | extern void delay(clock_t ticks); |
602 | ||
cc92e9d0 GW |
603 | #define SEC_TO_TICK(sec) ((sec) * hz) |
604 | #define MSEC_TO_TICK(msec) ((msec) / (MILLISEC / hz)) | |
605 | #define USEC_TO_TICK(usec) ((usec) / (MICROSEC / hz)) | |
606 | #define NSEC_TO_TICK(usec) ((usec) / (NANOSEC / hz)) | |
607 | ||
77755a57 | 608 | #define gethrestime_sec() time(NULL) |
428870ff BB |
609 | #define gethrestime(t) \ |
610 | do {\ | |
611 | (t)->tv_sec = gethrestime_sec();\ | |
612 | (t)->tv_nsec = 0;\ | |
613 | } while (0); | |
77755a57 BB |
614 | |
615 | #define max_ncpus 64 | |
ca67b33a | 616 | #define boot_ncpus (sysconf(_SC_NPROCESSORS_ONLN)) |
77755a57 | 617 | |
1229323d BB |
618 | /* |
619 | * Process priorities as defined by setpriority(2) and getpriority(2). | |
620 | */ | |
621 | #define minclsyspri 19 | |
622 | #define maxclsyspri -20 | |
623 | #define defclsyspri 0 | |
77755a57 | 624 | |
1a01c207 | 625 | #define CPU_SEQID ((uintptr_t)pthread_self() & (max_ncpus - 1)) |
77755a57 BB |
626 | |
627 | #define kcred NULL | |
628 | #define CRED() NULL | |
629 | ||
630 | #define ptob(x) ((x) * PAGESIZE) | |
631 | ||
f3c8c9e6 JK |
632 | #define NN_DIVISOR_1000 (1U << 0) |
633 | #define NN_NUMBUF_SZ (6) | |
634 | ||
77755a57 | 635 | extern uint64_t physmem; |
e1a0850c BB |
636 | extern char *random_path; |
637 | extern char *urandom_path; | |
77755a57 | 638 | |
9bd274dd | 639 | extern int highbit64(uint64_t i); |
193a37cb | 640 | extern int lowbit64(uint64_t i); |
77755a57 BB |
641 | extern int random_get_bytes(uint8_t *ptr, size_t len); |
642 | extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len); | |
643 | ||
644 | extern void kernel_init(int); | |
645 | extern void kernel_fini(void); | |
0b04990a TC |
646 | extern void random_init(void); |
647 | extern void random_fini(void); | |
77755a57 BB |
648 | |
649 | struct spa; | |
f3c8c9e6 | 650 | extern void nicenum(uint64_t num, char *buf, size_t); |
77755a57 | 651 | extern void show_pool_stats(struct spa *); |
ed828c0c | 652 | extern int set_global_var(char *arg); |
77755a57 BB |
653 | |
654 | typedef struct callb_cpr { | |
655 | kmutex_t *cc_lockp; | |
656 | } callb_cpr_t; | |
657 | ||
658 | #define CALLB_CPR_INIT(cp, lockp, func, name) { \ | |
659 | (cp)->cc_lockp = lockp; \ | |
660 | } | |
661 | ||
662 | #define CALLB_CPR_SAFE_BEGIN(cp) { \ | |
663 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
664 | } | |
665 | ||
666 | #define CALLB_CPR_SAFE_END(cp, lockp) { \ | |
667 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
668 | } | |
669 | ||
670 | #define CALLB_CPR_EXIT(cp) { \ | |
671 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
672 | mutex_exit((cp)->cc_lockp); \ | |
673 | } | |
674 | ||
675 | #define zone_dataset_visible(x, y) (1) | |
676 | #define INGLOBALZONE(z) (1) | |
677 | ||
00b46022 | 678 | extern char *kmem_vasprintf(const char *fmt, va_list adx); |
428870ff | 679 | extern char *kmem_asprintf(const char *fmt, ...); |
13fe0198 | 680 | #define strfree(str) kmem_free((str), strlen(str) + 1) |
428870ff | 681 | |
77755a57 BB |
682 | /* |
683 | * Hostname information | |
684 | */ | |
d164b209 | 685 | extern char hw_serial[]; /* for userland-emulated hostid access */ |
77755a57 BB |
686 | extern int ddi_strtoul(const char *str, char **nptr, int base, |
687 | unsigned long *result); | |
688 | ||
428870ff BB |
689 | extern int ddi_strtoull(const char *str, char **nptr, int base, |
690 | u_longlong_t *result); | |
691 | ||
f0e324f2 BB |
692 | typedef struct utsname utsname_t; |
693 | extern utsname_t *utsname(void); | |
694 | ||
77755a57 BB |
695 | /* ZFS Boot Related stuff. */ |
696 | ||
697 | struct _buf { | |
698 | intptr_t _fd; | |
699 | }; | |
700 | ||
701 | struct bootstat { | |
702 | uint64_t st_size; | |
703 | }; | |
704 | ||
705 | typedef struct ace_object { | |
706 | uid_t a_who; | |
707 | uint32_t a_access_mask; | |
708 | uint16_t a_flags; | |
709 | uint16_t a_type; | |
710 | uint8_t a_obj_type[16]; | |
711 | uint8_t a_inherit_obj_type[16]; | |
712 | } ace_object_t; | |
713 | ||
714 | ||
715 | #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 | |
716 | #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 | |
717 | #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 | |
718 | #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 | |
719 | ||
720 | extern struct _buf *kobj_open_file(char *name); | |
721 | extern int kobj_read_file(struct _buf *file, char *buf, unsigned size, | |
722 | unsigned off); | |
723 | extern void kobj_close_file(struct _buf *file); | |
724 | extern int kobj_get_filesize(struct _buf *file, uint64_t *size); | |
725 | extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); | |
726 | extern int zfs_secpolicy_rename_perms(const char *from, const char *to, | |
727 | cred_t *cr); | |
728 | extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); | |
f74b821a | 729 | extern int secpolicy_zfs(const cred_t *cr); |
77755a57 BB |
730 | extern zoneid_t getzoneid(void); |
731 | ||
732 | /* SID stuff */ | |
733 | typedef struct ksiddomain { | |
734 | uint_t kd_ref; | |
735 | uint_t kd_len; | |
736 | char *kd_name; | |
737 | } ksiddomain_t; | |
738 | ||
739 | ksiddomain_t *ksid_lookupdomain(const char *); | |
740 | void ksiddomain_rele(ksiddomain_t *); | |
741 | ||
9babb374 BB |
742 | #define DDI_SLEEP KM_SLEEP |
743 | #define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \ | |
744 | sysevent_post_event(_c, _d, _b, "libzpool", _e, _f) | |
745 | ||
d1d7e268 | 746 | #define zfs_sleep_until(wakeup) \ |
e8b96c60 MA |
747 | do { \ |
748 | hrtime_t delta = wakeup - gethrtime(); \ | |
749 | struct timespec ts; \ | |
750 | ts.tv_sec = delta / NANOSEC; \ | |
751 | ts.tv_nsec = delta % NANOSEC; \ | |
752 | (void) nanosleep(&ts, NULL); \ | |
753 | } while (0) | |
754 | ||
92119cc2 BB |
755 | typedef int fstrans_cookie_t; |
756 | ||
757 | extern fstrans_cookie_t spl_fstrans_mark(void); | |
758 | extern void spl_fstrans_unmark(fstrans_cookie_t); | |
e624cd19 | 759 | extern int __spl_pf_fstrans_check(void); |
77755a57 | 760 | |
92119cc2 | 761 | #endif /* _KERNEL */ |
77755a57 | 762 | #endif /* _SYS_ZFS_CONTEXT_H */ |