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