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 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/spa_impl.h>
31 #include <sys/vdev_impl.h>
34 #include <sys/fm/fs/zfs.h>
35 #include <sys/fm/protocol.h>
36 #include <sys/fm/util.h>
39 /* Including sys/bus.h is just too hard, so I declare what I need here. */
40 extern void devctl_notify(const char *__system, const char *__subsystem,
41 const char *__type, const char *__data);
45 * This general routine is responsible for generating all the different ZFS
46 * ereports. The payload is dependent on the class, and which arguments are
47 * supplied to the function:
49 * EREPORT POOL VDEV IO
55 * If we are in a loading state, all errors are chained together by the same
58 * For isolated I/O requests, we get the ENA from the zio_t. The propagation
59 * gets very complicated due to RAID-Z, gang blocks, and vdev caching. We want
60 * to chain together all ereports associated with a logical piece of data. For
61 * read I/Os, there are basically three 'types' of I/O, which form a roughly
65 * | Aggregate I/O | No associated logical data or device
69 * +---------------+ Reads associated with a piece of logical data.
70 * | Read I/O | This includes reads on behalf of RAID-Z,
71 * +---------------+ mirrors, gang blocks, retries, etc.
74 * +---------------+ Reads associated with a particular device, but
75 * | Physical I/O | no logical data. Issued as part of vdev caching
76 * +---------------+ and I/O aggregation.
78 * Note that 'physical I/O' here is not the same terminology as used in the rest
79 * of ZIO. Typically, 'physical I/O' simply means that there is no attached
80 * blockpointer. But I/O with no associated block pointer can still be related
81 * to a logical piece of data (i.e. RAID-Z requests).
83 * Purely physical I/O always have unique ENAs. They are not related to a
84 * particular piece of logical data, and therefore cannot be chained together.
85 * We still generate an ereport, but the DE doesn't correlate it with any
86 * logical piece of data. When such an I/O fails, the delegated I/O requests
87 * will issue a retry, which will trigger the 'real' ereport with the correct
90 * We keep track of the ENA for a ZIO chain through the 'io_logical' member.
91 * When a new logical I/O is issued, we set this to point to itself. Child I/Os
92 * then inherit this pointer, so that when it is first set subsequent failures
93 * will use the same ENA. If a physical I/O is issued (by passing the
94 * ZIO_FLAG_NOBOOKMARK flag), then this pointer is reset, guaranteeing that a
95 * unique ENA will be generated. For an aggregate I/O, this pointer is set to
96 * NULL, and no ereport will be generated (since it doesn't actually correspond
97 * to any particular device or piece of data).
100 zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd, zio_t *zio,
101 uint64_t stateoroffset, uint64_t size)
109 * If we are doing a spa_tryimport(), ignore errors.
111 if (spa->spa_load_state == SPA_LOAD_TRYIMPORT)
115 * If we are in the middle of opening a pool, and the previous attempt
116 * failed, don't bother logging any new ereports - we're just going to
117 * get the same diagnosis anyway.
119 if (spa->spa_load_state != SPA_LOAD_NONE &&
120 spa->spa_last_open_failed)
124 * Ignore any errors from I/Os that we are going to retry anyway - we
125 * only generate errors from the final failure.
127 if (zio && zio_should_retry(zio))
131 * If this is not a read or write zio, ignore the error. This can occur
132 * if the DKIOCFLUSHWRITECACHE ioctl fails.
134 if (zio && zio->io_type != ZIO_TYPE_READ &&
135 zio->io_type != ZIO_TYPE_WRITE)
140 sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
141 sbuf_printf(&sb, "time=%ju.%ld", (uintmax_t)ts.tv_sec, ts.tv_nsec);
144 * Serialize ereport generation
146 mutex_enter(&spa->spa_errlist_lock);
150 * Determine the ENA to use for this event. If we are in a loading
151 * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use
152 * a root zio-wide ENA. Otherwise, simply use a unique ENA.
154 if (spa->spa_load_state != SPA_LOAD_NONE) {
156 if (spa->spa_ena == 0)
157 spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1);
160 } else if (zio != NULL && zio->io_logical != NULL) {
162 if (zio->io_logical->io_ena == 0)
163 zio->io_logical->io_ena =
164 fm_ena_generate(0, FM_ENA_FMT1);
166 ena = zio->io_logical->io_ena;
169 ena = fm_ena_generate(0, FM_ENA_FMT1);
177 * Construct the full class, detector, and other standard FMA fields.
179 sbuf_printf(&sb, " ereport_version=%u", FM_EREPORT_VERSION);
180 sbuf_printf(&sb, " class=%s.%s", ZFS_ERROR_CLASS, subclass);
182 sbuf_printf(&sb, " zfs_scheme_version=%u", FM_ZFS_SCHEME_VERSION);
185 * Construct the per-ereport payload, depending on which parameters are
190 * Generic payload members common to all ereports.
192 * The direct reference to spa_name is used rather than spa_name()
193 * because of the asynchronous nature of the zio pipeline. spa_name()
194 * asserts that the config lock is held in some form. This is always
195 * the case in I/O context, but because the check for RW_WRITER compares
196 * against 'curthread', we may be in an asynchronous context and blow
197 * this assert. Rather than loosen this assert, we acknowledge that all
198 * contexts in which this function is called (pool open, I/O) are safe,
199 * and dereference the name directly.
201 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_POOL, spa->spa_name);
202 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
204 sbuf_printf(&sb, " %s=%u", FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT,
205 spa->spa_load_state);
208 vdev_t *pvd = vd->vdev_parent;
210 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
212 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE,
213 vd->vdev_ops->vdev_op_type);
215 sbuf_printf(&sb, " %s=%s",
216 FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, vd->vdev_path);
218 sbuf_printf(&sb, " %s=%s",
219 FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, vd->vdev_devid);
222 sbuf_printf(&sb, " %s=%ju",
223 FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, pvd->vdev_guid);
224 sbuf_printf(&sb, " %s=%s",
225 FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE,
226 pvd->vdev_ops->vdev_op_type);
228 sbuf_printf(&sb, " %s=%s",
229 FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH,
232 sbuf_printf(&sb, " %s=%s",
233 FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID,
240 * Payload common to all I/Os.
242 sbuf_printf(&sb, " %s=%u", FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR,
246 * If the 'size' parameter is non-zero, it indicates this is a
247 * RAID-Z or other I/O where the physical offset and length are
248 * provided for us, instead of within the zio_t.
252 sbuf_printf(&sb, " %s=%ju",
253 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
255 sbuf_printf(&sb, " %s=%ju",
256 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, size);
258 sbuf_printf(&sb, " %s=%ju",
259 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
261 sbuf_printf(&sb, " %s=%ju",
262 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
268 * Payload for I/Os with corresponding logical information.
270 if (zio->io_logical != NULL) {
271 sbuf_printf(&sb, " %s=%ju",
272 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT,
273 zio->io_logical->io_bookmark.zb_object);
274 sbuf_printf(&sb, " %s=%ju",
275 FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL,
276 zio->io_logical->io_bookmark.zb_level);
277 sbuf_printf(&sb, " %s=%ju",
278 FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID,
279 zio->io_logical->io_bookmark.zb_blkid);
281 } else if (vd != NULL) {
283 * If we have a vdev but no zio, this is a device fault, and the
284 * 'stateoroffset' parameter indicates the previous state of the
287 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_PREV_STATE,
290 mutex_exit(&spa->spa_errlist_lock);
293 ZFS_LOG(1, "%s", sbuf_data(&sb));
294 devctl_notify("ZFS", spa->spa_name, subclass, sbuf_data(&sb));
295 if (sbuf_overflowed(&sb))
296 printf("ZFS WARNING: sbuf overflowed\n");
302 * The 'resource.fs.zfs.ok' event is an internal signal that the associated
303 * resource (pool or disk) has been identified by ZFS as healthy. This will
304 * then trigger the DE to close the associated case, if any.
307 zfs_post_ok(spa_t *spa, vdev_t *vd)
317 sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
318 sbuf_printf(&sb, "time=%ju.%ld", (uintmax_t)ts.tv_sec, ts.tv_nsec);
320 snprintf(class, sizeof(class), "%s.%s.%s", FM_RSRC_RESOURCE,
321 ZFS_ERROR_CLASS, FM_RESOURCE_OK);
322 sbuf_printf(&sb, " %s=%hhu", FM_VERSION, FM_RSRC_VERSION);
323 sbuf_printf(&sb, " %s=%s", FM_CLASS, class);
324 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
327 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
330 devctl_notify("ZFS", spa->spa_name, class, sbuf_data(&sb));
331 if (sbuf_overflowed(&sb))
332 printf("ZFS WARNING: sbuf overflowed\n");