zfs_context.h revision 288593
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/* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved. 24 * Copyright (c) 2012, Joyent, Inc. All rights reserved. 25 */ 26/* 27 * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 28 */ 29 30#ifndef _SYS_ZFS_CONTEXT_H 31#define _SYS_ZFS_CONTEXT_H 32 33#ifdef __cplusplus 34extern "C" { 35#endif 36 37#define _SYS_MUTEX_H 38#define _SYS_RWLOCK_H 39#define _SYS_CONDVAR_H 40#define _SYS_SYSTM_H 41#define _SYS_T_LOCK_H 42#define _SYS_VNODE_H 43#define _SYS_VFS_H 44#define _SYS_SUNDDI_H 45#define _SYS_CALLB_H 46#define _SYS_SCHED_H_ 47 48#include <solaris.h> 49#include <stdio.h> 50#include <stdlib.h> 51#include <stddef.h> 52#include <stdarg.h> 53#include <fcntl.h> 54#include <unistd.h> 55#include <errno.h> 56#include <string.h> 57#include <strings.h> 58#include <thread.h> 59#include <assert.h> 60#include <limits.h> 61#include <dirent.h> 62#include <time.h> 63#include <math.h> 64#include <umem.h> 65#include <inttypes.h> 66#include <fsshare.h> 67#include <pthread.h> 68#include <sched.h> 69#include <sys/debug.h> 70#include <sys/note.h> 71#include <sys/types.h> 72#include <sys/cred.h> 73#include <sys/atomic.h> 74#include <sys/sysmacros.h> 75#include <sys/bitmap.h> 76#include <sys/resource.h> 77#include <sys/byteorder.h> 78#include <sys/list.h> 79#include <sys/time.h> 80#include <sys/uio.h> 81#include <sys/mntent.h> 82#include <sys/mnttab.h> 83#include <sys/zfs_debug.h> 84#include <sys/sdt.h> 85#include <sys/kstat.h> 86#include <sys/u8_textprep.h> 87#include <sys/kernel.h> 88#include <sys/disk.h> 89#include <sys/sysevent.h> 90#include <sys/sysevent/eventdefs.h> 91#include <sys/sysevent/dev.h> 92#include <machine/atomic.h> 93#include <sys/debug.h> 94#ifdef illumos 95#include "zfs.h" 96#endif 97 98#define ZFS_EXPORTS_PATH "/etc/zfs/exports" 99 100/* 101 * Debugging 102 */ 103 104/* 105 * Note that we are not using the debugging levels. 106 */ 107 108#define CE_CONT 0 /* continuation */ 109#define CE_NOTE 1 /* notice */ 110#define CE_WARN 2 /* warning */ 111#define CE_PANIC 3 /* panic */ 112#define CE_IGNORE 4 /* print nothing */ 113 114/* 115 * ZFS debugging 116 */ 117 118#define ZFS_LOG(...) do { } while (0) 119 120typedef u_longlong_t rlim64_t; 121#define RLIM64_INFINITY ((rlim64_t)-3) 122 123#ifdef ZFS_DEBUG 124extern void dprintf_setup(int *argc, char **argv); 125#endif /* ZFS_DEBUG */ 126 127extern void cmn_err(int, const char *, ...); 128extern void vcmn_err(int, const char *, __va_list); 129extern void panic(const char *, ...); 130extern void vpanic(const char *, __va_list); 131 132#define fm_panic panic 133 134extern int aok; 135 136/* 137 * DTrace SDT probes have different signatures in userland than they do in 138 * the kernel. If they're being used in kernel code, re-define them out of 139 * existence for their counterparts in libzpool. 140 * 141 * Here's an example of how to use the set-error probes in userland: 142 * zfs$target:::set-error /arg0 == EBUSY/ {stack();} 143 * 144 * Here's an example of how to use DTRACE_PROBE probes in userland: 145 * If there is a probe declared as follows: 146 * DTRACE_PROBE2(zfs__probe_name, uint64_t, blkid, dnode_t *, dn); 147 * Then you can use it as follows: 148 * zfs$target:::probe2 /copyinstr(arg0) == "zfs__probe_name"/ 149 * {printf("%u %p\n", arg1, arg2);} 150 */ 151 152#ifdef DTRACE_PROBE 153#undef DTRACE_PROBE 154#endif /* DTRACE_PROBE */ 155#ifdef illumos 156#define DTRACE_PROBE(a) \ 157 ZFS_PROBE0(#a) 158#endif 159 160#ifdef DTRACE_PROBE1 161#undef DTRACE_PROBE1 162#endif /* DTRACE_PROBE1 */ 163#ifdef illumos 164#define DTRACE_PROBE1(a, b, c) \ 165 ZFS_PROBE1(#a, (unsigned long)c) 166#endif 167 168#ifdef DTRACE_PROBE2 169#undef DTRACE_PROBE2 170#endif /* DTRACE_PROBE2 */ 171#ifdef illumos 172#define DTRACE_PROBE2(a, b, c, d, e) \ 173 ZFS_PROBE2(#a, (unsigned long)c, (unsigned long)e) 174#endif 175 176#ifdef DTRACE_PROBE3 177#undef DTRACE_PROBE3 178#endif /* DTRACE_PROBE3 */ 179#ifdef illumos 180#define DTRACE_PROBE3(a, b, c, d, e, f, g) \ 181 ZFS_PROBE3(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g) 182#endif 183 184#ifdef DTRACE_PROBE4 185#undef DTRACE_PROBE4 186#endif /* DTRACE_PROBE4 */ 187#ifdef illumos 188#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) \ 189 ZFS_PROBE4(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g, \ 190 (unsigned long)i) 191#endif 192 193#ifdef illumos 194/* 195 * We use the comma operator so that this macro can be used without much 196 * additional code. For example, "return (EINVAL);" becomes 197 * "return (SET_ERROR(EINVAL));". Note that the argument will be evaluated 198 * twice, so it should not have side effects (e.g. something like: 199 * "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice). 200 */ 201#define SET_ERROR(err) (ZFS_SET_ERROR(err), err) 202#else /* !illumos */ 203 204#define DTRACE_PROBE(a) ((void)0) 205#define DTRACE_PROBE1(a, b, c) ((void)0) 206#define DTRACE_PROBE2(a, b, c, d, e) ((void)0) 207#define DTRACE_PROBE3(a, b, c, d, e, f, g) ((void)0) 208#define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) 209 210#define SET_ERROR(err) (err) 211#endif /* !illumos */ 212 213/* 214 * Threads 215 */ 216#define curthread ((void *)(uintptr_t)thr_self()) 217 218#define kpreempt(x) sched_yield() 219 220typedef struct kthread kthread_t; 221 222#define thread_create(stk, stksize, func, arg, len, pp, state, pri) \ 223 zk_thread_create(func, arg) 224#define thread_exit() thr_exit(NULL) 225#define thread_join(t) panic("libzpool cannot join threads") 226 227#define newproc(f, a, cid, pri, ctp, pid) (ENOSYS) 228 229/* in libzpool, p0 exists only to have its address taken */ 230struct proc { 231 uintptr_t this_is_never_used_dont_dereference_it; 232}; 233 234extern struct proc p0; 235#define curproc (&p0) 236 237#define PS_NONE -1 238 239extern kthread_t *zk_thread_create(void (*func)(), void *arg); 240 241#define issig(why) (FALSE) 242#define ISSIG(thr, why) (FALSE) 243 244/* 245 * Mutexes 246 */ 247typedef struct kmutex { 248 void *m_owner; 249 boolean_t initialized; 250 mutex_t m_lock; 251} kmutex_t; 252 253#define MUTEX_DEFAULT USYNC_THREAD 254#undef MUTEX_HELD 255#undef MUTEX_NOT_HELD 256#define MUTEX_HELD(m) ((m)->m_owner == curthread) 257#define MUTEX_NOT_HELD(m) (!MUTEX_HELD(m)) 258#define _mutex_held(m) pthread_mutex_isowned_np(m) 259 260/* 261 * Argh -- we have to get cheesy here because the kernel and userland 262 * have different signatures for the same routine. 263 */ 264//extern int _mutex_init(mutex_t *mp, int type, void *arg); 265//extern int _mutex_destroy(mutex_t *mp); 266//extern int _mutex_owned(mutex_t *mp); 267 268#define mutex_init(mp, b, c, d) zmutex_init((kmutex_t *)(mp)) 269#define mutex_destroy(mp) zmutex_destroy((kmutex_t *)(mp)) 270#define mutex_owned(mp) zmutex_owned((kmutex_t *)(mp)) 271 272extern void zmutex_init(kmutex_t *mp); 273extern void zmutex_destroy(kmutex_t *mp); 274extern int zmutex_owned(kmutex_t *mp); 275extern void mutex_enter(kmutex_t *mp); 276extern void mutex_exit(kmutex_t *mp); 277extern int mutex_tryenter(kmutex_t *mp); 278extern void *mutex_owner(kmutex_t *mp); 279 280/* 281 * RW locks 282 */ 283typedef struct krwlock { 284 int rw_count; 285 void *rw_owner; 286 boolean_t initialized; 287 rwlock_t rw_lock; 288} krwlock_t; 289 290typedef int krw_t; 291 292#define RW_READER 0 293#define RW_WRITER 1 294#define RW_DEFAULT USYNC_THREAD 295 296#undef RW_READ_HELD 297#define RW_READ_HELD(x) ((x)->rw_owner == NULL && (x)->rw_count > 0) 298 299#undef RW_WRITE_HELD 300#define RW_WRITE_HELD(x) ((x)->rw_owner == curthread) 301#define RW_LOCK_HELD(x) rw_lock_held(x) 302 303#undef RW_LOCK_HELD 304#define RW_LOCK_HELD(x) (RW_READ_HELD(x) || RW_WRITE_HELD(x)) 305 306extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg); 307extern void rw_destroy(krwlock_t *rwlp); 308extern void rw_enter(krwlock_t *rwlp, krw_t rw); 309extern int rw_tryenter(krwlock_t *rwlp, krw_t rw); 310extern int rw_tryupgrade(krwlock_t *rwlp); 311extern void rw_exit(krwlock_t *rwlp); 312extern int rw_lock_held(krwlock_t *rwlp); 313#define rw_downgrade(rwlp) do { } while (0) 314 315extern uid_t crgetuid(cred_t *cr); 316extern uid_t crgetruid(cred_t *cr); 317extern gid_t crgetgid(cred_t *cr); 318extern int crgetngroups(cred_t *cr); 319extern gid_t *crgetgroups(cred_t *cr); 320 321/* 322 * Condition variables 323 */ 324typedef cond_t kcondvar_t; 325 326#define CV_DEFAULT USYNC_THREAD 327 328extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg); 329extern void cv_destroy(kcondvar_t *cv); 330extern void cv_wait(kcondvar_t *cv, kmutex_t *mp); 331extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime); 332extern clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim, 333 hrtime_t res, int flag); 334extern void cv_signal(kcondvar_t *cv); 335extern void cv_broadcast(kcondvar_t *cv); 336 337/* 338 * Thread-specific data 339 */ 340#define tsd_get(k) pthread_getspecific(k) 341#define tsd_set(k, v) pthread_setspecific(k, v) 342#define tsd_create(kp, d) pthread_key_create(kp, d) 343#define tsd_destroy(kp) /* nothing */ 344 345/* 346 * Kernel memory 347 */ 348#define KM_SLEEP UMEM_NOFAIL 349#define KM_PUSHPAGE KM_SLEEP 350#define KM_NOSLEEP UMEM_DEFAULT 351#define KMC_NODEBUG UMC_NODEBUG 352#define KMC_NOTOUCH 0 /* not needed for userland caches */ 353#define KM_NODEBUG 0 354#define kmem_alloc(_s, _f) umem_alloc(_s, _f) 355#define kmem_zalloc(_s, _f) umem_zalloc(_s, _f) 356#define kmem_free(_b, _s) umem_free(_b, _s) 357#define kmem_size() (physmem * PAGESIZE) 358#define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \ 359 umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) 360#define kmem_cache_destroy(_c) umem_cache_destroy(_c) 361#define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f) 362#define kmem_cache_free(_c, _b) umem_cache_free(_c, _b) 363#define kmem_debugging() 0 364#define kmem_cache_reap_now(_c) /* nothing */ 365#define kmem_cache_set_move(_c, _cb) /* nothing */ 366#define POINTER_INVALIDATE(_pp) /* nothing */ 367#define POINTER_IS_VALID(_p) 0 368 369typedef umem_cache_t kmem_cache_t; 370 371typedef enum kmem_cbrc { 372 KMEM_CBRC_YES, 373 KMEM_CBRC_NO, 374 KMEM_CBRC_LATER, 375 KMEM_CBRC_DONT_NEED, 376 KMEM_CBRC_DONT_KNOW 377} kmem_cbrc_t; 378 379/* 380 * Task queues 381 */ 382typedef struct taskq taskq_t; 383typedef uintptr_t taskqid_t; 384typedef void (task_func_t)(void *); 385 386typedef struct taskq_ent { 387 struct taskq_ent *tqent_next; 388 struct taskq_ent *tqent_prev; 389 task_func_t *tqent_func; 390 void *tqent_arg; 391 uintptr_t tqent_flags; 392} taskq_ent_t; 393 394#define TQENT_FLAG_PREALLOC 0x1 /* taskq_dispatch_ent used */ 395 396#define TASKQ_PREPOPULATE 0x0001 397#define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ 398#define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ 399#define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */ 400#define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */ 401 402#define TQ_SLEEP KM_SLEEP /* Can block for memory */ 403#define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */ 404#define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ 405#define TQ_FRONT 0x08 /* Queue in front */ 406 407 408extern taskq_t *system_taskq; 409 410extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); 411#define taskq_create_proc(a, b, c, d, e, p, f) \ 412 (taskq_create(a, b, c, d, e, f)) 413#define taskq_create_sysdc(a, b, d, e, p, dc, f) \ 414 (taskq_create(a, b, maxclsyspri, d, e, f)) 415extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); 416extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, 417 taskq_ent_t *); 418extern void taskq_destroy(taskq_t *); 419extern void taskq_wait(taskq_t *); 420extern int taskq_member(taskq_t *, void *); 421extern void system_taskq_init(void); 422extern void system_taskq_fini(void); 423 424#define taskq_dispatch_safe(tq, func, arg, flags, task) \ 425 taskq_dispatch((tq), (func), (arg), (flags)) 426 427#define XVA_MAPSIZE 3 428#define XVA_MAGIC 0x78766174 429 430/* 431 * vnodes 432 */ 433typedef struct vnode { 434 uint64_t v_size; 435 int v_fd; 436 char *v_path; 437 int v_dump_fd; 438} vnode_t; 439 440extern char *vn_dumpdir; 441#define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ 442 443typedef struct xoptattr { 444 timestruc_t xoa_createtime; /* Create time of file */ 445 uint8_t xoa_archive; 446 uint8_t xoa_system; 447 uint8_t xoa_readonly; 448 uint8_t xoa_hidden; 449 uint8_t xoa_nounlink; 450 uint8_t xoa_immutable; 451 uint8_t xoa_appendonly; 452 uint8_t xoa_nodump; 453 uint8_t xoa_settable; 454 uint8_t xoa_opaque; 455 uint8_t xoa_av_quarantined; 456 uint8_t xoa_av_modified; 457 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; 458 uint8_t xoa_reparse; 459 uint8_t xoa_offline; 460 uint8_t xoa_sparse; 461} xoptattr_t; 462 463typedef struct vattr { 464 uint_t va_mask; /* bit-mask of attributes */ 465 u_offset_t va_size; /* file size in bytes */ 466} vattr_t; 467 468 469typedef struct xvattr { 470 vattr_t xva_vattr; /* Embedded vattr structure */ 471 uint32_t xva_magic; /* Magic Number */ 472 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ 473 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ 474 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ 475 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ 476 xoptattr_t xva_xoptattrs; /* Optional attributes */ 477} xvattr_t; 478 479typedef struct vsecattr { 480 uint_t vsa_mask; /* See below */ 481 int vsa_aclcnt; /* ACL entry count */ 482 void *vsa_aclentp; /* pointer to ACL entries */ 483 int vsa_dfaclcnt; /* default ACL entry count */ 484 void *vsa_dfaclentp; /* pointer to default ACL entries */ 485 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ 486} vsecattr_t; 487 488#define AT_TYPE 0x00001 489#define AT_MODE 0x00002 490#define AT_UID 0x00004 491#define AT_GID 0x00008 492#define AT_FSID 0x00010 493#define AT_NODEID 0x00020 494#define AT_NLINK 0x00040 495#define AT_SIZE 0x00080 496#define AT_ATIME 0x00100 497#define AT_MTIME 0x00200 498#define AT_CTIME 0x00400 499#define AT_RDEV 0x00800 500#define AT_BLKSIZE 0x01000 501#define AT_NBLOCKS 0x02000 502#define AT_SEQ 0x08000 503#define AT_XVATTR 0x10000 504 505#define CRCREAT 0 506 507extern int fop_getattr(vnode_t *vp, vattr_t *vap); 508 509#define VOP_CLOSE(vp, f, c, o, cr, ct) 0 510#define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0 511#define VOP_GETATTR(vp, vap, cr) fop_getattr((vp), (vap)); 512 513#define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd) 514 515#define VN_RELE(vp) vn_close(vp, 0, NULL, NULL) 516#define VN_RELE_ASYNC(vp, taskq) vn_close(vp, 0, NULL, NULL) 517 518#define vn_lock(vp, type) 519#define VOP_UNLOCK(vp, type) 520 521extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp, 522 int x2, int x3); 523extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp, 524 int x2, int x3, vnode_t *vp, int fd); 525extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, 526 offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp); 527extern void vn_close(vnode_t *vp, int openflag, cred_t *cr, kthread_t *td); 528 529#define vn_remove(path, x1, x2) remove(path) 530#define vn_rename(from, to, seg) rename((from), (to)) 531#define vn_is_readonly(vp) B_FALSE 532 533extern vnode_t *rootdir; 534 535#include <sys/file.h> /* for FREAD, FWRITE, etc */ 536#define FTRUNC O_TRUNC 537 538/* 539 * Random stuff 540 */ 541#define ddi_get_lbolt() (gethrtime() >> 23) 542#define ddi_get_lbolt64() (gethrtime() >> 23) 543#define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */ 544 545extern void delay(clock_t ticks); 546 547#define SEC_TO_TICK(sec) ((sec) * hz) 548#define NSEC_TO_TICK(usec) ((usec) / (NANOSEC / hz)) 549 550#define gethrestime_sec() time(NULL) 551#define gethrestime(t) \ 552 do {\ 553 (t)->tv_sec = gethrestime_sec();\ 554 (t)->tv_nsec = 0;\ 555 } while (0); 556 557#define max_ncpus 64 558 559#define minclsyspri 60 560#define maxclsyspri 99 561 562#define CPU_SEQID (thr_self() & (max_ncpus - 1)) 563 564#define kcred NULL 565#define CRED() NULL 566 567#ifndef ptob 568#define ptob(x) ((x) * PAGESIZE) 569#endif 570 571extern uint64_t physmem; 572 573extern int highbit64(uint64_t i); 574extern int random_get_bytes(uint8_t *ptr, size_t len); 575extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len); 576 577extern void kernel_init(int); 578extern void kernel_fini(void); 579 580struct spa; 581extern void nicenum(uint64_t num, char *buf); 582extern void show_pool_stats(struct spa *); 583 584typedef struct callb_cpr { 585 kmutex_t *cc_lockp; 586} callb_cpr_t; 587 588#define CALLB_CPR_INIT(cp, lockp, func, name) { \ 589 (cp)->cc_lockp = lockp; \ 590} 591 592#define CALLB_CPR_SAFE_BEGIN(cp) { \ 593 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 594} 595 596#define CALLB_CPR_SAFE_END(cp, lockp) { \ 597 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 598} 599 600#define CALLB_CPR_EXIT(cp) { \ 601 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 602 mutex_exit((cp)->cc_lockp); \ 603} 604 605#define zone_dataset_visible(x, y) (1) 606#define INGLOBALZONE(z) (1) 607 608extern char *kmem_asprintf(const char *fmt, ...); 609#define strfree(str) kmem_free((str), strlen(str) + 1) 610 611/* 612 * Hostname information 613 */ 614extern struct utsname utsname; 615extern char hw_serial[]; /* for userland-emulated hostid access */ 616extern int ddi_strtoul(const char *str, char **nptr, int base, 617 unsigned long *result); 618 619extern int ddi_strtoull(const char *str, char **nptr, int base, 620 u_longlong_t *result); 621 622/* ZFS Boot Related stuff. */ 623 624struct _buf { 625 intptr_t _fd; 626}; 627 628struct bootstat { 629 uint64_t st_size; 630}; 631 632typedef struct ace_object { 633 uid_t a_who; 634 uint32_t a_access_mask; 635 uint16_t a_flags; 636 uint16_t a_type; 637 uint8_t a_obj_type[16]; 638 uint8_t a_inherit_obj_type[16]; 639} ace_object_t; 640 641 642#define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 643#define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 644#define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 645#define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 646 647extern struct _buf *kobj_open_file(char *name); 648extern int kobj_read_file(struct _buf *file, char *buf, unsigned size, 649 unsigned off); 650extern void kobj_close_file(struct _buf *file); 651extern int kobj_get_filesize(struct _buf *file, uint64_t *size); 652extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); 653extern int zfs_secpolicy_rename_perms(const char *from, const char *to, 654 cred_t *cr); 655extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); 656extern zoneid_t getzoneid(void); 657/* Random compatibility stuff. */ 658#define pwrite64(d, p, n, o) pwrite(d, p, n, o) 659#define readdir64(d) readdir(d) 660#define SIGPENDING(td) (0) 661#define root_mount_wait() do { } while (0) 662#define root_mounted() (1) 663 664struct file { 665 void *dummy; 666}; 667 668#define FCREAT O_CREAT 669#define FOFFMAX 0x0 670 671/* SID stuff */ 672typedef struct ksiddomain { 673 uint_t kd_ref; 674 uint_t kd_len; 675 char *kd_name; 676} ksiddomain_t; 677 678ksiddomain_t *ksid_lookupdomain(const char *); 679void ksiddomain_rele(ksiddomain_t *); 680 681typedef uint32_t idmap_rid_t; 682 683#define DDI_SLEEP KM_SLEEP 684#define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) (0) 685 686#define SX_SYSINIT(name, lock, desc) 687 688#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, \ 689 intptr_t arg2, struct sysctl_req *req 690 691/* 692 * This describes the access space for a sysctl request. This is needed 693 * so that we can use the interface from the kernel or from user-space. 694 */ 695struct sysctl_req { 696 struct thread *td; /* used for access checking */ 697 int lock; /* wiring state */ 698 void *oldptr; 699 size_t oldlen; 700 size_t oldidx; 701 int (*oldfunc)(struct sysctl_req *, const void *, size_t); 702 void *newptr; 703 size_t newlen; 704 size_t newidx; 705 int (*newfunc)(struct sysctl_req *, void *, size_t); 706 size_t validlen; 707 int flags; 708}; 709 710SLIST_HEAD(sysctl_oid_list, sysctl_oid); 711 712/* 713 * This describes one "oid" in the MIB tree. Potentially more nodes can 714 * be hidden behind it, expanded by the handler. 715 */ 716struct sysctl_oid { 717 struct sysctl_oid_list *oid_parent; 718 SLIST_ENTRY(sysctl_oid) oid_link; 719 int oid_number; 720 u_int oid_kind; 721 void *oid_arg1; 722 intptr_t oid_arg2; 723 const char *oid_name; 724 int (*oid_handler)(SYSCTL_HANDLER_ARGS); 725 const char *oid_fmt; 726 int oid_refcnt; 727 u_int oid_running; 728 const char *oid_descr; 729}; 730 731#define SYSCTL_DECL(...) 732#define SYSCTL_NODE(...) 733#define SYSCTL_INT(...) 734#define SYSCTL_UINT(...) 735#define SYSCTL_ULONG(...) 736#define SYSCTL_PROC(...) 737#define SYSCTL_QUAD(...) 738#define SYSCTL_UQUAD(...) 739#ifdef TUNABLE_INT 740#undef TUNABLE_INT 741#undef TUNABLE_ULONG 742#undef TUNABLE_QUAD 743#endif 744#define TUNABLE_INT(...) 745#define TUNABLE_ULONG(...) 746#define TUNABLE_QUAD(...) 747 748int sysctl_handle_64(SYSCTL_HANDLER_ARGS); 749 750/* Errors */ 751 752#ifndef ERESTART 753#define ERESTART (-1) 754#endif 755 756#ifdef illumos 757/* 758 * Cyclic information 759 */ 760extern kmutex_t cpu_lock; 761 762typedef uintptr_t cyclic_id_t; 763typedef uint16_t cyc_level_t; 764typedef void (*cyc_func_t)(void *); 765 766#define CY_LOW_LEVEL 0 767#define CY_INFINITY INT64_MAX 768#define CYCLIC_NONE ((cyclic_id_t)0) 769 770typedef struct cyc_time { 771 hrtime_t cyt_when; 772 hrtime_t cyt_interval; 773} cyc_time_t; 774 775typedef struct cyc_handler { 776 cyc_func_t cyh_func; 777 void *cyh_arg; 778 cyc_level_t cyh_level; 779} cyc_handler_t; 780 781extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *); 782extern void cyclic_remove(cyclic_id_t); 783extern int cyclic_reprogram(cyclic_id_t, hrtime_t); 784#endif /* illumos */ 785 786#ifdef illumos 787/* 788 * Buf structure 789 */ 790#define B_BUSY 0x0001 791#define B_DONE 0x0002 792#define B_ERROR 0x0004 793#define B_READ 0x0040 /* read when I/O occurs */ 794#define B_WRITE 0x0100 /* non-read pseudo-flag */ 795 796typedef struct buf { 797 int b_flags; 798 size_t b_bcount; 799 union { 800 caddr_t b_addr; 801 } b_un; 802 803 lldaddr_t _b_blkno; 804#define b_lblkno _b_blkno._f 805 size_t b_resid; 806 size_t b_bufsize; 807 int (*b_iodone)(struct buf *); 808 int b_error; 809 void *b_private; 810} buf_t; 811 812extern void bioinit(buf_t *); 813extern void biodone(buf_t *); 814extern void bioerror(buf_t *, int); 815extern int geterror(buf_t *); 816#endif 817 818#ifdef __cplusplus 819} 820#endif 821 822#endif /* _SYS_ZFS_CONTEXT_H */ 823