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