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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  28  * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
  29  */
  30 
  31 #ifndef _ZIO_IMPL_H
  32 #define _ZIO_IMPL_H
  33 
  34 #include <sys/zfs_context.h>
  35 #include <sys/zio.h>
  36 
  37 #ifdef  __cplusplus
  38 extern "C" {
  39 #endif
  40 
  41 /*
  42  * XXX -- Describe ZFS I/O pipeline here. Fill in as needed.
  43  *
  44  * The ZFS I/O pipeline is comprised of various stages which are defined
  45  * in the zio_stage enum below. The individual stages are used to construct
  46  * these basic I/O operations: Read, Write, Free, Claim, and Ioctl.
  47  *
  48  * I/O operations: (XXX - provide detail for each of the operations)
  49  *
  50  * Read:
  51  * Write:
  52  * Free:
  53  * Claim:
  54  * Ioctl:
  55  *
  56  * Although the most common pipeline are used by the basic I/O operations
  57  * above, there are some helper pipelines (one could consider them
  58  * sub-pipelines) which are used internally by the ZIO module and are
  59  * explained below:
  60  *
  61  * Interlock Pipeline:
  62  * The interlock pipeline is the most basic pipeline and is used by all
  63  * of the I/O operations. The interlock pipeline does not perform any I/O
  64  * and is used to coordinate the dependencies between I/Os that are being
  65  * issued (i.e. the parent/child relationship).
  66  *
  67  * Vdev child Pipeline:
  68  * The vdev child pipeline is responsible for performing the physical I/O.
  69  * It is in this pipeline where the I/O are queued and possibly cached.
  70  *
  71  * In addition to performing I/O, the pipeline is also responsible for
  72  * data transformations. The transformations performed are based on the
  73  * specific properties that user may have selected and modify the
  74  * behavior of the pipeline. Examples of supported transformations are
  75  * compression, dedup, and nop writes. Transformations will either modify
  76  * the data or the pipeline. This list below further describes each of
  77  * the supported transformations:
  78  *
  79  * Compression:
  80  * ZFS supports three different flavors of compression -- gzip, lzjb, and
  81  * zle. Compression occurs as part of the write pipeline and is performed
  82  * in the ZIO_STAGE_WRITE_BP_INIT stage.
  83  *
  84  * Dedup:
  85  * Dedup reads are handled by the ZIO_STAGE_DDT_READ_START and
  86  * ZIO_STAGE_DDT_READ_DONE stages. These stages are added to an existing
  87  * read pipeline if the dedup bit is set on the block pointer.
  88  * Writing a dedup block is performed by the ZIO_STAGE_DDT_WRITE stage
  89  * and added to a write pipeline if a user has enabled dedup on that
  90  * particular dataset.
  91  *
  92  * NOP Write:
  93  * The NOP write feature is performed by the ZIO_STAGE_NOP_WRITE stage
  94  * and is added to an existing write pipeline if a crypographically
  95  * secure checksum (i.e. SHA256) is enabled and compression is turned on.
  96  * The NOP write stage will compare the checksums of the current data
  97  * on-disk (level-0 blocks only) and the data that is currently being written.
  98  * If the checksum values are identical then the pipeline is converted to
  99  * an interlock pipeline skipping block allocation and bypassing the
 100  * physical I/O.  The nop write feature can handle writes in either
 101  * syncing or open context (i.e. zil writes) and as a result is mutually
 102  * exclusive with dedup.
 103  */
 104 
 105 /*
 106  * zio pipeline stage definitions
 107  */
 108 enum zio_stage {
 109         ZIO_STAGE_OPEN                  = 1 << 0, /* RWFCI */
 110 
 111         ZIO_STAGE_READ_BP_INIT          = 1 << 1, /* R---- */
 112         ZIO_STAGE_WRITE_BP_INIT         = 1 << 2, /* -W--- */
 113         ZIO_STAGE_FREE_BP_INIT          = 1 << 3, /* --F-- */
 114         ZIO_STAGE_ISSUE_ASYNC           = 1 << 4, /* RWF-- */
 115         ZIO_STAGE_WRITE_COMPRESS        = 1 << 5, /* -W--- */
 116 
 117         ZIO_STAGE_CHECKSUM_GENERATE     = 1 << 6, /* -W--- */
 118 
 119         ZIO_STAGE_NOP_WRITE             = 1 << 7, /* -W--- */
 120 
 121         ZIO_STAGE_DDT_READ_START        = 1 << 8, /* R---- */
 122         ZIO_STAGE_DDT_READ_DONE         = 1 << 9, /* R---- */
 123         ZIO_STAGE_DDT_WRITE             = 1 << 10,        /* -W--- */
 124         ZIO_STAGE_DDT_FREE              = 1 << 11,        /* --F-- */
 125 
 126         ZIO_STAGE_GANG_ASSEMBLE         = 1 << 12,        /* RWFC- */
 127         ZIO_STAGE_GANG_ISSUE            = 1 << 13,        /* RWFC- */
 128 
 129         ZIO_STAGE_DVA_THROTTLE          = 1 << 14,        /* -W--- */
 130         ZIO_STAGE_DVA_ALLOCATE          = 1 << 15,        /* -W--- */
 131         ZIO_STAGE_DVA_FREE              = 1 << 16,        /* --F-- */
 132         ZIO_STAGE_DVA_CLAIM             = 1 << 17,        /* ---C- */
 133 
 134         ZIO_STAGE_READY                 = 1 << 18,        /* RWFCI */
 135 
 136         ZIO_STAGE_VDEV_IO_START         = 1 << 19,        /* RW--I */
 137         ZIO_STAGE_VDEV_IO_DONE          = 1 << 20,        /* RW--I */
 138         ZIO_STAGE_VDEV_IO_ASSESS        = 1 << 21,        /* RW--I */
 139 
 140         ZIO_STAGE_CHECKSUM_VERIFY       = 1 << 22,        /* R---- */
 141 
 142         ZIO_STAGE_DONE                  = 1 << 23 /* RWFCI */
 143 };
 144 
 145 #define ZIO_INTERLOCK_STAGES                    \
 146         (ZIO_STAGE_READY |                      \
 147         ZIO_STAGE_DONE)
 148 
 149 #define ZIO_INTERLOCK_PIPELINE                  \
 150         ZIO_INTERLOCK_STAGES
 151 
 152 #define ZIO_VDEV_IO_STAGES                      \
 153         (ZIO_STAGE_VDEV_IO_START |              \
 154         ZIO_STAGE_VDEV_IO_DONE |                \
 155         ZIO_STAGE_VDEV_IO_ASSESS)
 156 
 157 #define ZIO_VDEV_CHILD_PIPELINE                 \
 158         (ZIO_VDEV_IO_STAGES |                   \
 159         ZIO_STAGE_DONE)
 160 
 161 #define ZIO_READ_COMMON_STAGES                  \
 162         (ZIO_INTERLOCK_STAGES |                 \
 163         ZIO_VDEV_IO_STAGES |                    \
 164         ZIO_STAGE_CHECKSUM_VERIFY)
 165 
 166 #define ZIO_READ_PHYS_PIPELINE                  \
 167         ZIO_READ_COMMON_STAGES
 168 
 169 #define ZIO_READ_PIPELINE                       \
 170         (ZIO_READ_COMMON_STAGES |               \
 171         ZIO_STAGE_READ_BP_INIT)
 172 
 173 #define ZIO_DDT_CHILD_READ_PIPELINE             \
 174         ZIO_READ_COMMON_STAGES
 175 
 176 #define ZIO_DDT_READ_PIPELINE                   \
 177         (ZIO_INTERLOCK_STAGES |                 \
 178         ZIO_STAGE_READ_BP_INIT |                \
 179         ZIO_STAGE_DDT_READ_START |              \
 180         ZIO_STAGE_DDT_READ_DONE)
 181 
 182 #define ZIO_MOVE_PIPELINE                       \
 183         (ZIO_INTERLOCK_STAGES |                 \
 184         ZIO_VDEV_IO_STAGES |                    \
 185         ZIO_STAGE_ISSUE_ASYNC |                 \
 186         ZIO_STAGE_WRITE_BP_INIT |               \
 187         ZIO_STAGE_DVA_ALLOCATE)
 188 
 189 #define ZIO_WRITE_COMMON_STAGES                 \
 190         (ZIO_INTERLOCK_STAGES |                 \
 191         ZIO_VDEV_IO_STAGES |                    \
 192         ZIO_STAGE_ISSUE_ASYNC |                 \
 193         ZIO_STAGE_CHECKSUM_GENERATE)
 194 
 195 #define ZIO_WRITE_PHYS_PIPELINE                 \
 196         ZIO_WRITE_COMMON_STAGES
 197 
 198 #define ZIO_REWRITE_PIPELINE                    \
 199         (ZIO_WRITE_COMMON_STAGES |              \
 200         ZIO_STAGE_WRITE_COMPRESS |              \
 201         ZIO_STAGE_WRITE_BP_INIT)
 202 
 203 #define ZIO_WRITE_PIPELINE                      \
 204         (ZIO_WRITE_COMMON_STAGES |              \
 205         ZIO_STAGE_WRITE_BP_INIT |               \
 206         ZIO_STAGE_WRITE_COMPRESS |              \
 207         ZIO_STAGE_DVA_THROTTLE |                \
 208         ZIO_STAGE_DVA_ALLOCATE)
 209 
 210 #define ZIO_DDT_CHILD_WRITE_PIPELINE            \
 211         (ZIO_INTERLOCK_STAGES |                 \
 212         ZIO_VDEV_IO_STAGES |                    \
 213         ZIO_STAGE_DVA_THROTTLE |                \
 214         ZIO_STAGE_DVA_ALLOCATE)
 215 
 216 #define ZIO_DDT_WRITE_PIPELINE                  \
 217         (ZIO_INTERLOCK_STAGES |                 \
 218         ZIO_STAGE_WRITE_BP_INIT |               \
 219         ZIO_STAGE_ISSUE_ASYNC |                 \
 220         ZIO_STAGE_WRITE_COMPRESS |              \
 221         ZIO_STAGE_CHECKSUM_GENERATE |           \
 222         ZIO_STAGE_DDT_WRITE)
 223 
 224 #define ZIO_GANG_STAGES                         \
 225         (ZIO_STAGE_GANG_ASSEMBLE |              \
 226         ZIO_STAGE_GANG_ISSUE)
 227 
 228 #define ZIO_FREE_PIPELINE                       \
 229         (ZIO_INTERLOCK_STAGES |                 \
 230         ZIO_STAGE_FREE_BP_INIT |                \
 231         ZIO_STAGE_DVA_FREE)
 232 
 233 #define ZIO_DDT_FREE_PIPELINE                   \
 234         (ZIO_INTERLOCK_STAGES |                 \
 235         ZIO_STAGE_FREE_BP_INIT |                \
 236         ZIO_STAGE_ISSUE_ASYNC |                 \
 237         ZIO_STAGE_DDT_FREE)
 238 
 239 #define ZIO_CLAIM_PIPELINE                      \
 240         (ZIO_INTERLOCK_STAGES |                 \
 241         ZIO_STAGE_DVA_CLAIM)
 242 
 243 #define ZIO_IOCTL_PIPELINE                      \
 244         (ZIO_INTERLOCK_STAGES |                 \
 245         ZIO_STAGE_VDEV_IO_START |               \
 246         ZIO_STAGE_VDEV_IO_ASSESS)
 247 
 248 #define ZIO_TRIM_PIPELINE                       \
 249         (ZIO_INTERLOCK_STAGES |                 \
 250         ZIO_STAGE_ISSUE_ASYNC |                 \
 251         ZIO_STAGE_VDEV_IO_START |               \
 252         ZIO_STAGE_VDEV_IO_ASSESS)
 253 
 254 #define ZIO_BLOCKING_STAGES                     \
 255         (ZIO_STAGE_DVA_ALLOCATE |               \
 256         ZIO_STAGE_DVA_CLAIM |                   \
 257         ZIO_STAGE_VDEV_IO_START)
 258 
 259 extern void zio_inject_init(void);
 260 extern void zio_inject_fini(void);
 261 
 262 #ifdef  __cplusplus
 263 }
 264 #endif
 265 
 266 #endif  /* _ZIO_IMPL_H */