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