zfs_context.h revision 235222
1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License (the "License"). 6168404Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd/* 22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23235222Smm * Copyright (c) 2012, Joyent, Inc. All rights reserved. 24168404Spjd */ 25168404Spjd 26168404Spjd#ifndef _SYS_ZFS_CONTEXT_H 27168404Spjd#define _SYS_ZFS_CONTEXT_H 28168404Spjd 29168404Spjd#ifdef __cplusplus 30168404Spjdextern "C" { 31168404Spjd#endif 32168404Spjd 33168404Spjd#define _SYS_MUTEX_H 34168404Spjd#define _SYS_RWLOCK_H 35168404Spjd#define _SYS_CONDVAR_H 36168404Spjd#define _SYS_SYSTM_H 37168404Spjd#define _SYS_DEBUG_H 38168404Spjd#define _SYS_T_LOCK_H 39168404Spjd#define _SYS_VNODE_H 40168404Spjd#define _SYS_VFS_H 41168404Spjd#define _SYS_SUNDDI_H 42168404Spjd#define _SYS_CALLB_H 43168404Spjd#define _SYS_SCHED_H_ 44168404Spjd 45168404Spjd#include <solaris.h> 46168404Spjd#include <stdio.h> 47168404Spjd#include <stdlib.h> 48168404Spjd#include <stddef.h> 49168404Spjd#include <stdarg.h> 50168404Spjd#include <fcntl.h> 51168404Spjd#include <unistd.h> 52168404Spjd#include <errno.h> 53168404Spjd#include <string.h> 54168404Spjd#include <strings.h> 55168404Spjd#include <thread.h> 56168404Spjd#include <assert.h> 57168404Spjd#include <limits.h> 58168404Spjd#include <dirent.h> 59168404Spjd#include <time.h> 60168404Spjd#include <math.h> 61168404Spjd#include <umem.h> 62219089Spjd#include <inttypes.h> 63168404Spjd#include <fsshare.h> 64168404Spjd#include <sys/note.h> 65168404Spjd#include <sys/types.h> 66185029Spjd#include <sys/cred.h> 67168404Spjd#include <sys/atomic.h> 68168404Spjd#include <sys/sysmacros.h> 69168404Spjd#include <sys/bitmap.h> 70168404Spjd#include <sys/resource.h> 71168404Spjd#include <sys/byteorder.h> 72168404Spjd#include <sys/list.h> 73168404Spjd#include <sys/time.h> 74168404Spjd#include <sys/uio.h> 75168404Spjd#include <sys/mntent.h> 76168404Spjd#include <sys/mnttab.h> 77168404Spjd#include <sys/zfs_debug.h> 78168404Spjd#include <sys/debug.h> 79168404Spjd#include <sys/sdt.h> 80168404Spjd#include <sys/kstat.h> 81185029Spjd#include <sys/u8_textprep.h> 82168404Spjd#include <sys/kernel.h> 83168722Ssimokawa#include <sys/disk.h> 84219089Spjd#include <sys/sysevent.h> 85185029Spjd#include <sys/sysevent/eventdefs.h> 86219089Spjd#include <sys/sysevent/dev.h> 87168404Spjd#include <machine/atomic.h> 88168404Spjd 89168404Spjd#define ZFS_EXPORTS_PATH "/etc/zfs/exports" 90168404Spjd 91168404Spjd/* 92168404Spjd * Debugging 93168404Spjd */ 94168404Spjd 95168404Spjd/* 96168404Spjd * Note that we are not using the debugging levels. 97168404Spjd */ 98168404Spjd 99168404Spjd#define CE_CONT 0 /* continuation */ 100168404Spjd#define CE_NOTE 1 /* notice */ 101168404Spjd#define CE_WARN 2 /* warning */ 102168404Spjd#define CE_PANIC 3 /* panic */ 103168404Spjd#define CE_IGNORE 4 /* print nothing */ 104168404Spjd 105168404Spjd/* 106168404Spjd * ZFS debugging 107168404Spjd */ 108168404Spjd 109168404Spjd#define ZFS_LOG(...) do { } while (0) 110168404Spjd 111168404Spjdtypedef u_longlong_t rlim64_t; 112168404Spjd#define RLIM64_INFINITY ((rlim64_t)-3) 113168404Spjd 114168404Spjd#ifdef ZFS_DEBUG 115168404Spjdextern void dprintf_setup(int *argc, char **argv); 116168404Spjd#endif /* ZFS_DEBUG */ 117168404Spjd 118168404Spjdextern void cmn_err(int, const char *, ...); 119168404Spjdextern void vcmn_err(int, const char *, __va_list); 120168404Spjdextern void panic(const char *, ...); 121168404Spjdextern void vpanic(const char *, __va_list); 122168404Spjd 123185029Spjd#define fm_panic panic 124185029Spjd 125219089Spjdextern int aok; 126219089Spjd 127168404Spjd/* This definition is copied from assert.h. */ 128168404Spjd#if defined(__STDC__) 129168404Spjd#if __STDC_VERSION__ - 0 >= 199901L 130219089Spjd#define zverify(EX) (void)((EX) || (aok) || \ 131219089Spjd (__assert(#EX, __FILE__, __LINE__), 0)) 132168404Spjd#else 133219089Spjd#define zverify(EX) (void)((EX) || (aok) || \ 134219089Spjd (__assert(#EX, __FILE__, __LINE__), 0)) 135168404Spjd#endif /* __STDC_VERSION__ - 0 >= 199901L */ 136168404Spjd#else 137219089Spjd#define zverify(EX) (void)((EX) || (aok) || \ 138219089Spjd (_assert("EX", __FILE__, __LINE__), 0)) 139168404Spjd#endif /* __STDC__ */ 140168404Spjd 141168404Spjd 142219089Spjd#define VERIFY zverify 143219089Spjd#define ASSERT zverify 144219089Spjd#undef assert 145219089Spjd#define assert zverify 146168404Spjd 147168404Spjdextern void __assert(const char *, const char *, int); 148168404Spjd 149168404Spjd#ifdef lint 150168404Spjd#define VERIFY3_IMPL(x, y, z, t) if (x == z) ((void)0) 151168404Spjd#else 152168404Spjd/* BEGIN CSTYLED */ 153168404Spjd#define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \ 154168404Spjd const TYPE __left = (TYPE)(LEFT); \ 155168404Spjd const TYPE __right = (TYPE)(RIGHT); \ 156219089Spjd if (!(__left OP __right) && (!aok)) { \ 157168404Spjd char *__buf = alloca(256); \ 158168404Spjd (void) snprintf(__buf, 256, "%s %s %s (0x%llx %s 0x%llx)", \ 159168404Spjd #LEFT, #OP, #RIGHT, \ 160168404Spjd (u_longlong_t)__left, #OP, (u_longlong_t)__right); \ 161168404Spjd __assert(__buf, __FILE__, __LINE__); \ 162168404Spjd } \ 163168404Spjd_NOTE(CONSTCOND) } while (0) 164168404Spjd/* END CSTYLED */ 165168404Spjd#endif /* lint */ 166168404Spjd 167168404Spjd#define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t) 168168404Spjd#define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t) 169168404Spjd#define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t) 170168404Spjd 171168404Spjd#ifdef NDEBUG 172168404Spjd#define ASSERT3S(x, y, z) ((void)0) 173168404Spjd#define ASSERT3U(x, y, z) ((void)0) 174168404Spjd#define ASSERT3P(x, y, z) ((void)0) 175168404Spjd#else 176168404Spjd#define ASSERT3S(x, y, z) VERIFY3S(x, y, z) 177168404Spjd#define ASSERT3U(x, y, z) VERIFY3U(x, y, z) 178168404Spjd#define ASSERT3P(x, y, z) VERIFY3P(x, y, z) 179168404Spjd#endif 180168404Spjd 181168404Spjd/* 182185029Spjd * DTrace SDT probes have different signatures in userland than they do in 183168404Spjd * kernel. If they're being used in kernel code, re-define them out of 184168404Spjd * existence for their counterparts in libzpool. 185168404Spjd */ 186168404Spjd 187185029Spjd#ifdef DTRACE_PROBE 188185029Spjd#undef DTRACE_PROBE 189185029Spjd#define DTRACE_PROBE(a) ((void)0) 190185029Spjd#endif /* DTRACE_PROBE */ 191185029Spjd 192168404Spjd#ifdef DTRACE_PROBE1 193168404Spjd#undef DTRACE_PROBE1 194168404Spjd#define DTRACE_PROBE1(a, b, c) ((void)0) 195168404Spjd#endif /* DTRACE_PROBE1 */ 196168404Spjd 197168404Spjd#ifdef DTRACE_PROBE2 198168404Spjd#undef DTRACE_PROBE2 199168404Spjd#define DTRACE_PROBE2(a, b, c, d, e) ((void)0) 200168404Spjd#endif /* DTRACE_PROBE2 */ 201168404Spjd 202168404Spjd#ifdef DTRACE_PROBE3 203168404Spjd#undef DTRACE_PROBE3 204168404Spjd#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) 205168404Spjd#endif /* DTRACE_PROBE3 */ 206168404Spjd 207168404Spjd#ifdef DTRACE_PROBE4 208168404Spjd#undef DTRACE_PROBE4 209168404Spjd#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) 210168404Spjd#endif /* DTRACE_PROBE4 */ 211168404Spjd 212168404Spjd/* 213168404Spjd * Threads 214168404Spjd */ 215168404Spjd#define curthread ((void *)(uintptr_t)thr_self()) 216168404Spjd 217168404Spjdtypedef struct kthread kthread_t; 218168404Spjd 219168404Spjd#define thread_create(stk, stksize, func, arg, len, pp, state, pri) \ 220168404Spjd zk_thread_create(func, arg) 221168404Spjd#define thread_exit() thr_exit(NULL) 222219089Spjd#define thread_join(t) panic("libzpool cannot join threads") 223168404Spjd 224219089Spjd#define newproc(f, a, cid, pri, ctp, pid) (ENOSYS) 225219089Spjd 226219089Spjd/* in libzpool, p0 exists only to have its address taken */ 227219089Spjdstruct proc { 228219089Spjd uintptr_t this_is_never_used_dont_dereference_it; 229219089Spjd}; 230219089Spjd 231219089Spjdextern struct proc p0; 232235222Smm#define curproc (&p0) 233219089Spjd 234219089Spjd#define PS_NONE -1 235219089Spjd 236168404Spjdextern kthread_t *zk_thread_create(void (*func)(), void *arg); 237168404Spjd 238168404Spjd#define issig(why) (FALSE) 239168404Spjd#define ISSIG(thr, why) (FALSE) 240168404Spjd 241168404Spjd/* 242168404Spjd * Mutexes 243168404Spjd */ 244168404Spjdtypedef struct kmutex { 245185029Spjd void *m_owner; 246185029Spjd boolean_t initialized; 247185029Spjd mutex_t m_lock; 248168404Spjd} kmutex_t; 249168404Spjd 250168404Spjd#define MUTEX_DEFAULT USYNC_THREAD 251219089Spjd#undef MUTEX_HELD 252219089Spjd#undef MUTEX_NOT_HELD 253168404Spjd#define MUTEX_HELD(m) ((m)->m_owner == curthread) 254219089Spjd#define MUTEX_NOT_HELD(m) (!MUTEX_HELD(m)) 255219089Spjd#define _mutex_held(m) pthread_mutex_isowned_np(m) 256168404Spjd 257168404Spjd/* 258168404Spjd * Argh -- we have to get cheesy here because the kernel and userland 259168404Spjd * have different signatures for the same routine. 260168404Spjd */ 261168404Spjd//extern int _mutex_init(mutex_t *mp, int type, void *arg); 262168404Spjd//extern int _mutex_destroy(mutex_t *mp); 263219089Spjd//extern int _mutex_owned(mutex_t *mp); 264168404Spjd 265168404Spjd#define mutex_init(mp, b, c, d) zmutex_init((kmutex_t *)(mp)) 266168404Spjd#define mutex_destroy(mp) zmutex_destroy((kmutex_t *)(mp)) 267195515Spjd#define mutex_owned(mp) zmutex_owned((kmutex_t *)(mp)) 268168404Spjd 269168404Spjdextern void zmutex_init(kmutex_t *mp); 270168404Spjdextern void zmutex_destroy(kmutex_t *mp); 271195515Spjdextern int zmutex_owned(kmutex_t *mp); 272168404Spjdextern void mutex_enter(kmutex_t *mp); 273168404Spjdextern void mutex_exit(kmutex_t *mp); 274168404Spjdextern int mutex_tryenter(kmutex_t *mp); 275168404Spjdextern void *mutex_owner(kmutex_t *mp); 276168404Spjd 277168404Spjd/* 278168404Spjd * RW locks 279168404Spjd */ 280168404Spjdtypedef struct krwlock { 281168404Spjd int rw_count; 282168404Spjd void *rw_owner; 283185029Spjd boolean_t initialized; 284168404Spjd rwlock_t rw_lock; 285168404Spjd} krwlock_t; 286168404Spjd 287168404Spjdtypedef int krw_t; 288168404Spjd 289168404Spjd#define RW_READER 0 290168404Spjd#define RW_WRITER 1 291168404Spjd#define RW_DEFAULT USYNC_THREAD 292168404Spjd 293168404Spjd#undef RW_READ_HELD 294185029Spjd#define RW_READ_HELD(x) ((x)->rw_owner == NULL && (x)->rw_count > 0) 295168404Spjd 296168404Spjd#undef RW_WRITE_HELD 297168404Spjd#define RW_WRITE_HELD(x) ((x)->rw_owner == curthread) 298168404Spjd#define RW_LOCK_HELD(x) rw_lock_held(x) 299168404Spjd 300168404Spjdextern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg); 301168404Spjdextern void rw_destroy(krwlock_t *rwlp); 302168404Spjdextern void rw_enter(krwlock_t *rwlp, krw_t rw); 303168404Spjdextern int rw_tryenter(krwlock_t *rwlp, krw_t rw); 304168404Spjdextern int rw_tryupgrade(krwlock_t *rwlp); 305168404Spjdextern void rw_exit(krwlock_t *rwlp); 306168404Spjdextern int rw_lock_held(krwlock_t *rwlp); 307168404Spjd#define rw_downgrade(rwlp) do { } while (0) 308168404Spjd 309185029Spjdextern uid_t crgetuid(cred_t *cr); 310185029Spjdextern gid_t crgetgid(cred_t *cr); 311185029Spjdextern int crgetngroups(cred_t *cr); 312185029Spjdextern gid_t *crgetgroups(cred_t *cr); 313185029Spjd 314168404Spjd/* 315168404Spjd * Condition variables 316168404Spjd */ 317168404Spjdtypedef cond_t kcondvar_t; 318168404Spjd 319168404Spjd#define CV_DEFAULT USYNC_THREAD 320168404Spjd 321168404Spjdextern void cv_init(kcondvar_t *cv, char *name, int type, void *arg); 322168404Spjdextern void cv_destroy(kcondvar_t *cv); 323168404Spjdextern void cv_wait(kcondvar_t *cv, kmutex_t *mp); 324168404Spjdextern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime); 325168404Spjdextern void cv_signal(kcondvar_t *cv); 326168404Spjdextern void cv_broadcast(kcondvar_t *cv); 327168404Spjd 328168404Spjd/* 329168404Spjd * Kernel memory 330168404Spjd */ 331168404Spjd#define KM_SLEEP UMEM_NOFAIL 332185029Spjd#define KM_PUSHPAGE KM_SLEEP 333168404Spjd#define KM_NOSLEEP UMEM_DEFAULT 334168404Spjd#define KMC_NODEBUG UMC_NODEBUG 335219089Spjd#define KMC_NOTOUCH 0 /* not needed for userland caches */ 336230629Skmacy#define KM_NODEBUG 0 337168404Spjd#define kmem_alloc(_s, _f) umem_alloc(_s, _f) 338168404Spjd#define kmem_zalloc(_s, _f) umem_zalloc(_s, _f) 339168404Spjd#define kmem_free(_b, _s) umem_free(_b, _s) 340168584Spjd#define kmem_size() (physmem * PAGESIZE) 341168404Spjd#define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \ 342168404Spjd umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) 343168404Spjd#define kmem_cache_destroy(_c) umem_cache_destroy(_c) 344168404Spjd#define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f) 345168404Spjd#define kmem_cache_free(_c, _b) umem_cache_free(_c, _b) 346168404Spjd#define kmem_debugging() 0 347219089Spjd#define kmem_cache_reap_now(_c) /* nothing */ 348219089Spjd#define kmem_cache_set_move(_c, _cb) /* nothing */ 349219089Spjd#define POINTER_INVALIDATE(_pp) /* nothing */ 350219089Spjd#define POINTER_IS_VALID(_p) 0 351168404Spjd 352168404Spjdtypedef umem_cache_t kmem_cache_t; 353168404Spjd 354219089Spjdtypedef enum kmem_cbrc { 355219089Spjd KMEM_CBRC_YES, 356219089Spjd KMEM_CBRC_NO, 357219089Spjd KMEM_CBRC_LATER, 358219089Spjd KMEM_CBRC_DONT_NEED, 359219089Spjd KMEM_CBRC_DONT_KNOW 360219089Spjd} kmem_cbrc_t; 361219089Spjd 362168404Spjd/* 363168404Spjd * Task queues 364168404Spjd */ 365168404Spjdtypedef struct taskq taskq_t; 366168404Spjdtypedef uintptr_t taskqid_t; 367168404Spjdtypedef void (task_func_t)(void *); 368168404Spjd 369168404Spjd#define TASKQ_PREPOPULATE 0x0001 370168404Spjd#define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ 371168404Spjd#define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ 372219089Spjd#define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */ 373219089Spjd#define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */ 374168404Spjd 375168404Spjd#define TQ_SLEEP KM_SLEEP /* Can block for memory */ 376168404Spjd#define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */ 377219089Spjd#define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ 378219089Spjd#define TQ_FRONT 0x08 /* Queue in front */ 379168404Spjd 380208047Smmextern taskq_t *system_taskq; 381208047Smm 382168404Spjdextern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); 383219089Spjd#define taskq_create_proc(a, b, c, d, e, p, f) \ 384219089Spjd (taskq_create(a, b, c, d, e, f)) 385219089Spjd#define taskq_create_sysdc(a, b, d, e, p, dc, f) \ 386219089Spjd (taskq_create(a, b, maxclsyspri, d, e, f)) 387168404Spjdextern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); 388168404Spjdextern void taskq_destroy(taskq_t *); 389168404Spjdextern void taskq_wait(taskq_t *); 390168404Spjdextern int taskq_member(taskq_t *, void *); 391208047Smmextern void system_taskq_init(void); 392219089Spjdextern void system_taskq_fini(void); 393168404Spjd 394219089Spjd#define taskq_dispatch_safe(tq, func, arg, flags, task) \ 395219089Spjd taskq_dispatch((tq), (func), (arg), (flags)) 396208166Spjd 397185029Spjd#define XVA_MAPSIZE 3 398185029Spjd#define XVA_MAGIC 0x78766174 399185029Spjd 400168404Spjd/* 401168404Spjd * vnodes 402168404Spjd */ 403168404Spjdtypedef struct vnode { 404168404Spjd uint64_t v_size; 405168404Spjd int v_fd; 406168404Spjd char *v_path; 407168404Spjd} vnode_t; 408168404Spjd 409219089Spjd#define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ 410185029Spjd 411185029Spjdtypedef struct xoptattr { 412185029Spjd timestruc_t xoa_createtime; /* Create time of file */ 413185029Spjd uint8_t xoa_archive; 414185029Spjd uint8_t xoa_system; 415185029Spjd uint8_t xoa_readonly; 416185029Spjd uint8_t xoa_hidden; 417185029Spjd uint8_t xoa_nounlink; 418185029Spjd uint8_t xoa_immutable; 419185029Spjd uint8_t xoa_appendonly; 420185029Spjd uint8_t xoa_nodump; 421185029Spjd uint8_t xoa_settable; 422185029Spjd uint8_t xoa_opaque; 423185029Spjd uint8_t xoa_av_quarantined; 424185029Spjd uint8_t xoa_av_modified; 425219089Spjd uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; 426219089Spjd uint8_t xoa_reparse; 427219089Spjd uint8_t xoa_offline; 428219089Spjd uint8_t xoa_sparse; 429185029Spjd} xoptattr_t; 430185029Spjd 431168404Spjdtypedef struct vattr { 432168404Spjd uint_t va_mask; /* bit-mask of attributes */ 433168404Spjd u_offset_t va_size; /* file size in bytes */ 434168404Spjd} vattr_t; 435168404Spjd 436168404Spjd 437185029Spjdtypedef struct xvattr { 438185029Spjd vattr_t xva_vattr; /* Embedded vattr structure */ 439185029Spjd uint32_t xva_magic; /* Magic Number */ 440185029Spjd uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ 441185029Spjd uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ 442185029Spjd uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ 443185029Spjd uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ 444185029Spjd xoptattr_t xva_xoptattrs; /* Optional attributes */ 445185029Spjd} xvattr_t; 446185029Spjd 447185029Spjdtypedef struct vsecattr { 448185029Spjd uint_t vsa_mask; /* See below */ 449185029Spjd int vsa_aclcnt; /* ACL entry count */ 450185029Spjd void *vsa_aclentp; /* pointer to ACL entries */ 451185029Spjd int vsa_dfaclcnt; /* default ACL entry count */ 452185029Spjd void *vsa_dfaclentp; /* pointer to default ACL entries */ 453185029Spjd size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ 454185029Spjd} vsecattr_t; 455185029Spjd 456185029Spjd#define AT_TYPE 0x00001 457185029Spjd#define AT_MODE 0x00002 458185029Spjd#define AT_UID 0x00004 459185029Spjd#define AT_GID 0x00008 460185029Spjd#define AT_FSID 0x00010 461185029Spjd#define AT_NODEID 0x00020 462185029Spjd#define AT_NLINK 0x00040 463185029Spjd#define AT_SIZE 0x00080 464185029Spjd#define AT_ATIME 0x00100 465185029Spjd#define AT_MTIME 0x00200 466185029Spjd#define AT_CTIME 0x00400 467185029Spjd#define AT_RDEV 0x00800 468185029Spjd#define AT_BLKSIZE 0x01000 469185029Spjd#define AT_NBLOCKS 0x02000 470185029Spjd#define AT_SEQ 0x08000 471185029Spjd#define AT_XVATTR 0x10000 472185029Spjd 473168404Spjd#define CRCREAT 0 474168404Spjd 475219089Spjdextern int fop_getattr(vnode_t *vp, vattr_t *vap); 476219089Spjd 477185029Spjd#define VOP_CLOSE(vp, f, c, o, cr, ct) 0 478185029Spjd#define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0 479219089Spjd#define VOP_GETATTR(vp, vap, cr) fop_getattr((vp), (vap)); 480168404Spjd 481185029Spjd#define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd) 482168404Spjd 483219089Spjd#define VN_RELE(vp) vn_close(vp, 0, NULL, NULL) 484191906Skmacy#define VN_RELE_ASYNC(vp, taskq) vn_close(vp, 0, NULL, NULL) 485168404Spjd 486185029Spjd#define vn_lock(vp, type) 487185029Spjd#define VOP_UNLOCK(vp, type) 488185029Spjd#ifdef VFS_LOCK_GIANT 489185029Spjd#undef VFS_LOCK_GIANT 490185029Spjd#endif 491185029Spjd#define VFS_LOCK_GIANT(mp) 0 492185029Spjd#ifdef VFS_UNLOCK_GIANT 493185029Spjd#undef VFS_UNLOCK_GIANT 494185029Spjd#endif 495185029Spjd#define VFS_UNLOCK_GIANT(vfslocked) 496185029Spjd 497168404Spjdextern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp, 498168404Spjd int x2, int x3); 499168404Spjdextern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp, 500185029Spjd int x2, int x3, vnode_t *vp, int fd); 501168404Spjdextern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, 502168404Spjd offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp); 503185029Spjdextern void vn_close(vnode_t *vp, int openflag, cred_t *cr, kthread_t *td); 504168404Spjd 505168404Spjd#define vn_remove(path, x1, x2) remove(path) 506168404Spjd#define vn_rename(from, to, seg) rename((from), (to)) 507168404Spjd#define vn_is_readonly(vp) B_FALSE 508168404Spjd 509168404Spjdextern vnode_t *rootdir; 510168404Spjd 511168404Spjd#include <sys/file.h> /* for FREAD, FWRITE, etc */ 512168404Spjd#define FTRUNC O_TRUNC 513168404Spjd 514168404Spjd/* 515168404Spjd * Random stuff 516168404Spjd */ 517219089Spjd#define ddi_get_lbolt() (gethrtime() >> 23) 518219089Spjd#define ddi_get_lbolt64() (gethrtime() >> 23) 519219089Spjd#define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */ 520168404Spjd 521168404Spjdextern void delay(clock_t ticks); 522168404Spjd 523168404Spjd#define gethrestime_sec() time(NULL) 524219089Spjd#define gethrestime(t) \ 525219089Spjd do {\ 526219089Spjd (t)->tv_sec = gethrestime_sec();\ 527219089Spjd (t)->tv_nsec = 0;\ 528219089Spjd } while (0); 529168404Spjd 530168404Spjd#define max_ncpus 64 531168404Spjd 532168404Spjd#define minclsyspri 60 533168404Spjd#define maxclsyspri 99 534168404Spjd 535168404Spjd#define CPU_SEQID (thr_self() & (max_ncpus - 1)) 536168404Spjd 537219089Spjd#define kcred NULL 538219089Spjd#define CRED() NULL 539219089Spjd 540185029Spjd#ifndef ptob 541185029Spjd#define ptob(x) ((x) * PAGESIZE) 542185029Spjd#endif 543168404Spjd 544168404Spjdextern uint64_t physmem; 545168404Spjd 546168404Spjdextern int highbit(ulong_t i); 547168404Spjdextern int random_get_bytes(uint8_t *ptr, size_t len); 548168404Spjdextern int random_get_pseudo_bytes(uint8_t *ptr, size_t len); 549168404Spjd 550168404Spjdextern void kernel_init(int); 551168404Spjdextern void kernel_fini(void); 552168404Spjd 553168404Spjdstruct spa; 554168404Spjdextern void nicenum(uint64_t num, char *buf); 555168404Spjdextern void show_pool_stats(struct spa *); 556168404Spjd 557168404Spjdtypedef struct callb_cpr { 558168404Spjd kmutex_t *cc_lockp; 559168404Spjd} callb_cpr_t; 560168404Spjd 561168404Spjd#define CALLB_CPR_INIT(cp, lockp, func, name) { \ 562168404Spjd (cp)->cc_lockp = lockp; \ 563168404Spjd} 564168404Spjd 565168404Spjd#define CALLB_CPR_SAFE_BEGIN(cp) { \ 566168404Spjd ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 567168404Spjd} 568168404Spjd 569168404Spjd#define CALLB_CPR_SAFE_END(cp, lockp) { \ 570168404Spjd ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 571168404Spjd} 572168404Spjd 573168404Spjd#define CALLB_CPR_EXIT(cp) { \ 574168404Spjd ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 575168404Spjd mutex_exit((cp)->cc_lockp); \ 576168404Spjd} 577168404Spjd 578168404Spjd#define zone_dataset_visible(x, y) (1) 579168404Spjd#define INGLOBALZONE(z) (1) 580168404Spjd 581219089Spjdextern char *kmem_asprintf(const char *fmt, ...); 582219089Spjd#define strfree(str) kmem_free((str), strlen(str)+1) 583219089Spjd 584168498Spjd/* 585168498Spjd * Hostname information 586168498Spjd */ 587168498Spjdextern struct utsname utsname; 588219089Spjdextern char hw_serial[]; /* for userland-emulated hostid access */ 589168498Spjdextern int ddi_strtoul(const char *str, char **nptr, int base, 590168498Spjd unsigned long *result); 591168498Spjd 592219089Spjdextern int ddi_strtoull(const char *str, char **nptr, int base, 593219089Spjd u_longlong_t *result); 594219089Spjd 595168404Spjd/* ZFS Boot Related stuff. */ 596168404Spjd 597168404Spjdstruct _buf { 598168404Spjd intptr_t _fd; 599168404Spjd}; 600168404Spjd 601168404Spjdstruct bootstat { 602168404Spjd uint64_t st_size; 603168404Spjd}; 604168404Spjd 605185029Spjdtypedef struct ace_object { 606185029Spjd uid_t a_who; 607185029Spjd uint32_t a_access_mask; 608185029Spjd uint16_t a_flags; 609185029Spjd uint16_t a_type; 610185029Spjd uint8_t a_obj_type[16]; 611185029Spjd uint8_t a_inherit_obj_type[16]; 612185029Spjd} ace_object_t; 613185029Spjd 614185029Spjd 615185029Spjd#define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 616185029Spjd#define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 617185029Spjd#define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 618185029Spjd#define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 619185029Spjd 620168404Spjdextern struct _buf *kobj_open_file(char *name); 621168404Spjdextern int kobj_read_file(struct _buf *file, char *buf, unsigned size, 622168404Spjd unsigned off); 623168404Spjdextern void kobj_close_file(struct _buf *file); 624168404Spjdextern int kobj_get_filesize(struct _buf *file, uint64_t *size); 625185029Spjdextern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); 626185029Spjdextern int zfs_secpolicy_rename_perms(const char *from, const char *to, 627185029Spjd cred_t *cr); 628185029Spjdextern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); 629185029Spjdextern zoneid_t getzoneid(void); 630168404Spjd/* Random compatibility stuff. */ 631168404Spjd#define lbolt (gethrtime() >> 23) 632168404Spjd#define lbolt64 (gethrtime() >> 23) 633168404Spjd 634168404Spjdextern uint64_t physmem; 635168404Spjd 636168404Spjd#define gethrestime_sec() time(NULL) 637168404Spjd 638168404Spjd#define pwrite64(d, p, n, o) pwrite(d, p, n, o) 639168404Spjd#define readdir64(d) readdir(d) 640168404Spjd#define SIGPENDING(td) (0) 641168404Spjd#define root_mount_wait() do { } while (0) 642168825Spjd#define root_mounted() (1) 643168404Spjd 644168404Spjdstruct file { 645168404Spjd void *dummy; 646168404Spjd}; 647168404Spjd 648168404Spjd#define FCREAT O_CREAT 649168404Spjd#define FOFFMAX 0x0 650168404Spjd 651185029Spjd/* SID stuff */ 652185029Spjdtypedef struct ksiddomain { 653185029Spjd uint_t kd_ref; 654185029Spjd uint_t kd_len; 655185029Spjd char *kd_name; 656185029Spjd} ksiddomain_t; 657185029Spjd 658185029Spjdksiddomain_t *ksid_lookupdomain(const char *); 659185029Spjdvoid ksiddomain_rele(ksiddomain_t *); 660185029Spjd 661209962Smmtypedef uint32_t idmap_rid_t; 662209962Smm 663219089Spjd#define DDI_SLEEP KM_SLEEP 664219089Spjd#define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) (0) 665219089Spjd 666168404Spjd#define SX_SYSINIT(name, lock, desc) 667168404Spjd 668168404Spjd#define SYSCTL_DECL(...) 669168582Spjd#define SYSCTL_NODE(...) 670168404Spjd#define SYSCTL_INT(...) 671185029Spjd#define SYSCTL_UINT(...) 672168582Spjd#define SYSCTL_ULONG(...) 673185029Spjd#define SYSCTL_QUAD(...) 674217367Smdf#define SYSCTL_UQUAD(...) 675168404Spjd#ifdef TUNABLE_INT 676168404Spjd#undef TUNABLE_INT 677168582Spjd#undef TUNABLE_ULONG 678185029Spjd#undef TUNABLE_QUAD 679168404Spjd#endif 680168404Spjd#define TUNABLE_INT(...) 681168582Spjd#define TUNABLE_ULONG(...) 682185029Spjd#define TUNABLE_QUAD(...) 683168404Spjd 684168404Spjd/* Errors */ 685168404Spjd 686168404Spjd#ifndef ERESTART 687168404Spjd#define ERESTART (-1) 688168404Spjd#endif 689168404Spjd 690169301Spjd#ifdef __cplusplus 691169301Spjd} 692169301Spjd#endif 693169301Spjd 694168404Spjd#endif /* _SYS_ZFS_CONTEXT_H */ 695