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