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) 2013 by Saso Kiselkov. All rights reserved.
  25  */
  26 
  27 #ifndef _SYS_ARC_H
  28 #define _SYS_ARC_H
  29 
  30 #include <sys/zfs_context.h>
  31 
  32 #ifdef  __cplusplus
  33 extern "C" {
  34 #endif
  35 
  36 #include <sys/zio.h>
  37 #include <sys/dmu.h>
  38 #include <sys/spa.h>
  39 
  40 typedef struct arc_buf_hdr arc_buf_hdr_t;
  41 typedef struct arc_buf arc_buf_t;
  42 typedef void arc_done_func_t(zio_t *zio, arc_buf_t *buf, void *private);
  43 typedef int arc_evict_func_t(void *private);
  44 
  45 /* generic arc_done_func_t's which you can use */
  46 arc_done_func_t arc_bcopy_func;
  47 arc_done_func_t arc_getbuf_func;
  48 
  49 struct arc_buf {
  50         arc_buf_hdr_t           *b_hdr;
  51         arc_buf_t               *b_next;
  52         kmutex_t                b_evict_lock;
  53         void                    *b_data;
  54         arc_evict_func_t        *b_efunc;
  55         void                    *b_private;
  56 };
  57 
  58 typedef enum arc_buf_contents {
  59         ARC_BUFC_DATA,                          /* buffer contains data */
  60         ARC_BUFC_METADATA,                      /* buffer contains metadata */
  61         ARC_BUFC_NUMTYPES
  62 } arc_buf_contents_t;
  63 /*
  64  * These are the flags we pass into calls to the arc
  65  */
  66 #define ARC_WAIT        (1 << 1)  /* perform I/O synchronously */
  67 #define ARC_NOWAIT      (1 << 2)  /* perform I/O asynchronously */
  68 #define ARC_PREFETCH    (1 << 3)  /* I/O is a prefetch */
  69 #define ARC_CACHED      (1 << 4)  /* I/O was already in cache */
  70 #define ARC_L2CACHE     (1 << 5)  /* cache in L2ARC */
  71 #define ARC_L2COMPRESS  (1 << 6)  /* compress in L2ARC */
  72 
  73 /*
  74  * The following breakdows of arc_size exist for kstat only.
  75  */
  76 typedef enum arc_space_type {
  77         ARC_SPACE_DATA,
  78         ARC_SPACE_HDRS,
  79         ARC_SPACE_L2HDRS,
  80         ARC_SPACE_OTHER,
  81         ARC_SPACE_NUMTYPES
  82 } arc_space_type_t;
  83 
  84 void arc_space_consume(uint64_t space, arc_space_type_t type);
  85 void arc_space_return(uint64_t space, arc_space_type_t type);
  86 arc_buf_t *arc_buf_alloc(spa_t *spa, int size, void *tag,
  87     arc_buf_contents_t type);
  88 arc_buf_t *arc_loan_buf(spa_t *spa, int size);
  89 void arc_return_buf(arc_buf_t *buf, void *tag);
  90 void arc_loan_inuse_buf(arc_buf_t *buf, void *tag);
  91 void arc_buf_add_ref(arc_buf_t *buf, void *tag);
  92 boolean_t arc_buf_remove_ref(arc_buf_t *buf, void *tag);
  93 int arc_buf_size(arc_buf_t *buf);
  94 void arc_release(arc_buf_t *buf, void *tag);
  95 int arc_released(arc_buf_t *buf);
  96 void arc_buf_freeze(arc_buf_t *buf);
  97 void arc_buf_thaw(arc_buf_t *buf);
  98 boolean_t arc_buf_eviction_needed(arc_buf_t *buf);
  99 #ifdef ZFS_DEBUG
 100 int arc_referenced(arc_buf_t *buf);
 101 #endif
 102 
 103 int arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
 104     arc_done_func_t *done, void *private, zio_priority_t priority, int flags,
 105     uint32_t *arc_flags, const zbookmark_phys_t *zb);
 106 zio_t *arc_write(zio_t *pio, spa_t *spa, uint64_t txg,
 107     blkptr_t *bp, arc_buf_t *buf, boolean_t l2arc, boolean_t l2arc_compress,
 108     const zio_prop_t *zp, arc_done_func_t *ready, arc_done_func_t *physdone,
 109     arc_done_func_t *done, void *private, zio_priority_t priority,
 110     int zio_flags, const zbookmark_phys_t *zb);
 111 void arc_freed(spa_t *spa, const blkptr_t *bp);
 112 
 113 void arc_set_callback(arc_buf_t *buf, arc_evict_func_t *func, void *private);
 114 boolean_t arc_clear_callback(arc_buf_t *buf);
 115 
 116 void arc_flush(spa_t *spa);
 117 void arc_tempreserve_clear(uint64_t reserve);
 118 int arc_tempreserve_space(uint64_t reserve, uint64_t txg);
 119 
 120 void arc_init(void);
 121 void arc_fini(void);
 122 
 123 /*
 124  * Level 2 ARC
 125  */
 126 
 127 void l2arc_add_vdev(spa_t *spa, vdev_t *vd);
 128 void l2arc_remove_vdev(vdev_t *vd);
 129 boolean_t l2arc_vdev_present(vdev_t *vd);
 130 void l2arc_init(void);
 131 void l2arc_fini(void);
 132 void l2arc_start(void);
 133 void l2arc_stop(void);
 134 
 135 #ifndef _KERNEL
 136 extern boolean_t arc_watch;
 137 extern int arc_procfd;
 138 #endif
 139 
 140 #ifdef  __cplusplus
 141 }
 142 #endif
 143 
 144 #endif /* _SYS_ARC_H */