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