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