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