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.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
25 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
28 #ifndef _SYS_ZFS_CONTEXT_H
29 #define _SYS_ZFS_CONTEXT_H
34 #include <sys/types.h>
35 #include <sys/t_lock.h>
36 #include <sys/atomic.h>
37 #include <sys/sysmacros.h>
38 #include <sys/bitmap.h>
39 #include <sys/cmn_err.h>
41 #include <sys/kmem_cache.h>
43 #include <sys/taskq.h>
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/cpuvar.h>
51 #include <sys/debug.h>
52 #include <sys/random.h>
53 #include <sys/byteorder.h>
54 #include <sys/systm.h>
56 #include <sys/uio_impl.h>
57 #include <sys/dirent.h>
59 #include <vm/seg_kmem.h>
62 #include <sys/kstat.h>
63 #include <sys/zfs_debug.h>
64 #include <sys/sysevent.h>
65 #include <sys/sysevent/eventdefs.h>
66 #include <sys/zfs_delay.h>
67 #include <sys/sunddi.h>
68 #include <sys/ctype.h>
70 #include <sys/trace.h>
71 #include <linux/dcache_compat.h>
72 #include <linux/utsname_compat.h>
78 #define _SYS_CONDVAR_H
106 #include <sys/mman.h>
107 #include <sys/note.h>
108 #include <sys/types.h>
109 #include <sys/cred.h>
110 #include <sys/sysmacros.h>
111 #include <sys/bitmap.h>
112 #include <sys/resource.h>
113 #include <sys/byteorder.h>
114 #include <sys/list.h>
116 #include <sys/zfs_debug.h>
118 #include <sys/kstat.h>
119 #include <sys/u8_textprep.h>
120 #include <sys/sysevent.h>
121 #include <sys/sysevent/eventdefs.h>
122 #include <sys/sunddi.h>
123 #include <sys/debug.h>
124 #include <sys/utsname.h>
130 #define noinline __attribute__((noinline))
131 #define likely(x) __builtin_expect((x), 1)
138 * Note that we are not using the debugging levels.
141 #define CE_CONT 0 /* continuation */
142 #define CE_NOTE 1 /* notice */
143 #define CE_WARN 2 /* warning */
144 #define CE_PANIC 3 /* panic */
145 #define CE_IGNORE 4 /* print nothing */
151 extern void dprintf_setup(int *argc, char **argv);
153 extern void cmn_err(int, const char *, ...);
154 extern void vcmn_err(int, const char *, va_list);
155 extern void panic(const char *, ...);
156 extern void vpanic(const char *, va_list);
158 #define fm_panic panic
163 * DTrace SDT probes have different signatures in userland than they do in
164 * the kernel. If they're being used in kernel code, re-define them out of
165 * existence for their counterparts in libzpool.
167 * Here's an example of how to use the set-error probes in userland:
168 * zfs$target:::set-error /arg0 == EBUSY/ {stack();}
170 * Here's an example of how to use DTRACE_PROBE probes in userland:
171 * If there is a probe declared as follows:
172 * DTRACE_PROBE2(zfs__probe_name, uint64_t, blkid, dnode_t *, dn);
173 * Then you can use it as follows:
174 * zfs$target:::probe2 /copyinstr(arg0) == "zfs__probe_name"/
175 * {printf("%u %p\n", arg1, arg2);}
180 #endif /* DTRACE_PROBE */
181 #define DTRACE_PROBE(a) \
186 #endif /* DTRACE_PROBE1 */
187 #define DTRACE_PROBE1(a, b, c) \
188 ZFS_PROBE1(#a, (unsigned long)c)
192 #endif /* DTRACE_PROBE2 */
193 #define DTRACE_PROBE2(a, b, c, d, e) \
194 ZFS_PROBE2(#a, (unsigned long)c, (unsigned long)e)
198 #endif /* DTRACE_PROBE3 */
199 #define DTRACE_PROBE3(a, b, c, d, e, f, g) \
200 ZFS_PROBE3(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g)
204 #endif /* DTRACE_PROBE4 */
205 #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) \
206 ZFS_PROBE4(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g, \
210 * We use the comma operator so that this macro can be used without much
211 * additional code. For example, "return (EINVAL);" becomes
212 * "return (SET_ERROR(EINVAL));". Note that the argument will be evaluated
213 * twice, so it should not have side effects (e.g. something like:
214 * "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice).
216 #define SET_ERROR(err) (ZFS_SET_ERROR(err), err)
219 * Threads. TS_STACK_MIN is dictated by the minimum allowed pthread stack
220 * size. While TS_STACK_MAX is somewhat arbitrary, it was selected to be
221 * large enough for the expected stack depth while small enough to avoid
222 * exhausting address space with high thread counts.
224 #define TS_MAGIC 0x72f158ab4261e538ull
225 #define TS_RUN 0x00000002
226 #define TS_STACK_MIN MAX(PTHREAD_STACK_MIN, 32768)
227 #define TS_STACK_MAX (256 * 1024)
229 /* in libzpool, p0 exists only to have its address taken */
230 typedef struct proc {
231 uintptr_t this_is_never_used_dont_dereference_it;
234 extern struct proc p0;
235 #define curproc (&p0)
237 typedef void (*thread_func_t)(void *);
238 typedef void (*thread_func_arg_t)(void *);
239 typedef pthread_t kt_did_t;
241 #define kpreempt(x) ((void)0)
243 typedef struct kthread {
245 thread_func_t t_func;
250 #define curthread zk_thread_current()
251 #define getcomm() "unknown"
252 #define thread_exit zk_thread_exit
253 #define thread_create(stk, stksize, func, arg, len, pp, state, pri) \
254 zk_thread_create(stk, stksize, (thread_func_t)func, arg, \
255 len, NULL, state, pri, PTHREAD_CREATE_DETACHED)
256 #define thread_join(t) zk_thread_join(t)
257 #define newproc(f, a, cid, pri, ctp, pid) (ENOSYS)
259 extern kthread_t *zk_thread_current(void);
260 extern void zk_thread_exit(void);
261 extern kthread_t *zk_thread_create(caddr_t stk, size_t stksize,
262 thread_func_t func, void *arg, uint64_t len,
263 proc_t *pp, int state, pri_t pri, int detachstate);
264 extern void zk_thread_join(kt_did_t tid);
266 #define kpreempt_disable() ((void)0)
267 #define kpreempt_enable() ((void)0)
271 #define issig(why) (FALSE)
272 #define ISSIG(thr, why) (FALSE)
277 #define MTX_MAGIC 0x9522f51362a6e326ull
278 #define MTX_INIT ((void *)NULL)
279 #define MTX_DEST ((void *)-1UL)
281 typedef struct kmutex {
284 pthread_mutex_t m_lock;
287 #define MUTEX_DEFAULT 0
288 #define MUTEX_NOLOCKDEP MUTEX_DEFAULT
289 #define MUTEX_HELD(m) ((m)->m_owner == curthread)
290 #define MUTEX_NOT_HELD(m) (!MUTEX_HELD(m))
292 extern void mutex_init(kmutex_t *mp, char *name, int type, void *cookie);
293 extern void mutex_destroy(kmutex_t *mp);
294 extern void mutex_enter(kmutex_t *mp);
295 extern void mutex_exit(kmutex_t *mp);
296 extern int mutex_tryenter(kmutex_t *mp);
297 extern void *mutex_owner(kmutex_t *mp);
298 extern int mutex_held(kmutex_t *mp);
303 #define RW_MAGIC 0x4d31fb123648e78aull
304 #define RW_INIT ((void *)NULL)
305 #define RW_DEST ((void *)-1UL)
307 typedef struct krwlock {
311 pthread_rwlock_t rw_lock;
319 #define RW_DEFAULT RW_READER
320 #define RW_NOLOCKDEP RW_READER
322 #define RW_READ_HELD(x) ((x)->rw_readers > 0)
323 #define RW_WRITE_HELD(x) ((x)->rw_wr_owner == curthread)
324 #define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x))
327 #define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x))
330 #define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x))
332 extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg);
333 extern void rw_destroy(krwlock_t *rwlp);
334 extern void rw_enter(krwlock_t *rwlp, krw_t rw);
335 extern int rw_tryenter(krwlock_t *rwlp, krw_t rw);
336 extern int rw_tryupgrade(krwlock_t *rwlp);
337 extern void rw_exit(krwlock_t *rwlp);
338 #define rw_downgrade(rwlp) do { } while (0)
340 extern uid_t crgetuid(cred_t *cr);
341 extern uid_t crgetruid(cred_t *cr);
342 extern gid_t crgetgid(cred_t *cr);
343 extern int crgetngroups(cred_t *cr);
344 extern gid_t *crgetgroups(cred_t *cr);
347 * Condition variables
349 #define CV_MAGIC 0xd31ea9a83b1b30c4ull
351 typedef struct kcondvar {
357 #define CALLOUT_FLAG_ABSOLUTE 0x2
359 extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
360 extern void cv_destroy(kcondvar_t *cv);
361 extern void cv_wait(kcondvar_t *cv, kmutex_t *mp);
362 extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime);
363 extern clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
364 hrtime_t res, int flag);
365 extern void cv_signal(kcondvar_t *cv);
366 extern void cv_broadcast(kcondvar_t *cv);
367 #define cv_timedwait_sig(cv, mp, at) cv_timedwait(cv, mp, at)
368 #define cv_wait_sig(cv, mp) cv_wait(cv, mp)
369 #define cv_wait_io(cv, mp) cv_wait(cv, mp)
370 #define cv_timedwait_sig_hires(cv, mp, t, r, f) \
371 cv_timedwait_hires(cv, mp, t, r, f)
374 * Thread-specific data
376 #define tsd_get(k) pthread_getspecific(k)
377 #define tsd_set(k, v) pthread_setspecific(k, v)
378 #define tsd_create(kp, d) pthread_key_create(kp, d)
379 #define tsd_destroy(kp) /* nothing */
382 * Thread-specific data
384 #define tsd_get(k) pthread_getspecific(k)
385 #define tsd_set(k, v) pthread_setspecific(k, v)
386 #define tsd_create(kp, d) pthread_key_create(kp, d)
387 #define tsd_destroy(kp) /* nothing */
390 * kstat creation, installation and deletion
392 extern kstat_t *kstat_create(const char *, int,
393 const char *, const char *, uchar_t, ulong_t, uchar_t);
394 extern void kstat_named_init(kstat_named_t *, const char *, uchar_t);
395 extern void kstat_install(kstat_t *);
396 extern void kstat_delete(kstat_t *);
397 extern void kstat_waitq_enter(kstat_io_t *);
398 extern void kstat_waitq_exit(kstat_io_t *);
399 extern void kstat_runq_enter(kstat_io_t *);
400 extern void kstat_runq_exit(kstat_io_t *);
401 extern void kstat_waitq_to_runq(kstat_io_t *);
402 extern void kstat_runq_back_to_waitq(kstat_io_t *);
403 extern void kstat_set_raw_ops(kstat_t *ksp,
404 int (*headers)(char *buf, size_t size),
405 int (*data)(char *buf, size_t size, void *data),
406 void *(*addr)(kstat_t *ksp, loff_t index));
411 #define KM_SLEEP UMEM_NOFAIL
412 #define KM_PUSHPAGE KM_SLEEP
413 #define KM_NOSLEEP UMEM_DEFAULT
414 #define KMC_NODEBUG UMC_NODEBUG
417 #define kmem_alloc(_s, _f) umem_alloc(_s, _f)
418 #define kmem_zalloc(_s, _f) umem_zalloc(_s, _f)
419 #define kmem_free(_b, _s) umem_free(_b, _s)
420 #define vmem_alloc(_s, _f) kmem_alloc(_s, _f)
421 #define vmem_zalloc(_s, _f) kmem_zalloc(_s, _f)
422 #define vmem_free(_b, _s) kmem_free(_b, _s)
423 #define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \
424 umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i)
425 #define kmem_cache_destroy(_c) umem_cache_destroy(_c)
426 #define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f)
427 #define kmem_cache_free(_c, _b) umem_cache_free(_c, _b)
428 #define kmem_debugging() 0
429 #define kmem_cache_reap_now(_c) umem_cache_reap_now(_c);
430 #define kmem_cache_set_move(_c, _cb) /* nothing */
431 #define vmem_qcache_reap(_v) /* nothing */
432 #define POINTER_INVALIDATE(_pp) /* nothing */
433 #define POINTER_IS_VALID(_p) 0
435 extern vmem_t *zio_arena;
437 typedef umem_cache_t kmem_cache_t;
439 typedef enum kmem_cbrc {
451 #define TASKQ_NAMELEN 31
453 typedef uintptr_t taskqid_t;
454 typedef void (task_func_t)(void *);
456 typedef struct taskq_ent {
457 struct taskq_ent *tqent_next;
458 struct taskq_ent *tqent_prev;
459 task_func_t *tqent_func;
461 uintptr_t tqent_flags;
464 typedef struct taskq {
465 char tq_name[TASKQ_NAMELEN + 1];
467 krwlock_t tq_threadlock;
468 kcondvar_t tq_dispatch_cv;
469 kcondvar_t tq_wait_cv;
470 kthread_t **tq_threadlist;
477 kcondvar_t tq_maxalloc_cv;
478 int tq_maxalloc_wait;
479 taskq_ent_t *tq_freelist;
483 #define TQENT_FLAG_PREALLOC 0x1 /* taskq_dispatch_ent used */
485 #define TASKQ_PREPOPULATE 0x0001
486 #define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */
487 #define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */
488 #define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */
489 #define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */
491 #define TQ_SLEEP KM_SLEEP /* Can block for memory */
492 #define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */
493 #define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */
494 #define TQ_FRONT 0x08 /* Queue in front */
496 #define TASKQID_INVALID ((taskqid_t)0)
498 extern taskq_t *system_taskq;
499 extern taskq_t *system_delay_taskq;
501 extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
502 #define taskq_create_proc(a, b, c, d, e, p, f) \
503 (taskq_create(a, b, c, d, e, f))
504 #define taskq_create_sysdc(a, b, d, e, p, dc, f) \
505 (taskq_create(a, b, maxclsyspri, d, e, f))
506 extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
507 extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *, uint_t,
509 extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
511 extern int taskq_empty_ent(taskq_ent_t *);
512 extern void taskq_init_ent(taskq_ent_t *);
513 extern void taskq_destroy(taskq_t *);
514 extern void taskq_wait(taskq_t *);
515 extern void taskq_wait_id(taskq_t *, taskqid_t);
516 extern void taskq_wait_outstanding(taskq_t *, taskqid_t);
517 extern int taskq_member(taskq_t *, kthread_t *);
518 extern int taskq_cancel_id(taskq_t *, taskqid_t);
519 extern void system_taskq_init(void);
520 extern void system_taskq_fini(void);
522 #define XVA_MAPSIZE 3
523 #define XVA_MAGIC 0x78766174
528 typedef struct vnode {
535 extern char *vn_dumpdir;
536 #define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */
538 typedef struct xoptattr {
539 timestruc_t xoa_createtime; /* Create time of file */
542 uint8_t xoa_readonly;
544 uint8_t xoa_nounlink;
545 uint8_t xoa_immutable;
546 uint8_t xoa_appendonly;
548 uint8_t xoa_settable;
550 uint8_t xoa_av_quarantined;
551 uint8_t xoa_av_modified;
552 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ];
558 typedef struct vattr {
559 uint_t va_mask; /* bit-mask of attributes */
560 u_offset_t va_size; /* file size in bytes */
564 typedef struct xvattr {
565 vattr_t xva_vattr; /* Embedded vattr structure */
566 uint32_t xva_magic; /* Magic Number */
567 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */
568 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */
569 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */
570 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */
571 xoptattr_t xva_xoptattrs; /* Optional attributes */
574 typedef struct vsecattr {
575 uint_t vsa_mask; /* See below */
576 int vsa_aclcnt; /* ACL entry count */
577 void *vsa_aclentp; /* pointer to ACL entries */
578 int vsa_dfaclcnt; /* default ACL entry count */
579 void *vsa_dfaclentp; /* pointer to default ACL entries */
580 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */
583 #define AT_TYPE 0x00001
584 #define AT_MODE 0x00002
585 #define AT_UID 0x00004
586 #define AT_GID 0x00008
587 #define AT_FSID 0x00010
588 #define AT_NODEID 0x00020
589 #define AT_NLINK 0x00040
590 #define AT_SIZE 0x00080
591 #define AT_ATIME 0x00100
592 #define AT_MTIME 0x00200
593 #define AT_CTIME 0x00400
594 #define AT_RDEV 0x00800
595 #define AT_BLKSIZE 0x01000
596 #define AT_NBLOCKS 0x02000
597 #define AT_SEQ 0x08000
598 #define AT_XVATTR 0x10000
602 extern int fop_getattr(vnode_t *vp, vattr_t *vap);
604 #define VOP_CLOSE(vp, f, c, o, cr, ct) vn_close(vp)
605 #define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0
606 #define VOP_GETATTR(vp, vap, fl, cr, ct) fop_getattr((vp), (vap));
608 #define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd)
610 #define VN_RELE(vp) vn_close(vp)
612 extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp,
614 extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp,
615 int x2, int x3, vnode_t *vp, int fd);
616 extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len,
617 offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp);
618 extern void vn_close(vnode_t *vp);
620 #define vn_remove(path, x1, x2) remove(path)
621 #define vn_rename(from, to, seg) rename((from), (to))
622 #define vn_is_readonly(vp) B_FALSE
624 extern vnode_t *rootdir;
626 #include <sys/file.h> /* for FREAD, FWRITE, etc */
631 #define ddi_get_lbolt() (gethrtime() >> 23)
632 #define ddi_get_lbolt64() (gethrtime() >> 23)
633 #define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */
635 #define ddi_time_before(a, b) (a < b)
636 #define ddi_time_after(a, b) ddi_time_before(b, a)
637 #define ddi_time_before_eq(a, b) (!ddi_time_after(a, b))
638 #define ddi_time_after_eq(a, b) ddi_time_before_eq(b, a)
640 #define ddi_time_before64(a, b) (a < b)
641 #define ddi_time_after64(a, b) ddi_time_before64(b, a)
642 #define ddi_time_before_eq64(a, b) (!ddi_time_after64(a, b))
643 #define ddi_time_after_eq64(a, b) ddi_time_before_eq64(b, a)
645 extern void delay(clock_t ticks);
647 #define SEC_TO_TICK(sec) ((sec) * hz)
648 #define MSEC_TO_TICK(msec) ((msec) / (MILLISEC / hz))
649 #define USEC_TO_TICK(usec) ((usec) / (MICROSEC / hz))
650 #define NSEC_TO_TICK(usec) ((usec) / (NANOSEC / hz))
652 #define gethrestime_sec() time(NULL)
653 #define gethrestime(t) \
655 (t)->tv_sec = gethrestime_sec();\
660 #define boot_ncpus (sysconf(_SC_NPROCESSORS_ONLN))
663 * Process priorities as defined by setpriority(2) and getpriority(2).
665 #define minclsyspri 19
666 #define maxclsyspri -20
667 #define defclsyspri 0
669 #define CPU_SEQID ((uintptr_t)pthread_self() & (max_ncpus - 1))
674 #define ptob(x) ((x) * PAGESIZE)
676 extern uint64_t physmem;
678 extern int highbit64(uint64_t i);
679 extern int lowbit64(uint64_t i);
680 extern int highbit(ulong_t i);
681 extern int lowbit(ulong_t i);
682 extern int random_get_bytes(uint8_t *ptr, size_t len);
683 extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
685 extern void kernel_init(int);
686 extern void kernel_fini(void);
687 extern void thread_init(void);
688 extern void thread_fini(void);
689 extern void random_init(void);
690 extern void random_fini(void);
693 extern void nicenum(uint64_t num, char *buf);
694 extern void show_pool_stats(struct spa *);
695 extern int set_global_var(char *arg);
697 typedef struct callb_cpr {
701 #define CALLB_CPR_INIT(cp, lockp, func, name) { \
702 (cp)->cc_lockp = lockp; \
705 #define CALLB_CPR_SAFE_BEGIN(cp) { \
706 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \
709 #define CALLB_CPR_SAFE_END(cp, lockp) { \
710 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \
713 #define CALLB_CPR_EXIT(cp) { \
714 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \
715 mutex_exit((cp)->cc_lockp); \
718 #define zone_dataset_visible(x, y) (1)
719 #define INGLOBALZONE(z) (1)
721 extern char *kmem_vasprintf(const char *fmt, va_list adx);
722 extern char *kmem_asprintf(const char *fmt, ...);
723 #define strfree(str) kmem_free((str), strlen(str) + 1)
726 * Hostname information
728 extern char hw_serial[]; /* for userland-emulated hostid access */
729 extern int ddi_strtoul(const char *str, char **nptr, int base,
730 unsigned long *result);
732 extern int ddi_strtoull(const char *str, char **nptr, int base,
733 u_longlong_t *result);
735 typedef struct utsname utsname_t;
736 extern utsname_t *utsname(void);
738 /* ZFS Boot Related stuff. */
748 typedef struct ace_object {
750 uint32_t a_access_mask;
753 uint8_t a_obj_type[16];
754 uint8_t a_inherit_obj_type[16];
758 #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05
759 #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06
760 #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07
761 #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08
763 extern struct _buf *kobj_open_file(char *name);
764 extern int kobj_read_file(struct _buf *file, char *buf, unsigned size,
766 extern void kobj_close_file(struct _buf *file);
767 extern int kobj_get_filesize(struct _buf *file, uint64_t *size);
768 extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
769 extern int zfs_secpolicy_rename_perms(const char *from, const char *to,
771 extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
772 extern int secpolicy_zfs(const cred_t *cr);
773 extern zoneid_t getzoneid(void);
776 typedef struct ksiddomain {
782 ksiddomain_t *ksid_lookupdomain(const char *);
783 void ksiddomain_rele(ksiddomain_t *);
785 #define DDI_SLEEP KM_SLEEP
786 #define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \
787 sysevent_post_event(_c, _d, _b, "libzpool", _e, _f)
789 #define zfs_sleep_until(wakeup) \
791 hrtime_t delta = wakeup - gethrtime(); \
792 struct timespec ts; \
793 ts.tv_sec = delta / NANOSEC; \
794 ts.tv_nsec = delta % NANOSEC; \
795 (void) nanosleep(&ts, NULL); \
798 typedef int fstrans_cookie_t;
800 extern fstrans_cookie_t spl_fstrans_mark(void);
801 extern void spl_fstrans_unmark(fstrans_cookie_t);
802 extern int __spl_pf_fstrans_check(void);
805 #endif /* _SYS_ZFS_CONTEXT_H */