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