Print this page
    
OS-6363 system went to dark side of moon for ~467 seconds OS-6404 ARC reclaim should throttle its calls to arc_kmem_reap_now() Reviewed by: Bryan Cantrill <bryan@joyent.com> Reviewed by: Dan McDonald <danmcd@joyent.com>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/lib/libzpool/common/sys/zfs_context.h
          +++ new/usr/src/lib/libzpool/common/sys/zfs_context.h
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  
    | 
      ↓ open down ↓ | 
    14 lines elided | 
    
      ↑ open up ↑ | 
  
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  24   24   * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  25      - * Copyright (c) 2012, Joyent, Inc. All rights reserved.
       25 + * Copyright (c) 2017, Joyent, Inc. All rights reserved.
  26   26   */
  27   27  
  28   28  #ifndef _SYS_ZFS_CONTEXT_H
  29   29  #define _SYS_ZFS_CONTEXT_H
  30   30  
  31   31  #ifdef  __cplusplus
  32   32  extern "C" {
  33   33  #endif
  34   34  
  35   35  #define _SYS_MUTEX_H
  36   36  #define _SYS_RWLOCK_H
  37   37  #define _SYS_CONDVAR_H
  38   38  #define _SYS_SYSTM_H
  39   39  #define _SYS_T_LOCK_H
  40   40  #define _SYS_VNODE_H
  41   41  #define _SYS_VFS_H
  42   42  #define _SYS_SUNDDI_H
  43   43  #define _SYS_CALLB_H
  44   44  
  45   45  #include <stdio.h>
  46   46  #include <stdlib.h>
  47   47  #include <stddef.h>
  48   48  #include <stdarg.h>
  49   49  #include <fcntl.h>
  50   50  #include <unistd.h>
  51   51  #include <errno.h>
  52   52  #include <string.h>
  53   53  #include <strings.h>
  54   54  #include <synch.h>
  55   55  #include <thread.h>
  56   56  #include <assert.h>
  57   57  #include <alloca.h>
  58   58  #include <umem.h>
  59   59  #include <limits.h>
  60   60  #include <atomic.h>
  61   61  #include <dirent.h>
  62   62  #include <time.h>
  63   63  #include <procfs.h>
  64   64  #include <pthread.h>
  65   65  #include <setjmp.h>
  66   66  #include <sys/debug.h>
  67   67  #include <libsysevent.h>
  68   68  #include <sys/note.h>
  69   69  #include <sys/types.h>
  70   70  #include <sys/cred.h>
  71   71  #include <sys/sysmacros.h>
  72   72  #include <sys/bitmap.h>
  73   73  #include <sys/resource.h>
  74   74  #include <sys/byteorder.h>
  75   75  #include <sys/list.h>
  76   76  #include <sys/uio.h>
  77   77  #include <sys/zfs_debug.h>
  78   78  #include <sys/sdt.h>
  79   79  #include <sys/kstat.h>
  80   80  #include <sys/u8_textprep.h>
  81   81  #include <sys/sysevent/eventdefs.h>
  82   82  #include <sys/sysevent/dev.h>
  83   83  #include <sys/sunddi.h>
  84   84  #include <sys/debug.h>
  85   85  #include "zfs.h"
  86   86  
  87   87  /*
  88   88   * Debugging
  89   89   */
  90   90  
  91   91  /*
  92   92   * Note that we are not using the debugging levels.
  93   93   */
  94   94  
  95   95  #define CE_CONT         0       /* continuation         */
  96   96  #define CE_NOTE         1       /* notice               */
  97   97  #define CE_WARN         2       /* warning              */
  98   98  #define CE_PANIC        3       /* panic                */
  99   99  #define CE_IGNORE       4       /* print nothing        */
 100  100  
 101  101  /*
 102  102   * ZFS debugging
 103  103   */
 104  104  
 105  105  #ifdef ZFS_DEBUG
 106  106  extern void dprintf_setup(int *argc, char **argv);
 107  107  #endif /* ZFS_DEBUG */
 108  108  
 109  109  extern void cmn_err(int, const char *, ...);
 110  110  extern void vcmn_err(int, const char *, __va_list);
 111  111  extern void panic(const char *, ...)  __NORETURN;
 112  112  extern void vpanic(const char *, __va_list)  __NORETURN;
 113  113  
 114  114  #define fm_panic        panic
 115  115  
 116  116  extern int aok;
 117  117  
 118  118  /*
 119  119   * DTrace SDT probes have different signatures in userland than they do in
 120  120   * the kernel.  If they're being used in kernel code, re-define them out of
 121  121   * existence for their counterparts in libzpool.
 122  122   *
 123  123   * Here's an example of how to use the set-error probes in userland:
 124  124   * zfs$target:::set-error /arg0 == EBUSY/ {stack();}
 125  125   *
 126  126   * Here's an example of how to use DTRACE_PROBE probes in userland:
 127  127   * If there is a probe declared as follows:
 128  128   * DTRACE_PROBE2(zfs__probe_name, uint64_t, blkid, dnode_t *, dn);
 129  129   * Then you can use it as follows:
 130  130   * zfs$target:::probe2 /copyinstr(arg0) == "zfs__probe_name"/
 131  131   *     {printf("%u %p\n", arg1, arg2);}
 132  132   */
 133  133  
 134  134  #ifdef DTRACE_PROBE
 135  135  #undef  DTRACE_PROBE
 136  136  #endif  /* DTRACE_PROBE */
 137  137  #define DTRACE_PROBE(a) \
 138  138          ZFS_PROBE0(#a)
 139  139  
 140  140  #ifdef DTRACE_PROBE1
 141  141  #undef  DTRACE_PROBE1
 142  142  #endif  /* DTRACE_PROBE1 */
 143  143  #define DTRACE_PROBE1(a, b, c) \
 144  144          ZFS_PROBE1(#a, (unsigned long)c)
 145  145  
 146  146  #ifdef DTRACE_PROBE2
 147  147  #undef  DTRACE_PROBE2
 148  148  #endif  /* DTRACE_PROBE2 */
 149  149  #define DTRACE_PROBE2(a, b, c, d, e) \
 150  150          ZFS_PROBE2(#a, (unsigned long)c, (unsigned long)e)
 151  151  
 152  152  #ifdef DTRACE_PROBE3
 153  153  #undef  DTRACE_PROBE3
 154  154  #endif  /* DTRACE_PROBE3 */
 155  155  #define DTRACE_PROBE3(a, b, c, d, e, f, g) \
 156  156          ZFS_PROBE3(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g)
 157  157  
 158  158  #ifdef DTRACE_PROBE4
 159  159  #undef  DTRACE_PROBE4
 160  160  #endif  /* DTRACE_PROBE4 */
 161  161  #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) \
 162  162          ZFS_PROBE4(#a, (unsigned long)c, (unsigned long)e, (unsigned long)g, \
 163  163          (unsigned long)i)
 164  164  
 165  165  /*
 166  166   * We use the comma operator so that this macro can be used without much
 167  167   * additional code.  For example, "return (EINVAL);" becomes
 168  168   * "return (SET_ERROR(EINVAL));".  Note that the argument will be evaluated
 169  169   * twice, so it should not have side effects (e.g. something like:
 170  170   * "return (SET_ERROR(log_error(EINVAL, info)));" would log the error twice).
 171  171   */
 172  172  #define SET_ERROR(err) (ZFS_SET_ERROR(err), err)
 173  173  
 174  174  /*
 175  175   * Threads
 176  176   */
 177  177  #define curthread       ((void *)(uintptr_t)thr_self())
 178  178  
 179  179  #define kpreempt(x)     yield()
 180  180  
 181  181  typedef struct kthread kthread_t;
 182  182  
 183  183  #define thread_create(stk, stksize, func, arg, len, pp, state, pri)     \
 184  184          zk_thread_create(func, arg, len)
 185  185  #define thread_exit() thr_exit(NULL)
 186  186  #define thread_join(t)  panic("libzpool cannot join threads")
 187  187  
 188  188  #define newproc(f, a, cid, pri, ctp, pid)       (ENOSYS)
 189  189  
 190  190  /* in libzpool, p0 exists only to have its address taken */
 191  191  struct proc {
 192  192          uintptr_t       this_is_never_used_dont_dereference_it;
 193  193  };
 194  194  
 195  195  extern struct proc p0;
 196  196  #define curproc         (&p0)
 197  197  
 198  198  #define PS_NONE         -1
 199  199  
 200  200  extern kthread_t *zk_thread_create(void (*func)(void*), void *arg,
 201  201      uint64_t len);
 202  202  
 203  203  #define issig(why)      (FALSE)
 204  204  #define ISSIG(thr, why) (FALSE)
 205  205  
 206  206  /*
 207  207   * Mutexes
 208  208   */
 209  209  typedef struct kmutex {
 210  210          void            *m_owner;
 211  211          boolean_t       initialized;
 212  212          mutex_t         m_lock;
 213  213  } kmutex_t;
 214  214  
 215  215  #define MUTEX_DEFAULT   USYNC_THREAD
 216  216  #undef  MUTEX_HELD
 217  217  #undef  MUTEX_NOT_HELD
 218  218  #define MUTEX_HELD(m) _mutex_held(&(m)->m_lock)
 219  219  #define MUTEX_NOT_HELD(m) (!MUTEX_HELD(m))
 220  220  
 221  221  /*
 222  222   * Argh -- we have to get cheesy here because the kernel and userland
 223  223   * have different signatures for the same routine.
 224  224   */
 225  225  extern int _mutex_init(mutex_t *mp, int type, void *arg);
 226  226  extern int _mutex_destroy(mutex_t *mp);
 227  227  
 228  228  #define mutex_init(mp, b, c, d)         zmutex_init((kmutex_t *)(mp))
 229  229  #define mutex_destroy(mp)               zmutex_destroy((kmutex_t *)(mp))
 230  230  #define mutex_enter(mp)                 zmutex_enter(mp)
 231  231  #define mutex_exit(mp)                  zmutex_exit(mp)
 232  232  
 233  233  extern void zmutex_init(kmutex_t *mp);
 234  234  extern void zmutex_destroy(kmutex_t *mp);
 235  235  extern void zmutex_enter(kmutex_t *mp);
 236  236  extern void zmutex_exit(kmutex_t *mp);
 237  237  extern int mutex_tryenter(kmutex_t *mp);
 238  238  extern void *mutex_owner(kmutex_t *mp);
 239  239  
 240  240  /*
 241  241   * RW locks
 242  242   */
 243  243  typedef struct krwlock {
 244  244          void            *rw_owner;
 245  245          boolean_t       initialized;
 246  246          rwlock_t        rw_lock;
 247  247  } krwlock_t;
 248  248  
 249  249  typedef int krw_t;
 250  250  
 251  251  #define RW_READER       0
 252  252  #define RW_WRITER       1
 253  253  #define RW_DEFAULT      USYNC_THREAD
 254  254  
 255  255  #undef RW_READ_HELD
 256  256  #define RW_READ_HELD(x)         _rw_read_held(&(x)->rw_lock)
 257  257  
 258  258  #undef RW_WRITE_HELD
 259  259  #define RW_WRITE_HELD(x)        _rw_write_held(&(x)->rw_lock)
 260  260  
 261  261  #undef RW_LOCK_HELD
 262  262  #define RW_LOCK_HELD(x)         (RW_READ_HELD(x) || RW_WRITE_HELD(x))
 263  263  
 264  264  extern void rw_init(krwlock_t *rwlp, char *name, int type, void *arg);
 265  265  extern void rw_destroy(krwlock_t *rwlp);
 266  266  extern void rw_enter(krwlock_t *rwlp, krw_t rw);
 267  267  extern int rw_tryenter(krwlock_t *rwlp, krw_t rw);
 268  268  extern int rw_tryupgrade(krwlock_t *rwlp);
 269  269  extern void rw_exit(krwlock_t *rwlp);
 270  270  #define rw_downgrade(rwlp) do { } while (0)
 271  271  
 272  272  extern uid_t crgetuid(cred_t *cr);
 273  273  extern uid_t crgetruid(cred_t *cr);
 274  274  extern gid_t crgetgid(cred_t *cr);
 275  275  extern int crgetngroups(cred_t *cr);
 276  276  extern gid_t *crgetgroups(cred_t *cr);
 277  277  
 278  278  /*
 279  279   * Condition variables
 280  280   */
 281  281  typedef cond_t kcondvar_t;
 282  282  
 283  283  #define CV_DEFAULT      USYNC_THREAD
 284  284  #define CALLOUT_FLAG_ABSOLUTE   0x2
 285  285  
 286  286  extern void cv_init(kcondvar_t *cv, char *name, int type, void *arg);
 287  287  extern void cv_destroy(kcondvar_t *cv);
 288  288  extern void cv_wait(kcondvar_t *cv, kmutex_t *mp);
 289  289  extern clock_t cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime);
 290  290  extern clock_t cv_timedwait_hires(kcondvar_t *cvp, kmutex_t *mp, hrtime_t tim,
 291  291      hrtime_t res, int flag);
 292  292  extern void cv_signal(kcondvar_t *cv);
 293  293  extern void cv_broadcast(kcondvar_t *cv);
 294  294  
 295  295  /*
 296  296   * Thread-specific data
 297  297   */
 298  298  #define tsd_get(k) pthread_getspecific(k)
 299  299  #define tsd_set(k, v) pthread_setspecific(k, v)
 300  300  #define tsd_create(kp, d) pthread_key_create(kp, d)
 301  301  #define tsd_destroy(kp) /* nothing */
 302  302  
 303  303  /*
 304  304   * kstat creation, installation and deletion
 305  305   */
 306  306  extern kstat_t *kstat_create(const char *, int,
 307  307      const char *, const char *, uchar_t, ulong_t, uchar_t);
 308  308  extern void kstat_named_init(kstat_named_t *, const char *, uchar_t);
 309  309  extern void kstat_install(kstat_t *);
 310  310  extern void kstat_delete(kstat_t *);
 311  311  extern void kstat_waitq_enter(kstat_io_t *);
 312  312  extern void kstat_waitq_exit(kstat_io_t *);
 313  313  extern void kstat_runq_enter(kstat_io_t *);
 314  314  extern void kstat_runq_exit(kstat_io_t *);
 315  315  extern void kstat_waitq_to_runq(kstat_io_t *);
 316  316  extern void kstat_runq_back_to_waitq(kstat_io_t *);
 317  317  
 318  318  /*
 319  319   * Kernel memory
 320  320   */
 321  321  #define KM_SLEEP                UMEM_NOFAIL
 322  322  #define KM_PUSHPAGE             KM_SLEEP
 323  323  #define KM_NOSLEEP              UMEM_DEFAULT
 324  324  #define KM_NORMALPRI            0       /* not needed with UMEM_DEFAULT */
 325  325  #define KMC_NODEBUG             UMC_NODEBUG
  
    | 
      ↓ open down ↓ | 
    290 lines elided | 
    
      ↑ open up ↑ | 
  
 326  326  #define KMC_NOTOUCH             0       /* not needed for userland caches */
 327  327  #define kmem_alloc(_s, _f)      umem_alloc(_s, _f)
 328  328  #define kmem_zalloc(_s, _f)     umem_zalloc(_s, _f)
 329  329  #define kmem_free(_b, _s)       umem_free(_b, _s)
 330  330  #define kmem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i) \
 331  331          umem_cache_create(_a, _b, _c, _d, _e, _f, _g, _h, _i)
 332  332  #define kmem_cache_destroy(_c)  umem_cache_destroy(_c)
 333  333  #define kmem_cache_alloc(_c, _f) umem_cache_alloc(_c, _f)
 334  334  #define kmem_cache_free(_c, _b) umem_cache_free(_c, _b)
 335  335  #define kmem_debugging()        0
 336      -#define kmem_cache_reap_now(_c)         /* nothing */
      336 +#define kmem_cache_reap_active()        (B_FALSE)
      337 +#define kmem_cache_reap_soon(_c)        /* nothing */
 337  338  #define kmem_cache_set_move(_c, _cb)    /* nothing */
 338  339  #define vmem_qcache_reap(_v)            /* nothing */
 339  340  #define POINTER_INVALIDATE(_pp)         /* nothing */
 340  341  #define POINTER_IS_VALID(_p)    0
 341  342  
 342  343  extern vmem_t *zio_arena;
 343  344  
 344  345  typedef umem_cache_t kmem_cache_t;
 345  346  
 346  347  typedef enum kmem_cbrc {
 347  348          KMEM_CBRC_YES,
 348  349          KMEM_CBRC_NO,
 349  350          KMEM_CBRC_LATER,
 350  351          KMEM_CBRC_DONT_NEED,
 351  352          KMEM_CBRC_DONT_KNOW
 352  353  } kmem_cbrc_t;
 353  354  
 354  355  /*
 355  356   * Task queues
 356  357   */
 357  358  typedef struct taskq taskq_t;
 358  359  typedef uintptr_t taskqid_t;
 359  360  typedef void (task_func_t)(void *);
 360  361  
 361  362  typedef struct taskq_ent {
 362  363          struct taskq_ent        *tqent_next;
 363  364          struct taskq_ent        *tqent_prev;
 364  365          task_func_t             *tqent_func;
 365  366          void                    *tqent_arg;
 366  367          uintptr_t               tqent_flags;
 367  368  } taskq_ent_t;
 368  369  
 369  370  #define TQENT_FLAG_PREALLOC     0x1     /* taskq_dispatch_ent used */
 370  371  
 371  372  #define TASKQ_PREPOPULATE       0x0001
 372  373  #define TASKQ_CPR_SAFE          0x0002  /* Use CPR safe protocol */
 373  374  #define TASKQ_DYNAMIC           0x0004  /* Use dynamic thread scheduling */
 374  375  #define TASKQ_THREADS_CPU_PCT   0x0008  /* Scale # threads by # cpus */
 375  376  #define TASKQ_DC_BATCH          0x0010  /* Mark threads as batch */
 376  377  
 377  378  #define TQ_SLEEP        KM_SLEEP        /* Can block for memory */
 378  379  #define TQ_NOSLEEP      KM_NOSLEEP      /* cannot block for memory; may fail */
 379  380  #define TQ_NOQUEUE      0x02            /* Do not enqueue if can't dispatch */
 380  381  #define TQ_FRONT        0x08            /* Queue in front */
 381  382  
 382  383  
 383  384  extern taskq_t *system_taskq;
  
    | 
      ↓ open down ↓ | 
    37 lines elided | 
    
      ↑ open up ↑ | 
  
 384  385  
 385  386  extern taskq_t  *taskq_create(const char *, int, pri_t, int, int, uint_t);
 386  387  #define taskq_create_proc(a, b, c, d, e, p, f) \
 387  388              (taskq_create(a, b, c, d, e, f))
 388  389  #define taskq_create_sysdc(a, b, d, e, p, dc, f) \
 389  390              (taskq_create(a, b, maxclsyspri, d, e, f))
 390  391  extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
 391  392  extern void     taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
 392  393      taskq_ent_t *);
 393  394  extern void     taskq_destroy(taskq_t *);
      395 +extern boolean_t taskq_empty(taskq_t *);
 394  396  extern void     taskq_wait(taskq_t *);
 395  397  extern int      taskq_member(taskq_t *, void *);
 396  398  extern void     system_taskq_init(void);
 397  399  extern void     system_taskq_fini(void);
 398  400  
 399  401  #define XVA_MAPSIZE     3
 400  402  #define XVA_MAGIC       0x78766174
 401  403  
 402  404  /*
 403  405   * vnodes
 404  406   */
 405  407  typedef struct vnode {
 406  408          uint64_t        v_size;
 407  409          int             v_fd;
 408  410          char            *v_path;
 409  411          int             v_dump_fd;
 410  412  } vnode_t;
 411  413  
 412  414  extern char *vn_dumpdir;
 413  415  #define AV_SCANSTAMP_SZ 32              /* length of anti-virus scanstamp */
 414  416  
 415  417  typedef struct xoptattr {
 416  418          timestruc_t     xoa_createtime; /* Create time of file */
 417  419          uint8_t         xoa_archive;
 418  420          uint8_t         xoa_system;
 419  421          uint8_t         xoa_readonly;
 420  422          uint8_t         xoa_hidden;
 421  423          uint8_t         xoa_nounlink;
 422  424          uint8_t         xoa_immutable;
 423  425          uint8_t         xoa_appendonly;
 424  426          uint8_t         xoa_nodump;
 425  427          uint8_t         xoa_settable;
 426  428          uint8_t         xoa_opaque;
 427  429          uint8_t         xoa_av_quarantined;
 428  430          uint8_t         xoa_av_modified;
 429  431          uint8_t         xoa_av_scanstamp[AV_SCANSTAMP_SZ];
 430  432          uint8_t         xoa_reparse;
 431  433          uint8_t         xoa_offline;
 432  434          uint8_t         xoa_sparse;
 433  435  } xoptattr_t;
 434  436  
 435  437  typedef struct vattr {
 436  438          uint_t          va_mask;        /* bit-mask of attributes */
 437  439          u_offset_t      va_size;        /* file size in bytes */
 438  440  } vattr_t;
 439  441  
 440  442  
 441  443  typedef struct xvattr {
 442  444          vattr_t         xva_vattr;      /* Embedded vattr structure */
 443  445          uint32_t        xva_magic;      /* Magic Number */
 444  446          uint32_t        xva_mapsize;    /* Size of attr bitmap (32-bit words) */
 445  447          uint32_t        *xva_rtnattrmapp;       /* Ptr to xva_rtnattrmap[] */
 446  448          uint32_t        xva_reqattrmap[XVA_MAPSIZE];    /* Requested attrs */
 447  449          uint32_t        xva_rtnattrmap[XVA_MAPSIZE];    /* Returned attrs */
 448  450          xoptattr_t      xva_xoptattrs;  /* Optional attributes */
 449  451  } xvattr_t;
 450  452  
 451  453  typedef struct vsecattr {
 452  454          uint_t          vsa_mask;       /* See below */
 453  455          int             vsa_aclcnt;     /* ACL entry count */
 454  456          void            *vsa_aclentp;   /* pointer to ACL entries */
 455  457          int             vsa_dfaclcnt;   /* default ACL entry count */
 456  458          void            *vsa_dfaclentp; /* pointer to default ACL entries */
 457  459          size_t          vsa_aclentsz;   /* ACE size in bytes of vsa_aclentp */
 458  460  } vsecattr_t;
 459  461  
 460  462  #define AT_TYPE         0x00001
 461  463  #define AT_MODE         0x00002
 462  464  #define AT_UID          0x00004
 463  465  #define AT_GID          0x00008
 464  466  #define AT_FSID         0x00010
 465  467  #define AT_NODEID       0x00020
 466  468  #define AT_NLINK        0x00040
 467  469  #define AT_SIZE         0x00080
 468  470  #define AT_ATIME        0x00100
 469  471  #define AT_MTIME        0x00200
 470  472  #define AT_CTIME        0x00400
 471  473  #define AT_RDEV         0x00800
 472  474  #define AT_BLKSIZE      0x01000
 473  475  #define AT_NBLOCKS      0x02000
 474  476  #define AT_SEQ          0x08000
 475  477  #define AT_XVATTR       0x10000
 476  478  
 477  479  #define CRCREAT         0
 478  480  
 479  481  extern int fop_getattr(vnode_t *vp, vattr_t *vap);
 480  482  
 481  483  #define VOP_CLOSE(vp, f, c, o, cr, ct)  0
 482  484  #define VOP_PUTPAGE(vp, of, sz, fl, cr, ct)     0
 483  485  #define VOP_GETATTR(vp, vap, fl, cr, ct)  fop_getattr((vp), (vap));
 484  486  
 485  487  #define VOP_FSYNC(vp, f, cr, ct)        fsync((vp)->v_fd)
 486  488  
 487  489  #define VN_RELE(vp)     vn_close(vp)
 488  490  
 489  491  extern int vn_open(char *path, int x1, int oflags, int mode, vnode_t **vpp,
 490  492      int x2, int x3);
 491  493  extern int vn_openat(char *path, int x1, int oflags, int mode, vnode_t **vpp,
 492  494      int x2, int x3, vnode_t *vp, int fd);
 493  495  extern int vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len,
 494  496      offset_t offset, int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp);
 495  497  extern void vn_close(vnode_t *vp);
 496  498  
 497  499  #define vn_remove(path, x1, x2)         remove(path)
 498  500  #define vn_rename(from, to, seg)        rename((from), (to))
 499  501  #define vn_is_readonly(vp)              B_FALSE
 500  502  
 501  503  extern vnode_t *rootdir;
 502  504  
 503  505  #include <sys/file.h>           /* for FREAD, FWRITE, etc */
 504  506  
 505  507  /*
 506  508   * Random stuff
 507  509   */
 508  510  #define ddi_get_lbolt()         (gethrtime() >> 23)
 509  511  #define ddi_get_lbolt64()       (gethrtime() >> 23)
 510  512  #define hz      119     /* frequency when using gethrtime() >> 23 for lbolt */
 511  513  
 512  514  extern void delay(clock_t ticks);
 513  515  
 514  516  #define SEC_TO_TICK(sec)        ((sec) * hz)
 515  517  #define NSEC_TO_TICK(usec)      ((usec) / (NANOSEC / hz))
 516  518  
 517  519  #define gethrestime_sec() time(NULL)
 518  520  #define gethrestime(t) \
 519  521          do {\
 520  522                  (t)->tv_sec = gethrestime_sec();\
 521  523                  (t)->tv_nsec = 0;\
 522  524          } while (0);
 523  525  
 524  526  #define max_ncpus       64
 525  527  #define boot_ncpus      (sysconf(_SC_NPROCESSORS_ONLN))
 526  528  
 527  529  #define minclsyspri     60
 528  530  #define maxclsyspri     99
 529  531  
 530  532  #define CPU_SEQID       (thr_self() & (max_ncpus - 1))
 531  533  
 532  534  #define kcred           NULL
 533  535  #define CRED()          NULL
 534  536  
 535  537  #define ptob(x)         ((x) * PAGESIZE)
 536  538  
 537  539  extern uint64_t physmem;
 538  540  
 539  541  extern int highbit64(uint64_t i);
 540  542  extern int random_get_bytes(uint8_t *ptr, size_t len);
 541  543  extern int random_get_pseudo_bytes(uint8_t *ptr, size_t len);
 542  544  
 543  545  extern void kernel_init(int);
 544  546  extern void kernel_fini(void);
 545  547  
 546  548  struct spa;
 547  549  extern void nicenum(uint64_t num, char *buf, size_t);
 548  550  extern void show_pool_stats(struct spa *);
 549  551  extern int set_global_var(char *arg);
 550  552  
 551  553  typedef struct callb_cpr {
 552  554          kmutex_t        *cc_lockp;
 553  555  } callb_cpr_t;
 554  556  
 555  557  #define CALLB_CPR_INIT(cp, lockp, func, name)   {               \
 556  558          (cp)->cc_lockp = lockp;                                 \
 557  559  }
 558  560  
 559  561  #define CALLB_CPR_SAFE_BEGIN(cp) {                              \
 560  562          ASSERT(MUTEX_HELD((cp)->cc_lockp));                     \
 561  563  }
 562  564  
 563  565  #define CALLB_CPR_SAFE_END(cp, lockp) {                         \
 564  566          ASSERT(MUTEX_HELD((cp)->cc_lockp));                     \
 565  567  }
 566  568  
 567  569  #define CALLB_CPR_EXIT(cp) {                                    \
 568  570          ASSERT(MUTEX_HELD((cp)->cc_lockp));                     \
 569  571          mutex_exit((cp)->cc_lockp);                             \
 570  572  }
 571  573  
 572  574  #define zone_dataset_visible(x, y)      (1)
 573  575  #define INGLOBALZONE(z)                 (1)
 574  576  
 575  577  extern char *kmem_asprintf(const char *fmt, ...);
 576  578  #define strfree(str) kmem_free((str), strlen(str) + 1)
 577  579  
 578  580  /*
 579  581   * Hostname information
 580  582   */
 581  583  extern char hw_serial[];        /* for userland-emulated hostid access */
 582  584  extern int ddi_strtoul(const char *str, char **nptr, int base,
 583  585      unsigned long *result);
 584  586  
 585  587  extern int ddi_strtoull(const char *str, char **nptr, int base,
 586  588      u_longlong_t *result);
 587  589  
 588  590  /* ZFS Boot Related stuff. */
 589  591  
 590  592  struct _buf {
 591  593          intptr_t        _fd;
 592  594  };
 593  595  
 594  596  struct bootstat {
 595  597          uint64_t st_size;
 596  598  };
 597  599  
 598  600  typedef struct ace_object {
 599  601          uid_t           a_who;
 600  602          uint32_t        a_access_mask;
 601  603          uint16_t        a_flags;
 602  604          uint16_t        a_type;
 603  605          uint8_t         a_obj_type[16];
 604  606          uint8_t         a_inherit_obj_type[16];
 605  607  } ace_object_t;
 606  608  
 607  609  
 608  610  #define ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE      0x05
 609  611  #define ACE_ACCESS_DENIED_OBJECT_ACE_TYPE       0x06
 610  612  #define ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE        0x07
 611  613  #define ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE        0x08
 612  614  
 613  615  extern struct _buf *kobj_open_file(char *name);
 614  616  extern int kobj_read_file(struct _buf *file, char *buf, unsigned size,
 615  617      unsigned off);
 616  618  extern void kobj_close_file(struct _buf *file);
 617  619  extern int kobj_get_filesize(struct _buf *file, uint64_t *size);
 618  620  extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
 619  621  extern int zfs_secpolicy_rename_perms(const char *from, const char *to,
 620  622      cred_t *cr);
 621  623  extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
 622  624  extern zoneid_t getzoneid(void);
 623  625  
 624  626  /* SID stuff */
 625  627  typedef struct ksiddomain {
 626  628          uint_t  kd_ref;
 627  629          uint_t  kd_len;
 628  630          char    *kd_name;
 629  631  } ksiddomain_t;
 630  632  
 631  633  ksiddomain_t *ksid_lookupdomain(const char *);
 632  634  void ksiddomain_rele(ksiddomain_t *);
 633  635  
 634  636  #define DDI_SLEEP       KM_SLEEP
 635  637  #define ddi_log_sysevent(_a, _b, _c, _d, _e, _f, _g) \
 636  638          sysevent_post_event(_c, _d, _b, "libzpool", _e, _f)
 637  639  
 638  640  /*
 639  641   * Cyclic information
 640  642   */
 641  643  extern kmutex_t cpu_lock;
 642  644  
 643  645  typedef uintptr_t cyclic_id_t;
 644  646  typedef uint16_t cyc_level_t;
 645  647  typedef void (*cyc_func_t)(void *);
 646  648  
 647  649  #define CY_LOW_LEVEL    0
 648  650  #define CY_INFINITY     INT64_MAX
 649  651  #define CYCLIC_NONE     ((cyclic_id_t)0)
 650  652  
 651  653  typedef struct cyc_time {
 652  654          hrtime_t cyt_when;
 653  655          hrtime_t cyt_interval;
 654  656  } cyc_time_t;
 655  657  
 656  658  typedef struct cyc_handler {
 657  659          cyc_func_t cyh_func;
 658  660          void *cyh_arg;
 659  661          cyc_level_t cyh_level;
 660  662  } cyc_handler_t;
 661  663  
 662  664  extern cyclic_id_t cyclic_add(cyc_handler_t *, cyc_time_t *);
 663  665  extern void cyclic_remove(cyclic_id_t);
 664  666  extern int cyclic_reprogram(cyclic_id_t, hrtime_t);
 665  667  
 666  668  /*
 667  669   * Buf structure
 668  670   */
 669  671  #define B_BUSY          0x0001
 670  672  #define B_DONE          0x0002
 671  673  #define B_ERROR         0x0004
 672  674  #define B_READ          0x0040  /* read when I/O occurs */
 673  675  #define B_WRITE         0x0100  /* non-read pseudo-flag */
 674  676  
 675  677  typedef struct buf {
 676  678          int     b_flags;
 677  679          size_t b_bcount;
 678  680          union {
 679  681                  caddr_t b_addr;
 680  682          } b_un;
 681  683  
 682  684          lldaddr_t       _b_blkno;
 683  685  #define b_lblkno        _b_blkno._f
 684  686          size_t  b_resid;
 685  687          size_t  b_bufsize;
 686  688          int     (*b_iodone)(struct buf *);
 687  689          int     b_error;
 688  690          void    *b_private;
 689  691  } buf_t;
 690  692  
 691  693  extern void bioinit(buf_t *);
 692  694  extern void biodone(buf_t *);
 693  695  extern void bioerror(buf_t *, int);
 694  696  extern int geterror(buf_t *);
 695  697  
 696  698  #ifdef  __cplusplus
 697  699  }
 698  700  #endif
 699  701  
 700  702  #endif  /* _SYS_ZFS_CONTEXT_H */
  
    | 
      ↓ open down ↓ | 
    297 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX