zfs_context.h revision 325915
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, 2015 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#define CALLOUT_FLAG_ABSOLUTE 0x2 328 329extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg); 330extern void cv_destroy(kcondvar_t *cv); 331extern void cv_wait(kcondvar_t *cv, kmutex_t *mp); 332extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime); 333extern clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim, 334 hrtime_t res, int flag); 335extern void cv_signal(kcondvar_t *cv); 336extern void cv_broadcast(kcondvar_t *cv); 337 338/* 339 * Thread-specific data 340 */ 341#define tsd_get(k) pthread_getspecific(k) 342#define tsd_set(k, v) pthread_setspecific(k, v) 343#define tsd_create(kp, d) pthread_key_create(kp, d) 344#define tsd_destroy(kp) /* nothing */ 345 346/* 347 * Kernel memory 348 */ 349#define KM_SLEEP UMEM_NOFAIL 350#define KM_PUSHPAGE KM_SLEEP 351#define KM_NOSLEEP UMEM_DEFAULT 352#define KMC_NODEBUG UMC_NODEBUG 353#define KMC_NOTOUCH 0 /* not needed for userland caches */ 354#define KM_NODEBUG 0 355#define kmem_alloc(_s, _f) umem_alloc(_s, _f) 356#define kmem_zalloc(_s, _f) umem_zalloc(_s, _f) 357#define kmem_free(_b, _s) umem_free(_b, _s) 358#define kmem_size() (physmem * PAGESIZE) 359#define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \ 360 umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) 361#define kmem_cache_destroy(_c) umem_cache_destroy(_c) 362#define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f) 363#define kmem_cache_free(_c, _b) umem_cache_free(_c, _b) 364#define kmem_debugging() 0 365#define kmem_cache_reap_now(_c) /* nothing */ 366#define kmem_cache_set_move(_c, _cb) /* nothing */ 367#define POINTER_INVALIDATE(_pp) /* nothing */ 368#define POINTER_IS_VALID(_p) 0 369 370typedef umem_cache_t kmem_cache_t; 371 372typedef enum kmem_cbrc { 373 KMEM_CBRC_YES, 374 KMEM_CBRC_NO, 375 KMEM_CBRC_LATER, 376 KMEM_CBRC_DONT_NEED, 377 KMEM_CBRC_DONT_KNOW 378} kmem_cbrc_t; 379 380/* 381 * Task queues 382 */ 383typedef struct taskq taskq_t; 384typedef uintptr_t taskqid_t; 385typedef void (task_func_t)(void *); 386 387typedef struct taskq_ent { 388 struct taskq_ent *tqent_next; 389 struct taskq_ent *tqent_prev; 390 task_func_t *tqent_func; 391 void *tqent_arg; 392 uintptr_t tqent_flags; 393} taskq_ent_t; 394 395#define TQENT_FLAG_PREALLOC 0x1 /* taskq_dispatch_ent used */ 396 397#define TASKQ_PREPOPULATE 0x0001 398#define TASKQ_CPR_SAFE 0x0002 /* Use CPR safe protocol */ 399#define TASKQ_DYNAMIC 0x0004 /* Use dynamic thread scheduling */ 400#define TASKQ_THREADS_CPU_PCT 0x0008 /* Scale # threads by # cpus */ 401#define TASKQ_DC_BATCH 0x0010 /* Mark threads as batch */ 402 403#define TQ_SLEEP KM_SLEEP /* Can block for memory */ 404#define TQ_NOSLEEP KM_NOSLEEP /* cannot block for memory; may fail */ 405#define TQ_NOQUEUE 0x02 /* Do not enqueue if can't dispatch */ 406#define TQ_FRONT 0x08 /* Queue in front */ 407 408 409extern taskq_t *system_taskq; 410 411extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t); 412#define taskq_create_proc(a, b, c, d, e, p, f) \ 413 (taskq_create(a, b, c, d, e, f)) 414#define taskq_create_sysdc(a, b, d, e, p, dc, f) \ 415 (taskq_create(a, b, maxclsyspri, d, e, f)) 416extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t); 417extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t, 418 taskq_ent_t *); 419extern void taskq_destroy(taskq_t *); 420extern void taskq_wait(taskq_t *); 421extern int taskq_member(taskq_t *, void *); 422extern void system_taskq_init(void); 423extern void system_taskq_fini(void); 424 425#define taskq_dispatch_safe(tq, func, arg, flags, task) \ 426 taskq_dispatch((tq), (func), (arg), (flags)) 427 428#define XVA_MAPSIZE 3 429#define XVA_MAGIC 0x78766174 430 431/* 432 * vnodes 433 */ 434typedef struct vnode { 435 uint64_t v_size; 436 int v_fd; 437 char *v_path; 438 int v_dump_fd; 439} vnode_t; 440 441extern char *vn_dumpdir; 442#define AV_SCANSTAMP_SZ 32 /* length of anti-virus scanstamp */ 443 444typedef struct xoptattr { 445 timestruc_t xoa_createtime; /* Create time of file */ 446 uint8_t xoa_archive; 447 uint8_t xoa_system; 448 uint8_t xoa_readonly; 449 uint8_t xoa_hidden; 450 uint8_t xoa_nounlink; 451 uint8_t xoa_immutable; 452 uint8_t xoa_appendonly; 453 uint8_t xoa_nodump; 454 uint8_t xoa_settable; 455 uint8_t xoa_opaque; 456 uint8_t xoa_av_quarantined; 457 uint8_t xoa_av_modified; 458 uint8_t xoa_av_scanstamp[AV_SCANSTAMP_SZ]; 459 uint8_t xoa_reparse; 460 uint8_t xoa_offline; 461 uint8_t xoa_sparse; 462} xoptattr_t; 463 464typedef struct vattr { 465 uint_t va_mask; /* bit-mask of attributes */ 466 u_offset_t va_size; /* file size in bytes */ 467} vattr_t; 468 469 470typedef struct xvattr { 471 vattr_t xva_vattr; /* Embedded vattr structure */ 472 uint32_t xva_magic; /* Magic Number */ 473 uint32_t xva_mapsize; /* Size of attr bitmap (32-bit words) */ 474 uint32_t *xva_rtnattrmapp; /* Ptr to xva_rtnattrmap[] */ 475 uint32_t xva_reqattrmap[XVA_MAPSIZE]; /* Requested attrs */ 476 uint32_t xva_rtnattrmap[XVA_MAPSIZE]; /* Returned attrs */ 477 xoptattr_t xva_xoptattrs; /* Optional attributes */ 478} xvattr_t; 479 480typedef struct vsecattr { 481 uint_t vsa_mask; /* See below */ 482 int vsa_aclcnt; /* ACL entry count */ 483 void *vsa_aclentp; /* pointer to ACL entries */ 484 int vsa_dfaclcnt; /* default ACL entry count */ 485 void *vsa_dfaclentp; /* pointer to default ACL entries */ 486 size_t vsa_aclentsz; /* ACE size in bytes of vsa_aclentp */ 487} vsecattr_t; 488 489#define AT_TYPE 0x00001 490#define AT_MODE 0x00002 491#define AT_UID 0x00004 492#define AT_GID 0x00008 493#define AT_FSID 0x00010 494#define AT_NODEID 0x00020 495#define AT_NLINK 0x00040 496#define AT_SIZE 0x00080 497#define AT_ATIME 0x00100 498#define AT_MTIME 0x00200 499#define AT_CTIME 0x00400 500#define AT_RDEV 0x00800 501#define AT_BLKSIZE 0x01000 502#define AT_NBLOCKS 0x02000 503#define AT_SEQ 0x08000 504#define AT_XVATTR 0x10000 505 506#define CRCREAT 0 507 508extern int fop_getattr(vnode_t *vp, vattr_t *vap); 509 510#define VOP_CLOSE(vp, f, c, o, cr, ct) 0 511#define VOP_PUTPAGE(vp, of, sz, fl, cr, ct) 0 512#define VOP_GETATTR(vp, vap, cr) fop_getattr((vp), (vap)); 513 514#define VOP_FSYNC(vp, f, cr, ct) fsync((vp)->v_fd) 515 516#define VN_RELE(vp) vn_close(vp, 0, NULL, NULL) 517#define VN_RELE_ASYNC(vp, taskq) vn_close(vp, 0, NULL, NULL) 518 519#define vn_lock(vp, type) 520#define VOP_UNLOCK(vp, type) 521 522extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp, 523 int x2, int x3); 524extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp, 525 int x2, int x3, vnode_t *vp, int fd); 526extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, 527 offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp); 528extern void vn_close(vnode_t *vp, int openflag, cred_t *cr, kthread_t *td); 529 530#define vn_remove(path, x1, x2) remove(path) 531#define vn_rename(from, to, seg) rename((from), (to)) 532#define vn_is_readonly(vp) B_FALSE 533 534extern vnode_t *rootdir; 535 536#include <sys/file.h> /* for FREAD, FWRITE, etc */ 537#define FTRUNC O_TRUNC 538 539/* 540 * Random stuff 541 */ 542#define ddi_get_lbolt() (gethrtime() >> 23) 543#define ddi_get_lbolt64() (gethrtime() >> 23) 544#define hz 119 /* frequency when using gethrtime() >> 23 for lbolt */ 545 546extern void delay(clock_t ticks); 547 548#define SEC_TO_TICK(sec) ((sec) * hz) 549#define NSEC_TO_TICK(usec) ((usec) / (NANOSEC / hz)) 550 551#define gethrestime_sec() time(NULL) 552#define gethrestime(t) \ 553 do {\ 554 (t)->tv_sec = gethrestime_sec();\ 555 (t)->tv_nsec = 0;\ 556 } while (0); 557 558#define max_ncpus 64 559 560#define minclsyspri 60 561#define maxclsyspri 99 562 563#define CPU_SEQID (thr_self() & (max_ncpus - 1)) 564 565#define kcred NULL 566#define CRED() NULL 567 568#ifndef ptob 569#define ptob(x) ((x) * PAGESIZE) 570#endif 571 572extern uint64_t physmem; 573 574extern int highbit64(uint64_t i); 575extern int random_get_bytes(uint8_t *ptr, size_t len); 576extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len); 577 578extern void kernel_init(int); 579extern void kernel_fini(void); 580 581struct spa; 582extern void nicenum(uint64_t num, char *buf, size_t); 583extern void show_pool_stats(struct spa *); 584 585typedef struct callb_cpr { 586 kmutex_t *cc_lockp; 587} callb_cpr_t; 588 589#define CALLB_CPR_INIT(cp, lockp, func, name) { \ 590 (cp)->cc_lockp = lockp; \ 591} 592 593#define CALLB_CPR_SAFE_BEGIN(cp) { \ 594 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 595} 596 597#define CALLB_CPR_SAFE_END(cp, lockp) { \ 598 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 599} 600 601#define CALLB_CPR_EXIT(cp) { \ 602 ASSERT(MUTEX_HELD((cp)->cc_lockp)); \ 603 mutex_exit((cp)->cc_lockp); \ 604} 605 606#define zone_dataset_visible(x, y) (1) 607#define INGLOBALZONE(z) (1) 608 609extern char *kmem_asprintf(const char *fmt, ...); 610#define strfree(str) kmem_free((str), strlen(str) + 1) 611 612/* 613 * Hostname information 614 */ 615extern struct utsname utsname; 616extern char hw_serial[]; /* for userland-emulated hostid access */ 617extern int ddi_strtoul(const char *str, char **nptr, int base, 618 unsigned long *result); 619 620extern int ddi_strtoull(const char *str, char **nptr, int base, 621 u_longlong_t *result); 622 623/* ZFS Boot Related stuff. */ 624 625struct _buf { 626 intptr_t _fd; 627}; 628 629struct bootstat { 630 uint64_t st_size; 631}; 632 633typedef struct ace_object { 634 uid_t a_who; 635 uint32_t a_access_mask; 636 uint16_t a_flags; 637 uint16_t a_type; 638 uint8_t a_obj_type[16]; 639 uint8_t a_inherit_obj_type[16]; 640} ace_object_t; 641 642 643#define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE 0x05 644#define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE 0x06 645#define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE 0x07 646#define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE 0x08 647 648extern struct _buf *kobj_open_file(char *name); 649extern int kobj_read_file(struct _buf *file, char *buf, unsigned size, 650 unsigned off); 651extern void kobj_close_file(struct _buf *file); 652extern int kobj_get_filesize(struct _buf *file, uint64_t *size); 653extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr); 654extern int zfs_secpolicy_rename_perms(const char *from, const char *to, 655 cred_t *cr); 656extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr); 657extern zoneid_t getzoneid(void); 658/* Random compatibility stuff. */ 659#define pwrite64(d, p, n, o) pwrite(d, p, n, o) 660#define readdir64(d) readdir(d) 661#define SIGPENDING(td) (0) 662#define root_mount_wait() do { } while (0) 663#define root_mounted() (1) 664 665struct file { 666 void *dummy; 667}; 668 669#define FCREAT O_CREAT 670#define FOFFMAX 0x0 671 672/* SID stuff */ 673typedef struct ksiddomain { 674 uint_t kd_ref; 675 uint_t kd_len; 676 char *kd_name; 677} ksiddomain_t; 678 679ksiddomain_t *ksid_lookupdomain(const char *); 680void ksiddomain_rele(ksiddomain_t *); 681 682typedef uint32_t idmap_rid_t; 683 684#define DDI_SLEEP KM_SLEEP 685#define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) (0) 686 687#define SX_SYSINIT(name, lock, desc) 688 689#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, \ 690 intptr_t arg2, struct sysctl_req *req 691 692/* 693 * This describes the access space for a sysctl request. This is needed 694 * so that we can use the interface from the kernel or from user-space. 695 */ 696struct sysctl_req { 697 struct thread *td; /* used for access checking */ 698 int lock; /* wiring state */ 699 void *oldptr; 700 size_t oldlen; 701 size_t oldidx; 702 int (*oldfunc)(struct sysctl_req *, const void *, size_t); 703 void *newptr; 704 size_t newlen; 705 size_t newidx; 706 int (*newfunc)(struct sysctl_req *, void *, size_t); 707 size_t validlen; 708 int flags; 709}; 710 711SLIST_HEAD(sysctl_oid_list, sysctl_oid); 712 713/* 714 * This describes one "oid" in the MIB tree. Potentially more nodes can 715 * be hidden behind it, expanded by the handler. 716 */ 717struct sysctl_oid { 718 struct sysctl_oid_list *oid_parent; 719 SLIST_ENTRY(sysctl_oid) oid_link; 720 int oid_number; 721 u_int oid_kind; 722 void *oid_arg1; 723 intptr_t oid_arg2; 724 const char *oid_name; 725 int (*oid_handler)(SYSCTL_HANDLER_ARGS); 726 const char *oid_fmt; 727 int oid_refcnt; 728 u_int oid_running; 729 const char *oid_descr; 730}; 731 732#define SYSCTL_DECL(...) 733#define SYSCTL_NODE(...) 734#define SYSCTL_INT(...) 735#define SYSCTL_UINT(...) 736#define SYSCTL_ULONG(...) 737#define SYSCTL_PROC(...) 738#define SYSCTL_QUAD(...) 739#define SYSCTL_UQUAD(...) 740#ifdef TUNABLE_INT 741#undef TUNABLE_INT 742#undef TUNABLE_ULONG 743#undef TUNABLE_QUAD 744#endif 745#define TUNABLE_INT(...) 746#define TUNABLE_ULONG(...) 747#define TUNABLE_QUAD(...) 748 749int sysctl_handle_64(SYSCTL_HANDLER_ARGS); 750 751/* Errors */ 752 753#ifndef ERESTART 754#define ERESTART (-1) 755#endif 756 757#ifdef illumos 758/* 759 * Cyclic information 760 */ 761extern kmutex_t cpu_lock; 762 763typedef uintptr_t cyclic_id_t; 764typedef uint16_t cyc_level_t; 765typedef void (*cyc_func_t)(void *); 766 767#define CY_LOW_LEVEL 0 768#define CY_INFINITY INT64_MAX 769#define CYCLIC_NONE ((cyclic_id_t)0) 770 771typedef struct cyc_time { 772 hrtime_t cyt_when; 773 hrtime_t cyt_interval; 774} cyc_time_t; 775 776typedef struct cyc_handler { 777 cyc_func_t cyh_func; 778 void *cyh_arg; 779 cyc_level_t cyh_level; 780} cyc_handler_t; 781 782extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *); 783extern void cyclic_remove(cyclic_id_t); 784extern int cyclic_reprogram(cyclic_id_t, hrtime_t); 785#endif /* illumos */ 786 787#ifdef illumos 788/* 789 * Buf structure 790 */ 791#define B_BUSY 0x0001 792#define B_DONE 0x0002 793#define B_ERROR 0x0004 794#define B_READ 0x0040 /* read when I/O occurs */ 795#define B_WRITE 0x0100 /* non-read pseudo-flag */ 796 797typedef struct buf { 798 int b_flags; 799 size_t b_bcount; 800 union { 801 caddr_t b_addr; 802 } b_un; 803 804 lldaddr_t _b_blkno; 805#define b_lblkno _b_blkno._f 806 size_t b_resid; 807 size_t b_bufsize; 808 int (*b_iodone)(struct buf *); 809 int b_error; 810 void *b_private; 811} buf_t; 812 813extern void bioinit(buf_t *); 814extern void biodone(buf_t *); 815extern void bioerror(buf_t *, int); 816extern int geterror(buf_t *); 817#endif 818 819#ifdef __cplusplus 820} 821#endif 822 823#endif /* _SYS_ZFS_CONTEXT_H */ 824