]>
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. |
e8b96c60 | 28 | * Copyright (c) 2013 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 | 63 | #include <sys/zfs_debug.h> |
e8b96c60 | 64 | #include <sys/zfs_delay.h> |
6283f55e BB |
65 | #include <sys/fm/fs/zfs.h> |
66 | #include <sys/sunddi.h> | |
d96eb2b1 | 67 | #include <sys/ctype.h> |
15a9e033 | 68 | #include <sys/disp.h> |
8299a1f4 | 69 | #include <linux/dcache_compat.h> |
6283f55e BB |
70 | |
71 | #else /* _KERNEL */ | |
77755a57 BB |
72 | |
73 | #define _SYS_MUTEX_H | |
74 | #define _SYS_RWLOCK_H | |
75 | #define _SYS_CONDVAR_H | |
76 | #define _SYS_SYSTM_H | |
77755a57 BB |
77 | #define _SYS_T_LOCK_H |
78 | #define _SYS_VNODE_H | |
79 | #define _SYS_VFS_H | |
80 | #define _SYS_SUNDDI_H | |
81 | #define _SYS_CALLB_H | |
82 | ||
83 | #include <stdio.h> | |
84 | #include <stdlib.h> | |
85 | #include <stddef.h> | |
86 | #include <stdarg.h> | |
87 | #include <fcntl.h> | |
88 | #include <unistd.h> | |
89 | #include <errno.h> | |
90 | #include <string.h> | |
91 | #include <strings.h> | |
1e33ac1e | 92 | #include <pthread.h> |
3af3df90 | 93 | #include <synch.h> |
77755a57 BB |
94 | #include <assert.h> |
95 | #include <alloca.h> | |
96 | #include <umem.h> | |
97 | #include <limits.h> | |
98 | #include <atomic.h> | |
99 | #include <dirent.h> | |
100 | #include <time.h> | |
d96eb2b1 | 101 | #include <ctype.h> |
498877ba MA |
102 | #include <signal.h> |
103 | #include <sys/mman.h> | |
77755a57 BB |
104 | #include <sys/note.h> |
105 | #include <sys/types.h> | |
106 | #include <sys/cred.h> | |
107 | #include <sys/sysmacros.h> | |
108 | #include <sys/bitmap.h> | |
109 | #include <sys/resource.h> | |
110 | #include <sys/byteorder.h> | |
111 | #include <sys/list.h> | |
112 | #include <sys/uio.h> | |
113 | #include <sys/zfs_debug.h> | |
114 | #include <sys/sdt.h> | |
115 | #include <sys/kstat.h> | |
116 | #include <sys/u8_textprep.h> | |
26685276 | 117 | #include <sys/fm/fs/zfs.h> |
428870ff | 118 | #include <sys/sunddi.h> |
c99c9001 | 119 | #include <sys/debug.h> |
77755a57 | 120 | |
60948de1 BB |
121 | /* |
122 | * Stack | |
123 | */ | |
124 | ||
2e528b49 | 125 | #define noinline __attribute__((noinline)) |
60948de1 | 126 | |
77755a57 BB |
127 | /* |
128 | * Debugging | |
129 | */ | |
130 | ||
131 | /* | |
132 | * Note that we are not using the debugging levels. | |
133 | */ | |
134 | ||
135 | #define CE_CONT 0 /* continuation */ | |
136 | #define CE_NOTE 1 /* notice */ | |
137 | #define CE_WARN 2 /* warning */ | |
138 | #define CE_PANIC 3 /* panic */ | |
139 | #define CE_IGNORE 4 /* print nothing */ | |
140 | ||
1e33ac1e BB |
141 | extern int aok; |
142 | ||
77755a57 BB |
143 | /* |
144 | * ZFS debugging | |
145 | */ | |
146 | ||
77755a57 | 147 | extern void dprintf_setup(int *argc, char **argv); |
d7e398ce BB |
148 | extern void __dprintf(const char *file, const char *func, |
149 | int line, const char *fmt, ...); | |
77755a57 BB |
150 | extern void cmn_err(int, const char *, ...); |
151 | extern void vcmn_err(int, const char *, __va_list); | |
152 | extern void panic(const char *, ...); | |
153 | extern void vpanic(const char *, __va_list); | |
154 | ||
155 | #define fm_panic panic | |
156 | ||
2e528b49 | 157 | #ifdef __sun |
77755a57 BB |
158 | /* |
159 | * DTrace SDT probes have different signatures in userland than they do in | |
160 | * kernel. If they're being used in kernel code, re-define them out of | |
161 | * existence for their counterparts in libzpool. | |
162 | */ | |
163 | ||
164 | #ifdef DTRACE_PROBE | |
165 | #undef DTRACE_PROBE | |
77755a57 | 166 | #endif /* DTRACE_PROBE */ |
2e528b49 MA |
167 | #define DTRACE_PROBE(a) \ |
168 | ZFS_PROBE0(#a) | |
77755a57 BB |
169 | |
170 | #ifdef DTRACE_PROBE1 | |
171 | #undef DTRACE_PROBE1 | |
77755a57 | 172 | #endif /* DTRACE_PROBE1 */ |
2e528b49 MA |
173 | #define DTRACE_PROBE1(a, b, c) \ |
174 | ZFS_PROBE1(#a, (unsigned long)c) | |
77755a57 BB |
175 | |
176 | #ifdef DTRACE_PROBE2 | |
177 | #undef DTRACE_PROBE2 | |
77755a57 | 178 | #endif /* DTRACE_PROBE2 */ |
2e528b49 MA |
179 | #define DTRACE_PROBE2(a, b, c, d, e) \ |
180 | ZFS_PROBE2(#a, (unsigned long)c, (unsigned long)e) | |
77755a57 BB |
181 | |
182 | #ifdef DTRACE_PROBE3 | |
183 | #undef DTRACE_PROBE3 | |
77755a57 | 184 | #endif /* DTRACE_PROBE3 */ |
2e528b49 MA |
185 | #define DTRACE_PROBE3(a, b, c, d, e, f, g) \ |
186 | ZFS_PROBE3(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g) | |
77755a57 BB |
187 | |
188 | #ifdef DTRACE_PROBE4 | |
189 | #undef DTRACE_PROBE4 | |
77755a57 | 190 | #endif /* DTRACE_PROBE4 */ |
2e528b49 MA |
191 | #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) \ |
192 | ZFS_PROBE4(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g, \ | |
193 | (unsigned long)i) | |
77755a57 | 194 | |
2e528b49 MA |
195 | /* |
196 | * We use the comma operator so that this macro can be used without much | |
197 | * additional code. For example, "return (EINVAL);" becomes | |
198 | * "return (SET_ERROR(EINVAL));". Note that the argument will be evaluated | |
199 | * twice, so it should not have side effects (e.g. something like: | |
200 | * "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice). | |
201 | */ | |
202 | #define SET_ERROR(err) (ZFS_SET_ERROR(err), err) | |
203 | #else | |
204 | #define SET_ERROR(err) (err) | |
205 | #endif | |
77755a57 BB |
206 | /* |
207 | * Threads | |
208 | */ | |
1e33ac1e BB |
209 | #define TS_MAGIC 0x72f158ab4261e538ull |
210 | #define TS_RUN 0x00000002 | |
211 | #ifdef __linux__ | |
212 | #define STACK_SIZE 8192 /* Linux x86 and amd64 */ | |
213 | #else | |
214 | #define STACK_SIZE 24576 /* Solaris */ | |
215 | #endif | |
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 | |
00b46022 | 395 | #define KM_NODEBUG 0x0 |
77755a57 | 396 | #define KMC_NODEBUG UMC_NODEBUG |
ae6ba3db BB |
397 | #define KMC_KMEM 0x0 |
398 | #define KMC_VMEM 0x0 | |
77755a57 BB |
399 | #define kmem_alloc(_s, _f) umem_alloc(_s, _f) |
400 | #define kmem_zalloc(_s, _f) umem_zalloc(_s, _f) | |
401 | #define kmem_free(_b, _s) umem_free(_b, _s) | |
00b46022 BB |
402 | #define vmem_alloc(_s, _f) kmem_alloc(_s, _f) |
403 | #define vmem_zalloc(_s, _f) kmem_zalloc(_s, _f) | |
404 | #define vmem_free(_b, _s) kmem_free(_b, _s) | |
77755a57 BB |
405 | #define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \ |
406 | umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) | |
407 | #define kmem_cache_destroy(_c) umem_cache_destroy(_c) | |
408 | #define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f) | |
409 | #define kmem_cache_free(_c, _b) umem_cache_free(_c, _b) | |
410 | #define kmem_debugging() 0 | |
572e2857 BB |
411 | #define kmem_cache_reap_now(_c) /* nothing */ |
412 | #define kmem_cache_set_move(_c, _cb) /* nothing */ | |
413 | #define POINTER_INVALIDATE(_pp) /* nothing */ | |
414 | #define POINTER_IS_VALID(_p) 0 | |
77755a57 BB |
415 | |
416 | typedef umem_cache_t kmem_cache_t; | |
417 | ||
572e2857 BB |
418 | typedef enum kmem_cbrc { |
419 | KMEM_CBRC_YES, | |
420 | KMEM_CBRC_NO, | |
421 | KMEM_CBRC_LATER, | |
422 | KMEM_CBRC_DONT_NEED, | |
423 | KMEM_CBRC_DONT_KNOW | |
424 | } kmem_cbrc_t; | |
425 | ||
77755a57 BB |
426 | /* |
427 | * Task queues | |
428 | */ | |
429 | typedef struct taskq taskq_t; | |
430 | typedef uintptr_t taskqid_t; | |
431 | typedef void (task_func_t)(void *); | |
432 | ||
a38718a6 GA |
433 | typedef struct taskq_ent { |
434 | struct taskq_ent *tqent_next; | |
435 | struct taskq_ent *tqent_prev; | |
436 | task_func_t *tqent_func; | |
437 | void *tqent_arg; | |
438 | uintptr_t tqent_flags; | |
439 | } taskq_ent_t; | |
440 | ||
441 | #define TQENT_FLAG_PREALLOC 0x1 /* taskq_dispatch_ent used */ | |
442 | ||
77755a57 BB |
443 | #define TASKQ_PREPOPULATE 0x0001 |
444 | #define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ | |
445 | #define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ | |
428870ff BB |
446 | #define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */ |
447 | #define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */ | |
77755a57 BB |
448 | |
449 | #define TQ_SLEEP KM_SLEEP /* Can block for memory */ | |
450 | #define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */ | |
0ef0ff54 | 451 | #define TQ_PUSHPAGE KM_PUSHPAGE /* Cannot perform I/O */ |
428870ff BB |
452 | #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ |
453 | #define TQ_FRONT 0x08 /* Queue in front */ | |
77755a57 BB |
454 | |
455 | extern taskq_t *system_taskq; | |
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); |
1e33ac1e | 472 | extern int taskq_member(taskq_t *, kthread_t *); |
cc92e9d0 | 473 | extern int taskq_cancel_id(taskq_t *, taskqid_t); |
77755a57 | 474 | extern void system_taskq_init(void); |
428870ff | 475 | extern void system_taskq_fini(void); |
77755a57 BB |
476 | |
477 | #define XVA_MAPSIZE 3 | |
478 | #define XVA_MAGIC 0x78766174 | |
479 | ||
480 | /* | |
481 | * vnodes | |
482 | */ | |
483 | typedef struct vnode { | |
484 | uint64_t v_size; | |
485 | int v_fd; | |
486 | char *v_path; | |
487 | } vnode_t; | |
488 | ||
428870ff | 489 | #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ |
77755a57 BB |
490 | |
491 | typedef struct xoptattr { | |
492 | timestruc_t xoa_createtime; /* Create time of file */ | |
493 | uint8_t xoa_archive; | |
494 | uint8_t xoa_system; | |
495 | uint8_t xoa_readonly; | |
496 | uint8_t xoa_hidden; | |
497 | uint8_t xoa_nounlink; | |
498 | uint8_t xoa_immutable; | |
499 | uint8_t xoa_appendonly; | |
500 | uint8_t xoa_nodump; | |
501 | uint8_t xoa_settable; | |
502 | uint8_t xoa_opaque; | |
503 | uint8_t xoa_av_quarantined; | |
504 | uint8_t xoa_av_modified; | |
428870ff BB |
505 | uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; |
506 | uint8_t xoa_reparse; | |
572e2857 BB |
507 | uint8_t xoa_offline; |
508 | uint8_t xoa_sparse; | |
77755a57 BB |
509 | } xoptattr_t; |
510 | ||
511 | typedef struct vattr { | |
512 | uint_t va_mask; /* bit-mask of attributes */ | |
513 | u_offset_t va_size; /* file size in bytes */ | |
514 | } vattr_t; | |
515 | ||
516 | ||
517 | typedef struct xvattr { | |
518 | vattr_t xva_vattr; /* Embedded vattr structure */ | |
519 | uint32_t xva_magic; /* Magic Number */ | |
520 | uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ | |
521 | uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ | |
522 | uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ | |
523 | uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ | |
524 | xoptattr_t xva_xoptattrs; /* Optional attributes */ | |
525 | } xvattr_t; | |
526 | ||
527 | typedef struct vsecattr { | |
528 | uint_t vsa_mask; /* See below */ | |
529 | int vsa_aclcnt; /* ACL entry count */ | |
530 | void *vsa_aclentp; /* pointer to ACL entries */ | |
531 | int vsa_dfaclcnt; /* default ACL entry count */ | |
532 | void *vsa_dfaclentp; /* pointer to default ACL entries */ | |
533 | size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ | |
534 | } vsecattr_t; | |
535 | ||
536 | #define AT_TYPE 0x00001 | |
537 | #define AT_MODE 0x00002 | |
538 | #define AT_UID 0x00004 | |
539 | #define AT_GID 0x00008 | |
540 | #define AT_FSID 0x00010 | |
541 | #define AT_NODEID 0x00020 | |
542 | #define AT_NLINK 0x00040 | |
543 | #define AT_SIZE 0x00080 | |
544 | #define AT_ATIME 0x00100 | |
545 | #define AT_MTIME 0x00200 | |
546 | #define AT_CTIME 0x00400 | |
547 | #define AT_RDEV 0x00800 | |
548 | #define AT_BLKSIZE 0x01000 | |
549 | #define AT_NBLOCKS 0x02000 | |
550 | #define AT_SEQ 0x08000 | |
551 | #define AT_XVATTR 0x10000 | |
552 | ||
553 | #define CRCREAT 0 | |
554 | ||
428870ff BB |
555 | extern int fop_getattr(vnode_t *vp, vattr_t *vap); |
556 | ||
274091c0 | 557 | #define VOP_CLOSE(vp, f, c, o, cr, ct) vn_close(vp) |
77755a57 | 558 | #define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0 |
428870ff | 559 | #define VOP_GETATTR(vp, vap, fl, cr, ct) fop_getattr((vp), (vap)); |
77755a57 BB |
560 | |
561 | #define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd) | |
562 | ||
563 | #define VN_RELE(vp) vn_close(vp) | |
564 | ||
565 | extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp, | |
566 | int x2, int x3); | |
567 | extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp, | |
568 | int x2, int x3, vnode_t *vp, int fd); | |
569 | extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, | |
570 | offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp); | |
571 | extern void vn_close(vnode_t *vp); | |
572 | ||
573 | #define vn_remove(path, x1, x2) remove(path) | |
574 | #define vn_rename(from, to, seg) rename((from), (to)) | |
575 | #define vn_is_readonly(vp) B_FALSE | |
576 | ||
577 | extern vnode_t *rootdir; | |
578 | ||
579 | #include <sys/file.h> /* for FREAD, FWRITE, etc */ | |
580 | ||
581 | /* | |
582 | * Random stuff | |
583 | */ | |
428870ff BB |
584 | #define ddi_get_lbolt() (gethrtime() >> 23) |
585 | #define ddi_get_lbolt64() (gethrtime() >> 23) | |
77755a57 BB |
586 | #define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */ |
587 | ||
0b75bdb3 CC |
588 | #define ddi_time_before(a, b) (a < b) |
589 | #define ddi_time_after(a, b) ddi_time_before(b, a) | |
590 | #define ddi_time_before_eq(a, b) (!ddi_time_after(a, b)) | |
591 | #define ddi_time_after_eq(a, b) ddi_time_before_eq(b, a) | |
592 | ||
593 | #define ddi_time_before64(a, b) (a < b) | |
594 | #define ddi_time_after64(a, b) ddi_time_before64(b, a) | |
595 | #define ddi_time_before_eq64(a, b) (!ddi_time_after64(a, b)) | |
596 | #define ddi_time_after_eq64(a, b) ddi_time_before_eq64(b, a) | |
597 | ||
77755a57 BB |
598 | extern void delay(clock_t ticks); |
599 | ||
cc92e9d0 GW |
600 | #define SEC_TO_TICK(sec) ((sec) * hz) |
601 | #define MSEC_TO_TICK(msec) ((msec) / (MILLISEC / hz)) | |
602 | #define USEC_TO_TICK(usec) ((usec) / (MICROSEC / hz)) | |
603 | #define NSEC_TO_TICK(usec) ((usec) / (NANOSEC / hz)) | |
604 | ||
77755a57 | 605 | #define gethrestime_sec() time(NULL) |
428870ff BB |
606 | #define gethrestime(t) \ |
607 | do {\ | |
608 | (t)->tv_sec = gethrestime_sec();\ | |
609 | (t)->tv_nsec = 0;\ | |
610 | } while (0); | |
77755a57 BB |
611 | |
612 | #define max_ncpus 64 | |
613 | ||
614 | #define minclsyspri 60 | |
615 | #define maxclsyspri 99 | |
616 | ||
1e33ac1e | 617 | #define CPU_SEQID (pthread_self() & (max_ncpus - 1)) |
77755a57 BB |
618 | |
619 | #define kcred NULL | |
620 | #define CRED() NULL | |
621 | ||
622 | #define ptob(x) ((x) * PAGESIZE) | |
623 | ||
624 | extern uint64_t physmem; | |
625 | ||
626 | extern int highbit(ulong_t i); | |
627 | extern int random_get_bytes(uint8_t *ptr, size_t len); | |
628 | extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len); | |
629 | ||
630 | extern void kernel_init(int); | |
631 | extern void kernel_fini(void); | |
632 | ||
633 | struct spa; | |
634 | extern void nicenum(uint64_t num, char *buf); | |
635 | extern void show_pool_stats(struct spa *); | |
636 | ||
637 | typedef struct callb_cpr { | |
638 | kmutex_t *cc_lockp; | |
639 | } callb_cpr_t; | |
640 | ||
641 | #define CALLB_CPR_INIT(cp, lockp, func, name) { \ | |
642 | (cp)->cc_lockp = lockp; \ | |
643 | } | |
644 | ||
645 | #define CALLB_CPR_SAFE_BEGIN(cp) { \ | |
646 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
647 | } | |
648 | ||
649 | #define CALLB_CPR_SAFE_END(cp, lockp) { \ | |
650 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
651 | } | |
652 | ||
653 | #define CALLB_CPR_EXIT(cp) { \ | |
654 | ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ | |
655 | mutex_exit((cp)->cc_lockp); \ | |
656 | } | |
657 | ||
658 | #define zone_dataset_visible(x, y) (1) | |
659 | #define INGLOBALZONE(z) (1) | |
660 | ||
00b46022 | 661 | extern char *kmem_vasprintf(const char *fmt, va_list adx); |
428870ff | 662 | extern char *kmem_asprintf(const char *fmt, ...); |
13fe0198 | 663 | #define strfree(str) kmem_free((str), strlen(str) + 1) |
428870ff | 664 | |
77755a57 BB |
665 | /* |
666 | * Hostname information | |
667 | */ | |
d164b209 | 668 | extern char hw_serial[]; /* for userland-emulated hostid access */ |
77755a57 BB |
669 | extern int ddi_strtoul(const char *str, char **nptr, int base, |
670 | unsigned long *result); | |
671 | ||
428870ff BB |
672 | extern int ddi_strtoull(const char *str, char **nptr, int base, |
673 | u_longlong_t *result); | |
674 | ||
77755a57 BB |
675 | /* ZFS Boot Related stuff. */ |
676 | ||
677 | struct _buf { | |
678 | intptr_t _fd; | |
679 | }; | |
680 | ||
681 | struct bootstat { | |
682 | uint64_t st_size; | |
683 | }; | |
684 | ||
685 | typedef struct ace_object { | |
686 | uid_t a_who; | |
687 | uint32_t a_access_mask; | |
688 | uint16_t a_flags; | |
689 | uint16_t a_type; | |
690 | uint8_t a_obj_type[16]; | |
691 | uint8_t a_inherit_obj_type[16]; | |
692 | } ace_object_t; | |
693 | ||
694 | ||
695 | #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 | |
696 | #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 | |
697 | #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 | |
698 | #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 | |
699 | ||
700 | extern struct _buf *kobj_open_file(char *name); | |
701 | extern int kobj_read_file(struct _buf *file, char *buf, unsigned size, | |
702 | unsigned off); | |
703 | extern void kobj_close_file(struct _buf *file); | |
704 | extern int kobj_get_filesize(struct _buf *file, uint64_t *size); | |
705 | extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); | |
706 | extern int zfs_secpolicy_rename_perms(const char *from, const char *to, | |
707 | cred_t *cr); | |
708 | extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); | |
709 | extern zoneid_t getzoneid(void); | |
710 | ||
711 | /* SID stuff */ | |
712 | typedef struct ksiddomain { | |
713 | uint_t kd_ref; | |
714 | uint_t kd_len; | |
715 | char *kd_name; | |
716 | } ksiddomain_t; | |
717 | ||
718 | ksiddomain_t *ksid_lookupdomain(const char *); | |
719 | void ksiddomain_rele(ksiddomain_t *); | |
720 | ||
9babb374 BB |
721 | #define DDI_SLEEP KM_SLEEP |
722 | #define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \ | |
723 | sysevent_post_event(_c, _d, _b, "libzpool", _e, _f) | |
724 | ||
d1d7e268 | 725 | #define zfs_sleep_until(wakeup) \ |
e8b96c60 MA |
726 | do { \ |
727 | hrtime_t delta = wakeup - gethrtime(); \ | |
728 | struct timespec ts; \ | |
729 | ts.tv_sec = delta / NANOSEC; \ | |
730 | ts.tv_nsec = delta % NANOSEC; \ | |
731 | (void) nanosleep(&ts, NULL); \ | |
732 | } while (0) | |
733 | ||
6283f55e | 734 | #endif /* _KERNEL */ |
77755a57 BB |
735 | |
736 | #endif /* _SYS_ZFS_CONTEXT_H */ |