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