fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
5aeb94743e3be0c51e86f73096334611ae3a058eGarrett D'Amore * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
0e60744c982adecd0a1f146f5637475d07ab1069Pavel Zakharov * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
4e3c9f4489a18514e5e8caeb91d4e6db07c98415Bill Pijewski * Copyright (c) 2012, Joyent, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern "C" {
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Debugging
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Note that we are not using the debugging levels.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ZFS debugging
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* ZFS_DEBUG */
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern void cmn_err(int, const char *, ...);
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern void panic(const char *, ...);
3d7072f8bd27709dba14f6fe336f149d25d9e207eschrock * DTrace SDT probes have different signatures in userland than they do in
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * the kernel. If they're being used in kernel code, re-define them out of
fa9e4066f08beec538e775443c5be79dd423fcabahrens * existence for their counterparts in libzpool.
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Here's an example of how to use the set-error probes in userland:
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * zfs$target:::set-error /arg0 == EBUSY/ {stack();}
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Here's an example of how to use DTRACE_PROBE probes in userland:
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * If there is a probe declared as follows:
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * DTRACE_PROBE2(zfs__probe_name, uint64_t, blkid, dnode_t *, dn);
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * Then you can use it as follows:
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * zfs$target:::probe2 /copyinstr(arg0) == "zfs__probe_name"/
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie * {printf("%u %p\n", arg1, arg2);}
05715f945c5c007fc4bb6a4e7cf4a749c9b30038Mark Maybee#endif /* DTRACE_PROBE */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* DTRACE_PROBE1 */
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens ZFS_PROBE1(#a, (unsigned long)c)
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* DTRACE_PROBE2 */
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens ZFS_PROBE2(#a, (unsigned long)c, (unsigned long)e)
c543ec060d1359f6c8a9507242521f344a2ac3efahrens#endif /* DTRACE_PROBE3 */
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens ZFS_PROBE3(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g)
faafa6e33cc19afb09172d9a365a59da0dbfd965ahrens#endif /* DTRACE_PROBE4 */
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) \
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens ZFS_PROBE4(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g, \
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens (unsigned long)i)
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens * We use the comma operator so that this macro can be used without much
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens * additional code. For example, "return (EINVAL);" becomes
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens * "return (SET_ERROR(EINVAL));". Note that the argument will be evaluated
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens * twice, so it should not have side effects (e.g. something like:
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens * "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice).
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens#define SET_ERROR(err) (ZFS_SET_ERROR(err), err)
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define thread_create(stk, stksize, func, arg, len, pp, state, pri) \
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams#define thread_join(t) panic("libzpool cannot join threads")
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams#define newproc(f, a, cid, pri, ctp, pid) (ENOSYS)
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams/* in libzpool, p0 exists only to have its address taken */
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams uintptr_t this_is_never_used_dont_dereference_it;
8fc922875ed266f52ccd5cc6f973b9ad0839c710Eli Rosenthalextern kthread_t *zk_thread_create(void (*func)(), void *arg, uint64_t len);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Argh -- we have to get cheesy here because the kernel and userland
fa9e4066f08beec538e775443c5be79dd423fcabahrens * have different signatures for the same routine.
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern int _mutex_init(mutex_t *mp, int type, void *arg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define mutex_init(mp, b, c, d) zmutex_init((kmutex_t *)(mp))
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define mutex_destroy(mp) zmutex_destroy((kmutex_t *)(mp))
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define RW_WRITE_HELD(x) _rw_write_held(&(x)->rw_lock)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens#define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x))
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Condition variables
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime);
0689f76c08c5e553ff25ac43a852b56c430bb61eAdam Leventhalextern clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Thread-specific data
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens#define tsd_set(k, v) pthread_setspecific(k, v)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens#define tsd_create(kp, d) pthread_key_create(kp, d)
44cb6abc89aa591c23f5e58296c6d2a29302344abmc * kstat creation, installation and deletion
c3a66015199e1814c2af8f7e6929af2004302e7eMatthew Ahrensextern kstat_t *kstat_create(const char *, int,
c3a66015199e1814c2af8f7e6929af2004302e7eMatthew Ahrens const char *, const char *, uchar_t, ulong_t, uchar_t);
8363e80ae72609660f6090766ca8c2c18aa53f0cGeorge Wilsonextern void kstat_named_init(kstat_named_t *, const char *, uchar_t);
c3a66015199e1814c2af8f7e6929af2004302e7eMatthew Ahrensextern void kstat_waitq_to_runq(kstat_io_t *);
c3a66015199e1814c2af8f7e6929af2004302e7eMatthew Ahrensextern void kstat_runq_back_to_waitq(kstat_io_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Kernel memory
e291592ab12a560fc73b0610963bb3fe66aab341Jonathan Adams#define KMC_NOTOUCH 0 /* not needed for userland caches */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \
fa9e4066f08beec538e775443c5be79dd423fcabahrens umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i)
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f)
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define kmem_cache_free(_c, _b) umem_cache_free(_c, _b)
744947dc83c634d985ed3ad79ac9c5e28d1865fdTom Erickson#define kmem_cache_set_move(_c, _cb) /* nothing */
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Task queues
5aeb94743e3be0c51e86f73096334611ae3a058eGarrett D'Amore#define TQENT_FLAG_PREALLOC 0x1 /* taskq_dispatch_ent used */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams#define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams#define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams#define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams#define taskq_create_proc(a, b, c, d, e, p, f) \
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams (taskq_create(a, b, c, d, e, f))
35a5a3587fd94b666239c157d3722745250ccbd7Jonathan Adams#define taskq_create_sysdc(a, b, d, e, p, dc, f) \
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
5aeb94743e3be0c51e86f73096334611ae3a058eGarrett D'Amoreextern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrensextern void system_taskq_init(void);
d20e665c84abf083a9e8b62cca93383ecb55afdfRicardo M. Correiaextern void system_taskq_fini(void);
7a286c471efbab8562f7655a82931904703fffe0Dai Ngo#define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw void *vsa_dfaclentp; /* pointer to default ACL entries */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilsonextern int fop_getattr(vnode_t *vp, vattr_t *vap);
095bcd6622e3b3520eb3b71039a3be5cfab25b74George Wilson#define VOP_GETATTR(vp, vap, fl, cr, ct) fop_getattr((vp), (vap));
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp,
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp,
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len,
fa9e4066f08beec538e775443c5be79dd423fcabahrens offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Random stuff
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson#define NSEC_TO_TICK(usec) ((usec) / (NANOSEC / hz))
71eb05381846ad14a2087631474e832d0f316654Chris Kirby } while (0);
244781f10dcd82684fd8163c016540667842f203Prakash Surya#define boot_ncpus (sysconf(_SC_NPROCESSORS_ONLN))
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern int random_get_bytes(uint8_t *ptr, size_t len);
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern void kernel_init(int);
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern void kernel_fini(void);
ae46e4c775f2becc5343ff90b60a95acb79735f9Matthew Ahrensextern char *kmem_asprintf(const char *fmt, ...);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens#define strfree(str) kmem_free((str), strlen(str) + 1)
95173954d2b811ceb583a9012c3b16e1d0dd6438ek * Hostname information
5679c89fcd2facbb4334df8870d3d7a4d2b11673jvextern char hw_serial[]; /* for userland-emulated hostid access */
95173954d2b811ceb583a9012c3b16e1d0dd6438ekextern int ddi_strtoul(const char *str, char **nptr, int base,
95173954d2b811ceb583a9012c3b16e1d0dd6438ek unsigned long *result);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaumextern int ddi_strtoull(const char *str, char **nptr, int base,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock/* ZFS Boot Related stuff. */
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockextern int kobj_read_file(struct _buf *file, char *buf, unsigned size,
b1b8ab34de515a5e83206da22c3d7e563241b021llingextern int kobj_get_filesize(struct _buf *file, uint64_t *size);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarksextern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarksextern int zfs_secpolicy_rename_perms(const char *from, const char *to,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarksextern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
e0d35c4478bf9fd4080951b5b9d1f9a38948ba69marks/* SID stuff */
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson#define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \
573ca77e53dd31dcaebef023e7eb41969e6896c1George Wilson sysevent_post_event(_c, _d, _b, "libzpool", _e, _f)
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson * Cyclic information
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilsonextern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *);
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilsonextern int cyclic_reprogram(cyclic_id_t, hrtime_t);
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson * Buf structure
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson#define B_READ 0x0040 /* read when I/O occurs */
31d7e8fa33fae995f558673adb22641b5aa8b6e1George Wilson#define B_WRITE 0x0100 /* non-read pseudo-flag */
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* _SYS_ZFS_CONTEXT_H */