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 2009 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>
37 /* Including sys/bus.h is just too hard, so I declare what I need here. */
38 extern void devctl_notify(const char *__system, const char *__subsystem,
39 const char *__type, const char *__data);
43 * This general routine is responsible for generating all the different ZFS
44 * ereports. The payload is dependent on the class, and which arguments are
45 * supplied to the function:
47 * EREPORT POOL VDEV IO
53 * If we are in a loading state, all errors are chained together by the same
54 * SPA-wide ENA (Error Numeric Association).
56 * For isolated I/O requests, we get the ENA from the zio_t. The propagation
57 * gets very complicated due to RAID-Z, gang blocks, and vdev caching. We want
58 * to chain together all ereports associated with a logical piece of data. For
59 * read I/Os, there are basically three 'types' of I/O, which form a roughly
63 * | Aggregate I/O | No associated logical data or device
67 * +---------------+ Reads associated with a piece of logical data.
68 * | Read I/O | This includes reads on behalf of RAID-Z,
69 * +---------------+ mirrors, gang blocks, retries, etc.
72 * +---------------+ Reads associated with a particular device, but
73 * | Physical I/O | no logical data. Issued as part of vdev caching
74 * +---------------+ and I/O aggregation.
76 * Note that 'physical I/O' here is not the same terminology as used in the rest
77 * of ZIO. Typically, 'physical I/O' simply means that there is no attached
78 * blockpointer. But I/O with no associated block pointer can still be related
79 * to a logical piece of data (i.e. RAID-Z requests).
81 * Purely physical I/O always have unique ENAs. They are not related to a
82 * particular piece of logical data, and therefore cannot be chained together.
83 * We still generate an ereport, but the DE doesn't correlate it with any
84 * logical piece of data. When such an I/O fails, the delegated I/O requests
85 * will issue a retry, which will trigger the 'real' ereport with the correct
88 * We keep track of the ENA for a ZIO chain through the 'io_logical' member.
89 * When a new logical I/O is issued, we set this to point to itself. Child I/Os
90 * then inherit this pointer, so that when it is first set subsequent failures
91 * will use the same ENA. For vdev cache fill and queue aggregation I/O,
92 * this pointer is set to NULL, and no ereport will be generated (since it
93 * doesn't actually correspond to any particular device or piece of data,
94 * and the caller will always retry without caching or queueing anyway).
97 zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd, zio_t *zio,
98 uint64_t stateoroffset, uint64_t size)
106 * If we are doing a spa_tryimport(), ignore errors.
108 if (spa->spa_load_state == SPA_LOAD_TRYIMPORT)
112 * If we are in the middle of opening a pool, and the previous attempt
113 * failed, don't bother logging any new ereports - we're just going to
114 * get the same diagnosis anyway.
116 if (spa->spa_load_state != SPA_LOAD_NONE &&
117 spa->spa_last_open_failed)
122 * If this is not a read or write zio, ignore the error. This
123 * can occur if the DKIOCFLUSHWRITECACHE ioctl fails.
125 if (zio->io_type != ZIO_TYPE_READ &&
126 zio->io_type != ZIO_TYPE_WRITE)
130 * Ignore any errors from speculative I/Os, as failure is an
133 if (zio->io_flags & ZIO_FLAG_SPECULATIVE)
138 * If the vdev has already been marked as failing due
139 * to a failed probe, then ignore any subsequent I/O
140 * errors, as the DE will automatically fault the vdev
141 * on the first such failure. This also catches cases
142 * where vdev_remove_wanted is set and the device has
143 * not yet been asynchronously placed into the REMOVED
146 if (zio->io_vd == vd &&
147 !vdev_accessible(vd, zio) &&
148 strcmp(subclass, FM_EREPORT_ZFS_PROBE_FAILURE) != 0)
152 * Ignore checksum errors for reads from DTL regions of
155 if (zio->io_type == ZIO_TYPE_READ &&
156 zio->io_error == ECKSUM &&
157 vd->vdev_ops->vdev_op_leaf &&
158 vdev_dtl_contains(vd, DTL_MISSING, zio->io_txg, 1))
164 sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
165 sbuf_printf(&sb, "time=%ju.%ld", (uintmax_t)ts.tv_sec, ts.tv_nsec);
168 * Serialize ereport generation
170 mutex_enter(&spa->spa_errlist_lock);
174 * Determine the ENA to use for this event. If we are in a loading
175 * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use
176 * a root zio-wide ENA. Otherwise, simply use a unique ENA.
178 if (spa->spa_load_state != SPA_LOAD_NONE) {
180 if (spa->spa_ena == 0)
181 spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1);
184 } else if (zio != NULL && zio->io_logical != NULL) {
186 if (zio->io_logical->io_ena == 0)
187 zio->io_logical->io_ena =
188 fm_ena_generate(0, FM_ENA_FMT1);
190 ena = zio->io_logical->io_ena;
193 ena = fm_ena_generate(0, FM_ENA_FMT1);
201 * Construct the full class, detector, and other standard FMA fields.
203 sbuf_printf(&sb, " ereport_version=%u", FM_EREPORT_VERSION);
204 sbuf_printf(&sb, " class=%s.%s", ZFS_ERROR_CLASS, subclass);
206 sbuf_printf(&sb, " zfs_scheme_version=%u", FM_ZFS_SCHEME_VERSION);
209 * Construct the per-ereport payload, depending on which parameters are
214 * Generic payload members common to all ereports.
216 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_POOL, spa_name(spa));
217 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
219 sbuf_printf(&sb, " %s=%d", FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT,
220 spa->spa_load_state);
223 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE,
224 spa_get_failmode(spa) == ZIO_FAILURE_MODE_WAIT ?
225 FM_EREPORT_FAILMODE_WAIT :
226 spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE ?
227 FM_EREPORT_FAILMODE_CONTINUE : FM_EREPORT_FAILMODE_PANIC);
231 vdev_t *pvd = vd->vdev_parent;
233 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
235 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE,
236 vd->vdev_ops->vdev_op_type);
237 if (vd->vdev_path != NULL)
238 sbuf_printf(&sb, " %s=%s",
239 FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, vd->vdev_path);
240 if (vd->vdev_devid != NULL)
241 sbuf_printf(&sb, " %s=%s",
242 FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, vd->vdev_devid);
243 if (vd->vdev_fru != NULL)
244 sbuf_printf(&sb, " %s=%s",
245 FM_EREPORT_PAYLOAD_ZFS_VDEV_FRU, vd->vdev_fru);
248 sbuf_printf(&sb, " %s=%ju",
249 FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, pvd->vdev_guid);
250 sbuf_printf(&sb, " %s=%s",
251 FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE,
252 pvd->vdev_ops->vdev_op_type);
254 sbuf_printf(&sb, " %s=%s",
255 FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH,
258 sbuf_printf(&sb, " %s=%s",
259 FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID,
266 * Payload common to all I/Os.
268 sbuf_printf(&sb, " %s=%u", FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR,
272 * If the 'size' parameter is non-zero, it indicates this is a
273 * RAID-Z or other I/O where the physical offset and length are
274 * provided for us, instead of within the zio_t.
278 sbuf_printf(&sb, " %s=%ju",
279 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
281 sbuf_printf(&sb, " %s=%ju",
282 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, size);
284 sbuf_printf(&sb, " %s=%ju",
285 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
287 sbuf_printf(&sb, " %s=%ju",
288 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
294 * Payload for I/Os with corresponding logical information.
296 if (zio->io_logical != NULL) {
297 sbuf_printf(&sb, " %s=%ju",
298 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT,
299 zio->io_logical->io_bookmark.zb_object);
300 sbuf_printf(&sb, " %s=%ju",
301 FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL,
302 zio->io_logical->io_bookmark.zb_level);
303 sbuf_printf(&sb, " %s=%ju",
304 FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID,
305 zio->io_logical->io_bookmark.zb_blkid);
307 } else if (vd != NULL) {
309 * If we have a vdev but no zio, this is a device fault, and the
310 * 'stateoroffset' parameter indicates the previous state of the
313 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_PREV_STATE,
316 mutex_exit(&spa->spa_errlist_lock);
319 devctl_notify("ZFS", spa->spa_name, subclass, sbuf_data(&sb));
320 if (sbuf_overflowed(&sb))
321 printf("ZFS WARNING: sbuf overflowed\n");
327 zfs_post_common(spa_t *spa, vdev_t *vd, const char *name)
337 sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
338 sbuf_printf(&sb, "time=%ju.%ld", (uintmax_t)ts.tv_sec, ts.tv_nsec);
340 snprintf(class, sizeof(class), "%s.%s.%s", FM_RSRC_RESOURCE,
341 ZFS_ERROR_CLASS, name);
342 sbuf_printf(&sb, " %s=%hhu", FM_VERSION, FM_RSRC_VERSION);
343 sbuf_printf(&sb, " %s=%s", FM_CLASS, class);
344 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
347 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
350 ZFS_LOG(1, "%s", sbuf_data(&sb));
351 devctl_notify("ZFS", spa->spa_name, class, sbuf_data(&sb));
352 if (sbuf_overflowed(&sb))
353 printf("ZFS WARNING: sbuf overflowed\n");
359 * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev
360 * has been removed from the system. This will cause the DE to ignore any
361 * recent I/O errors, inferring that they are due to the asynchronous device
365 zfs_post_remove(spa_t *spa, vdev_t *vd)
367 zfs_post_common(spa, vd, FM_RESOURCE_REMOVED);
371 * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool
372 * has the 'autoreplace' property set, and therefore any broken vdevs will be
373 * handled by higher level logic, and no vdev fault should be generated.
376 zfs_post_autoreplace(spa_t *spa, vdev_t *vd)
378 zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE);