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