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