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.
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.
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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <sys/spa_impl.h>
29 #include <sys/vdev_impl.h>
32 #include <sys/fm/fs/zfs.h>
33 #include <sys/fm/protocol.h>
34 #include <sys/fm/util.h>
35 #include <sys/sysevent.h>
38 * This general routine is responsible for generating all the different ZFS
39 * ereports. The payload is dependent on the class, and which arguments are
40 * supplied to the function:
42 * EREPORT POOL VDEV IO
48 * If we are in a loading state, all errors are chained together by the same
49 * SPA-wide ENA (Error Numeric Association).
51 * For isolated I/O requests, we get the ENA from the zio_t. The propagation
52 * gets very complicated due to RAID-Z, gang blocks, and vdev caching. We want
53 * to chain together all ereports associated with a logical piece of data. For
54 * read I/Os, there are basically three 'types' of I/O, which form a roughly
58 * | Aggregate I/O | No associated logical data or device
62 * +---------------+ Reads associated with a piece of logical data.
63 * | Read I/O | This includes reads on behalf of RAID-Z,
64 * +---------------+ mirrors, gang blocks, retries, etc.
67 * +---------------+ Reads associated with a particular device, but
68 * | Physical I/O | no logical data. Issued as part of vdev caching
69 * +---------------+ and I/O aggregation.
71 * Note that 'physical I/O' here is not the same terminology as used in the rest
72 * of ZIO. Typically, 'physical I/O' simply means that there is no attached
73 * blockpointer. But I/O with no associated block pointer can still be related
74 * to a logical piece of data (i.e. RAID-Z requests).
76 * Purely physical I/O always have unique ENAs. They are not related to a
77 * particular piece of logical data, and therefore cannot be chained together.
78 * We still generate an ereport, but the DE doesn't correlate it with any
79 * logical piece of data. When such an I/O fails, the delegated I/O requests
80 * will issue a retry, which will trigger the 'real' ereport with the correct
83 * We keep track of the ENA for a ZIO chain through the 'io_logical' member.
84 * When a new logical I/O is issued, we set this to point to itself. Child I/Os
85 * then inherit this pointer, so that when it is first set subsequent failures
86 * will use the same ENA. For vdev cache fill and queue aggregation I/O,
87 * this pointer is set to NULL, and no ereport will be generated (since it
88 * doesn't actually correspond to any particular device or piece of data,
89 * and the caller will always retry without caching or queueing anyway).
92 zfs_ereport_post(const char *subclass
, spa_t
*spa
, vdev_t
*vd
, zio_t
*zio
,
93 uint64_t stateoroffset
, uint64_t size
)
96 nvlist_t
*ereport
, *detector
;
102 * If we are doing a spa_tryimport(), ignore errors.
104 if (spa
->spa_load_state
== SPA_LOAD_TRYIMPORT
)
108 * If we are in the middle of opening a pool, and the previous attempt
109 * failed, don't bother logging any new ereports - we're just going to
110 * get the same diagnosis anyway.
112 if (spa
->spa_load_state
!= SPA_LOAD_NONE
&&
113 spa
->spa_last_open_failed
)
118 * If this is not a read or write zio, ignore the error. This
119 * can occur if the DKIOCFLUSHWRITECACHE ioctl fails.
121 if (zio
->io_type
!= ZIO_TYPE_READ
&&
122 zio
->io_type
!= ZIO_TYPE_WRITE
)
126 * Ignore any errors from speculative I/Os, as failure is an
129 if (zio
->io_flags
& ZIO_FLAG_SPECULATIVE
)
133 * If the vdev has already been marked as failing due to a
134 * failed probe, then ignore any subsequent I/O errors, as the
135 * DE will automatically fault the vdev on the first such
139 (!vdev_readable(vd
) || !vdev_writeable(vd
)) &&
140 strcmp(subclass
, FM_EREPORT_ZFS_PROBE_FAILURE
) != 0)
144 if ((ereport
= fm_nvlist_create(NULL
)) == NULL
)
147 if ((detector
= fm_nvlist_create(NULL
)) == NULL
) {
148 fm_nvlist_destroy(ereport
, FM_NVA_FREE
);
153 * Serialize ereport generation
155 mutex_enter(&spa
->spa_errlist_lock
);
158 * Determine the ENA to use for this event. If we are in a loading
159 * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use
160 * a root zio-wide ENA. Otherwise, simply use a unique ENA.
162 if (spa
->spa_load_state
!= SPA_LOAD_NONE
) {
163 if (spa
->spa_ena
== 0)
164 spa
->spa_ena
= fm_ena_generate(0, FM_ENA_FMT1
);
166 } else if (zio
!= NULL
&& zio
->io_logical
!= NULL
) {
167 if (zio
->io_logical
->io_ena
== 0)
168 zio
->io_logical
->io_ena
=
169 fm_ena_generate(0, FM_ENA_FMT1
);
170 ena
= zio
->io_logical
->io_ena
;
172 ena
= fm_ena_generate(0, FM_ENA_FMT1
);
176 * Construct the full class, detector, and other standard FMA fields.
178 (void) snprintf(class, sizeof (class), "%s.%s",
179 ZFS_ERROR_CLASS
, subclass
);
181 fm_fmri_zfs_set(detector
, FM_ZFS_SCHEME_VERSION
, spa_guid(spa
),
182 vd
!= NULL
? vd
->vdev_guid
: 0);
184 fm_ereport_set(ereport
, FM_EREPORT_VERSION
, class, ena
, detector
, NULL
);
187 * Construct the per-ereport payload, depending on which parameters are
192 * If we are importing a faulted pool, then we treat it like an open,
193 * not an import. Otherwise, the DE will ignore all faults during
194 * import, since the default behavior is to mark the devices as
195 * persistently unavailable, not leave them in the faulted state.
197 state
= spa
->spa_import_faulted
? SPA_LOAD_OPEN
: spa
->spa_load_state
;
200 * Generic payload members common to all ereports.
202 fm_payload_set(ereport
, FM_EREPORT_PAYLOAD_ZFS_POOL
,
203 DATA_TYPE_STRING
, spa_name(spa
), FM_EREPORT_PAYLOAD_ZFS_POOL_GUID
,
204 DATA_TYPE_UINT64
, spa_guid(spa
),
205 FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT
, DATA_TYPE_INT32
,
209 fm_payload_set(ereport
, FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE
,
211 spa_get_failmode(spa
) == ZIO_FAILURE_MODE_WAIT
?
212 FM_EREPORT_FAILMODE_WAIT
:
213 spa_get_failmode(spa
) == ZIO_FAILURE_MODE_CONTINUE
?
214 FM_EREPORT_FAILMODE_CONTINUE
: FM_EREPORT_FAILMODE_PANIC
,
219 vdev_t
*pvd
= vd
->vdev_parent
;
221 fm_payload_set(ereport
, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID
,
222 DATA_TYPE_UINT64
, vd
->vdev_guid
,
223 FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE
,
224 DATA_TYPE_STRING
, vd
->vdev_ops
->vdev_op_type
, NULL
);
226 fm_payload_set(ereport
,
227 FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH
,
228 DATA_TYPE_STRING
, vd
->vdev_path
, NULL
);
230 fm_payload_set(ereport
,
231 FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID
,
232 DATA_TYPE_STRING
, vd
->vdev_devid
, NULL
);
235 fm_payload_set(ereport
,
236 FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID
,
237 DATA_TYPE_UINT64
, pvd
->vdev_guid
,
238 FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE
,
239 DATA_TYPE_STRING
, pvd
->vdev_ops
->vdev_op_type
,
242 fm_payload_set(ereport
,
243 FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH
,
244 DATA_TYPE_STRING
, pvd
->vdev_path
, NULL
);
246 fm_payload_set(ereport
,
247 FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID
,
248 DATA_TYPE_STRING
, pvd
->vdev_devid
, NULL
);
254 * Payload common to all I/Os.
256 fm_payload_set(ereport
, FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR
,
257 DATA_TYPE_INT32
, zio
->io_error
, NULL
);
260 * If the 'size' parameter is non-zero, it indicates this is a
261 * RAID-Z or other I/O where the physical offset and length are
262 * provided for us, instead of within the zio_t.
266 fm_payload_set(ereport
,
267 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET
,
268 DATA_TYPE_UINT64
, stateoroffset
,
269 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE
,
270 DATA_TYPE_UINT64
, size
, NULL
);
272 fm_payload_set(ereport
,
273 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET
,
274 DATA_TYPE_UINT64
, zio
->io_offset
,
275 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE
,
276 DATA_TYPE_UINT64
, zio
->io_size
, NULL
);
280 * Payload for I/Os with corresponding logical information.
282 if (zio
->io_logical
!= NULL
)
283 fm_payload_set(ereport
,
284 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET
,
286 zio
->io_logical
->io_bookmark
.zb_objset
,
287 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT
,
289 zio
->io_logical
->io_bookmark
.zb_object
,
290 FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL
,
292 zio
->io_logical
->io_bookmark
.zb_level
,
293 FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID
,
295 zio
->io_logical
->io_bookmark
.zb_blkid
, NULL
);
296 } else if (vd
!= NULL
) {
298 * If we have a vdev but no zio, this is a device fault, and the
299 * 'stateoroffset' parameter indicates the previous state of the
302 fm_payload_set(ereport
,
303 FM_EREPORT_PAYLOAD_ZFS_PREV_STATE
,
304 DATA_TYPE_UINT64
, stateoroffset
, NULL
);
306 mutex_exit(&spa
->spa_errlist_lock
);
308 fm_ereport_post(ereport
, EVCH_SLEEP
);
310 fm_nvlist_destroy(ereport
, FM_NVA_FREE
);
311 fm_nvlist_destroy(detector
, FM_NVA_FREE
);
316 zfs_post_common(spa_t
*spa
, vdev_t
*vd
, const char *name
)
322 if ((resource
= fm_nvlist_create(NULL
)) == NULL
)
325 (void) snprintf(class, sizeof (class), "%s.%s.%s", FM_RSRC_RESOURCE
,
326 ZFS_ERROR_CLASS
, name
);
327 VERIFY(nvlist_add_uint8(resource
, FM_VERSION
, FM_RSRC_VERSION
) == 0);
328 VERIFY(nvlist_add_string(resource
, FM_CLASS
, class) == 0);
329 VERIFY(nvlist_add_uint64(resource
,
330 FM_EREPORT_PAYLOAD_ZFS_POOL_GUID
, spa_guid(spa
)) == 0);
332 VERIFY(nvlist_add_uint64(resource
,
333 FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID
, vd
->vdev_guid
) == 0);
335 fm_ereport_post(resource
, EVCH_SLEEP
);
337 fm_nvlist_destroy(resource
, FM_NVA_FREE
);
342 * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev
343 * has been removed from the system. This will cause the DE to ignore any
344 * recent I/O errors, inferring that they are due to the asynchronous device
348 zfs_post_remove(spa_t
*spa
, vdev_t
*vd
)
350 zfs_post_common(spa
, vd
, FM_RESOURCE_REMOVED
);
354 * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool
355 * has the 'autoreplace' property set, and therefore any broken vdevs will be
356 * handled by higher level logic, and no vdev fault should be generated.
359 zfs_post_autoreplace(spa_t
*spa
, vdev_t
*vd
)
361 zfs_post_common(spa
, vd
, FM_RESOURCE_AUTOREPLACE
);