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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <sys/spa.h>
27#include <sys/spa_impl.h>
28#include <sys/vdev.h>
29#include <sys/vdev_impl.h>
30#include <sys/zio.h>
31
32#include <sys/fm/fs/zfs.h>
33#include <sys/fm/protocol.h>
34#include <sys/fm/util.h>
35
36#ifdef _KERNEL
37/* Including sys/bus.h is just too hard, so I declare what I need here. */
38extern void devctl_notify(const char *__system, const char *__subsystem,
39 const char *__type, const char *__data);
40#endif
41
42/*
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:
46 *
47 * EREPORT POOL VDEV IO
48 * block X X X
49 * data X X
50 * device X X
51 * pool X
52 *
53 * If we are in a loading state, all errors are chained together by the same
54 * SPA-wide ENA (Error Numeric Association).
55 *
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
60 * layered diagram:
61 *
62 * +---------------+
63 * | Aggregate I/O | No associated logical data or device
64 * +---------------+
65 * |
66 * V
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.
70 * |
71 * V
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.
75 *
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).
80 *
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
86 * ENA.
87 *
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).
95 */
96void
97zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd, zio_t *zio,
98 uint64_t stateoroffset, uint64_t size)
99{
100#ifdef _KERNEL
101 char buf[1024];
102 struct sbuf sb;
103 struct timespec ts;
104 int state;
105
106 /*
107 * If we are doing a spa_tryimport(), ignore errors.
108 */
109 if (spa->spa_load_state == SPA_LOAD_TRYIMPORT)
110 return;
111
112 /*
113 * If we are in the middle of opening a pool, and the previous attempt
114 * failed, don't bother logging any new ereports - we're just going to
115 * get the same diagnosis anyway.
116 */
117 if (spa->spa_load_state != SPA_LOAD_NONE &&
118 spa->spa_last_open_failed)
119 return;
120
121 if (zio != NULL) {
122 /*
123 * If this is not a read or write zio, ignore the error. This
124 * can occur if the DKIOCFLUSHWRITECACHE ioctl fails.
125 */
126 if (zio->io_type != ZIO_TYPE_READ &&
127 zio->io_type != ZIO_TYPE_WRITE)
128 return;
129
130 /*
131 * Ignore any errors from speculative I/Os, as failure is an
132 * expected result.
133 */
134 if (zio->io_flags & ZIO_FLAG_SPECULATIVE)
135 return;
136
137 /*
138 * If the vdev has already been marked as failing due to a
139 * failed probe, then ignore any subsequent I/O errors, as the
140 * DE will automatically fault the vdev on the first such
141 * failure.
142 */
143 if (vd != NULL &&
144 (!vdev_readable(vd) || !vdev_writeable(vd)) &&
145 strcmp(subclass, FM_EREPORT_ZFS_PROBE_FAILURE) != 0)
146 return;
147 }
148 nanotime(&ts);
149
150 sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
151 sbuf_printf(&sb, "time=%ju.%ld", (uintmax_t)ts.tv_sec, ts.tv_nsec);
152
153 /*
154 * Serialize ereport generation
155 */
156 mutex_enter(&spa->spa_errlist_lock);
157
158#if 0
159 /*
160 * Determine the ENA to use for this event. If we are in a loading
161 * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use
162 * a root zio-wide ENA. Otherwise, simply use a unique ENA.
163 */
164 if (spa->spa_load_state != SPA_LOAD_NONE) {
165#if 0
166 if (spa->spa_ena == 0)
167 spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1);
168#endif
169 ena = spa->spa_ena;
170 } else if (zio != NULL && zio->io_logical != NULL) {
171#if 0
172 if (zio->io_logical->io_ena == 0)
173 zio->io_logical->io_ena =
174 fm_ena_generate(0, FM_ENA_FMT1);
175#endif
176 ena = zio->io_logical->io_ena;
177 } else {
178#if 0
179 ena = fm_ena_generate(0, FM_ENA_FMT1);
180#else
181 ena = 0;
182#endif
183 }
184#endif
185
186 /*
187 * Construct the full class, detector, and other standard FMA fields.
188 */
189 sbuf_printf(&sb, " ereport_version=%u", FM_EREPORT_VERSION);
190 sbuf_printf(&sb, " class=%s.%s", ZFS_ERROR_CLASS, subclass);
191
192 sbuf_printf(&sb, " zfs_scheme_version=%u", FM_ZFS_SCHEME_VERSION);
193
194 /*
195 * Construct the per-ereport payload, depending on which parameters are
196 * passed in.
197 */
198
199 /*
200 * If we are importing a faulted pool, then we treat it like an open,
201 * not an import. Otherwise, the DE will ignore all faults during
202 * import, since the default behavior is to mark the devices as
203 * persistently unavailable, not leave them in the faulted state.
204 */
205 state = spa->spa_import_faulted ? SPA_LOAD_OPEN : spa->spa_load_state;
206
207 /*
208 * Generic payload members common to all ereports.
209 */
210 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_POOL, spa_name(spa));
211 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
212 spa_guid(spa));
213 sbuf_printf(&sb, " %s=%d", FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, state);
214
215 if (spa != NULL) {
216 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE,
217 spa_get_failmode(spa) == ZIO_FAILURE_MODE_WAIT ?
218 FM_EREPORT_FAILMODE_WAIT :
219 spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE ?
220 FM_EREPORT_FAILMODE_CONTINUE : FM_EREPORT_FAILMODE_PANIC);
221 }
222
223 if (vd != NULL) {
224 vdev_t *pvd = vd->vdev_parent;
225
226 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
227 vd->vdev_guid);
228 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE,
229 vd->vdev_ops->vdev_op_type);
230 if (vd->vdev_path)
231 sbuf_printf(&sb, " %s=%s",
232 FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, vd->vdev_path);
233 if (vd->vdev_devid)
234 sbuf_printf(&sb, " %s=%s",
235 FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, vd->vdev_devid);
236
237 if (pvd != NULL) {
238 sbuf_printf(&sb, " %s=%ju",
239 FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, pvd->vdev_guid);
240 sbuf_printf(&sb, " %s=%s",
241 FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE,
242 pvd->vdev_ops->vdev_op_type);
243 if (pvd->vdev_path)
244 sbuf_printf(&sb, " %s=%s",
245 FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH,
246 pvd->vdev_path);
247 if (pvd->vdev_devid)
248 sbuf_printf(&sb, " %s=%s",
249 FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID,
250 pvd->vdev_devid);
251 }
252 }
253
254 if (zio != NULL) {
255 /*
256 * Payload common to all I/Os.
257 */
258 sbuf_printf(&sb, " %s=%u", FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR,
259 zio->io_error);
260
261 /*
262 * If the 'size' parameter is non-zero, it indicates this is a
263 * RAID-Z or other I/O where the physical offset and length are
264 * provided for us, instead of within the zio_t.
265 */
266 if (vd != NULL) {
267 if (size) {
268 sbuf_printf(&sb, " %s=%ju",
269 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
270 stateoroffset);
271 sbuf_printf(&sb, " %s=%ju",
272 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, size);
273 } else {
274 sbuf_printf(&sb, " %s=%ju",
275 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
276 zio->io_offset);
277 sbuf_printf(&sb, " %s=%ju",
278 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
279 zio->io_size);
280 }
281 }
282
283 /*
284 * Payload for I/Os with corresponding logical information.
285 */
286 if (zio->io_logical != NULL) {
287 sbuf_printf(&sb, " %s=%ju",
288 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT,
289 zio->io_logical->io_bookmark.zb_object);
290 sbuf_printf(&sb, " %s=%ju",
291 FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL,
292 zio->io_logical->io_bookmark.zb_level);
293 sbuf_printf(&sb, " %s=%ju",
294 FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID,
295 zio->io_logical->io_bookmark.zb_blkid);
296 }
297 } else if (vd != NULL) {
298 /*
299 * If we have a vdev but no zio, this is a device fault, and the
300 * 'stateoroffset' parameter indicates the previous state of the
301 * vdev.
302 */
303 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_PREV_STATE,
304 stateoroffset);
305 }
306 mutex_exit(&spa->spa_errlist_lock);
307
308 sbuf_finish(&sb);
309 devctl_notify("ZFS", spa->spa_name, subclass, sbuf_data(&sb));
310 if (sbuf_overflowed(&sb))
311 printf("ZFS WARNING: sbuf overflowed\n");
312 sbuf_delete(&sb);
313#endif
314}
315
316static void
317zfs_post_common(spa_t *spa, vdev_t *vd, const char *name)
318{
319#ifdef _KERNEL
320 char buf[1024];
321 char class[64];
322 struct sbuf sb;
323 struct timespec ts;
324
325 nanotime(&ts);
326
327 sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
328 sbuf_printf(&sb, "time=%ju.%ld", (uintmax_t)ts.tv_sec, ts.tv_nsec);
329
330 snprintf(class, sizeof(class), "%s.%s.%s", FM_RSRC_RESOURCE,
331 ZFS_ERROR_CLASS, name);
332 sbuf_printf(&sb, " %s=%hhu", FM_VERSION, FM_RSRC_VERSION);
333 sbuf_printf(&sb, " %s=%s", FM_CLASS, class);
334 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
335 spa_guid(spa));
336 if (vd)
337 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
338 vd->vdev_guid);
339 sbuf_finish(&sb);
340 ZFS_LOG(1, "%s", sbuf_data(&sb));
341 devctl_notify("ZFS", spa->spa_name, class, sbuf_data(&sb));
342 if (sbuf_overflowed(&sb))
343 printf("ZFS WARNING: sbuf overflowed\n");
344 sbuf_delete(&sb);
345#endif
346}
347
348/*
349 * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev
350 * has been removed from the system. This will cause the DE to ignore any
351 * recent I/O errors, inferring that they are due to the asynchronous device
352 * removal.
353 */
354void
355zfs_post_remove(spa_t *spa, vdev_t *vd)
356{
357 zfs_post_common(spa, vd, FM_RESOURCE_REMOVED);
358}
359
360/*
361 * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool
362 * has the 'autoreplace' property set, and therefore any broken vdevs will be
363 * handled by higher level logic, and no vdev fault should be generated.
364 */
365void
366zfs_post_autoreplace(spa_t *spa, vdev_t *vd)
367{
368 zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE);
369}
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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <sys/spa.h>
27#include <sys/spa_impl.h>
28#include <sys/vdev.h>
29#include <sys/vdev_impl.h>
30#include <sys/zio.h>
31
32#include <sys/fm/fs/zfs.h>
33#include <sys/fm/protocol.h>
34#include <sys/fm/util.h>
35
36#ifdef _KERNEL
37/* Including sys/bus.h is just too hard, so I declare what I need here. */
38extern void devctl_notify(const char *__system, const char *__subsystem,
39 const char *__type, const char *__data);
40#endif
41
42/*
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:
46 *
47 * EREPORT POOL VDEV IO
48 * block X X X
49 * data X X
50 * device X X
51 * pool X
52 *
53 * If we are in a loading state, all errors are chained together by the same
54 * SPA-wide ENA (Error Numeric Association).
55 *
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
60 * layered diagram:
61 *
62 * +---------------+
63 * | Aggregate I/O | No associated logical data or device
64 * +---------------+
65 * |
66 * V
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.
70 * |
71 * V
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.
75 *
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).
80 *
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
86 * ENA.
87 *
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).
95 */
96void
97zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd, zio_t *zio,
98 uint64_t stateoroffset, uint64_t size)
99{
100#ifdef _KERNEL
101 char buf[1024];
102 struct sbuf sb;
103 struct timespec ts;
104 int state;
105
106 /*
107 * If we are doing a spa_tryimport(), ignore errors.
108 */
109 if (spa->spa_load_state == SPA_LOAD_TRYIMPORT)
110 return;
111
112 /*
113 * If we are in the middle of opening a pool, and the previous attempt
114 * failed, don't bother logging any new ereports - we're just going to
115 * get the same diagnosis anyway.
116 */
117 if (spa->spa_load_state != SPA_LOAD_NONE &&
118 spa->spa_last_open_failed)
119 return;
120
121 if (zio != NULL) {
122 /*
123 * If this is not a read or write zio, ignore the error. This
124 * can occur if the DKIOCFLUSHWRITECACHE ioctl fails.
125 */
126 if (zio->io_type != ZIO_TYPE_READ &&
127 zio->io_type != ZIO_TYPE_WRITE)
128 return;
129
130 /*
131 * Ignore any errors from speculative I/Os, as failure is an
132 * expected result.
133 */
134 if (zio->io_flags & ZIO_FLAG_SPECULATIVE)
135 return;
136
137 /*
138 * If the vdev has already been marked as failing due to a
139 * failed probe, then ignore any subsequent I/O errors, as the
140 * DE will automatically fault the vdev on the first such
141 * failure.
142 */
143 if (vd != NULL &&
144 (!vdev_readable(vd) || !vdev_writeable(vd)) &&
145 strcmp(subclass, FM_EREPORT_ZFS_PROBE_FAILURE) != 0)
146 return;
147 }
148 nanotime(&ts);
149
150 sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
151 sbuf_printf(&sb, "time=%ju.%ld", (uintmax_t)ts.tv_sec, ts.tv_nsec);
152
153 /*
154 * Serialize ereport generation
155 */
156 mutex_enter(&spa->spa_errlist_lock);
157
158#if 0
159 /*
160 * Determine the ENA to use for this event. If we are in a loading
161 * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use
162 * a root zio-wide ENA. Otherwise, simply use a unique ENA.
163 */
164 if (spa->spa_load_state != SPA_LOAD_NONE) {
165#if 0
166 if (spa->spa_ena == 0)
167 spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1);
168#endif
169 ena = spa->spa_ena;
170 } else if (zio != NULL && zio->io_logical != NULL) {
171#if 0
172 if (zio->io_logical->io_ena == 0)
173 zio->io_logical->io_ena =
174 fm_ena_generate(0, FM_ENA_FMT1);
175#endif
176 ena = zio->io_logical->io_ena;
177 } else {
178#if 0
179 ena = fm_ena_generate(0, FM_ENA_FMT1);
180#else
181 ena = 0;
182#endif
183 }
184#endif
185
186 /*
187 * Construct the full class, detector, and other standard FMA fields.
188 */
189 sbuf_printf(&sb, " ereport_version=%u", FM_EREPORT_VERSION);
190 sbuf_printf(&sb, " class=%s.%s", ZFS_ERROR_CLASS, subclass);
191
192 sbuf_printf(&sb, " zfs_scheme_version=%u", FM_ZFS_SCHEME_VERSION);
193
194 /*
195 * Construct the per-ereport payload, depending on which parameters are
196 * passed in.
197 */
198
199 /*
200 * If we are importing a faulted pool, then we treat it like an open,
201 * not an import. Otherwise, the DE will ignore all faults during
202 * import, since the default behavior is to mark the devices as
203 * persistently unavailable, not leave them in the faulted state.
204 */
205 state = spa->spa_import_faulted ? SPA_LOAD_OPEN : spa->spa_load_state;
206
207 /*
208 * Generic payload members common to all ereports.
209 */
210 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_POOL, spa_name(spa));
211 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
212 spa_guid(spa));
213 sbuf_printf(&sb, " %s=%d", FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, state);
214
215 if (spa != NULL) {
216 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE,
217 spa_get_failmode(spa) == ZIO_FAILURE_MODE_WAIT ?
218 FM_EREPORT_FAILMODE_WAIT :
219 spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE ?
220 FM_EREPORT_FAILMODE_CONTINUE : FM_EREPORT_FAILMODE_PANIC);
221 }
222
223 if (vd != NULL) {
224 vdev_t *pvd = vd->vdev_parent;
225
226 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
227 vd->vdev_guid);
228 sbuf_printf(&sb, " %s=%s", FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE,
229 vd->vdev_ops->vdev_op_type);
230 if (vd->vdev_path)
231 sbuf_printf(&sb, " %s=%s",
232 FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, vd->vdev_path);
233 if (vd->vdev_devid)
234 sbuf_printf(&sb, " %s=%s",
235 FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, vd->vdev_devid);
236
237 if (pvd != NULL) {
238 sbuf_printf(&sb, " %s=%ju",
239 FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, pvd->vdev_guid);
240 sbuf_printf(&sb, " %s=%s",
241 FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE,
242 pvd->vdev_ops->vdev_op_type);
243 if (pvd->vdev_path)
244 sbuf_printf(&sb, " %s=%s",
245 FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH,
246 pvd->vdev_path);
247 if (pvd->vdev_devid)
248 sbuf_printf(&sb, " %s=%s",
249 FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID,
250 pvd->vdev_devid);
251 }
252 }
253
254 if (zio != NULL) {
255 /*
256 * Payload common to all I/Os.
257 */
258 sbuf_printf(&sb, " %s=%u", FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR,
259 zio->io_error);
260
261 /*
262 * If the 'size' parameter is non-zero, it indicates this is a
263 * RAID-Z or other I/O where the physical offset and length are
264 * provided for us, instead of within the zio_t.
265 */
266 if (vd != NULL) {
267 if (size) {
268 sbuf_printf(&sb, " %s=%ju",
269 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
270 stateoroffset);
271 sbuf_printf(&sb, " %s=%ju",
272 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, size);
273 } else {
274 sbuf_printf(&sb, " %s=%ju",
275 FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
276 zio->io_offset);
277 sbuf_printf(&sb, " %s=%ju",
278 FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
279 zio->io_size);
280 }
281 }
282
283 /*
284 * Payload for I/Os with corresponding logical information.
285 */
286 if (zio->io_logical != NULL) {
287 sbuf_printf(&sb, " %s=%ju",
288 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT,
289 zio->io_logical->io_bookmark.zb_object);
290 sbuf_printf(&sb, " %s=%ju",
291 FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL,
292 zio->io_logical->io_bookmark.zb_level);
293 sbuf_printf(&sb, " %s=%ju",
294 FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID,
295 zio->io_logical->io_bookmark.zb_blkid);
296 }
297 } else if (vd != NULL) {
298 /*
299 * If we have a vdev but no zio, this is a device fault, and the
300 * 'stateoroffset' parameter indicates the previous state of the
301 * vdev.
302 */
303 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_PREV_STATE,
304 stateoroffset);
305 }
306 mutex_exit(&spa->spa_errlist_lock);
307
308 sbuf_finish(&sb);
309 devctl_notify("ZFS", spa->spa_name, subclass, sbuf_data(&sb));
310 if (sbuf_overflowed(&sb))
311 printf("ZFS WARNING: sbuf overflowed\n");
312 sbuf_delete(&sb);
313#endif
314}
315
316static void
317zfs_post_common(spa_t *spa, vdev_t *vd, const char *name)
318{
319#ifdef _KERNEL
320 char buf[1024];
321 char class[64];
322 struct sbuf sb;
323 struct timespec ts;
324
325 nanotime(&ts);
326
327 sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
328 sbuf_printf(&sb, "time=%ju.%ld", (uintmax_t)ts.tv_sec, ts.tv_nsec);
329
330 snprintf(class, sizeof(class), "%s.%s.%s", FM_RSRC_RESOURCE,
331 ZFS_ERROR_CLASS, name);
332 sbuf_printf(&sb, " %s=%hhu", FM_VERSION, FM_RSRC_VERSION);
333 sbuf_printf(&sb, " %s=%s", FM_CLASS, class);
334 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
335 spa_guid(spa));
336 if (vd)
337 sbuf_printf(&sb, " %s=%ju", FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
338 vd->vdev_guid);
339 sbuf_finish(&sb);
340 ZFS_LOG(1, "%s", sbuf_data(&sb));
341 devctl_notify("ZFS", spa->spa_name, class, sbuf_data(&sb));
342 if (sbuf_overflowed(&sb))
343 printf("ZFS WARNING: sbuf overflowed\n");
344 sbuf_delete(&sb);
345#endif
346}
347
348/*
349 * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev
350 * has been removed from the system. This will cause the DE to ignore any
351 * recent I/O errors, inferring that they are due to the asynchronous device
352 * removal.
353 */
354void
355zfs_post_remove(spa_t *spa, vdev_t *vd)
356{
357 zfs_post_common(spa, vd, FM_RESOURCE_REMOVED);
358}
359
360/*
361 * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool
362 * has the 'autoreplace' property set, and therefore any broken vdevs will be
363 * handled by higher level logic, and no vdev fault should be generated.
364 */
365void
366zfs_post_autoreplace(spa_t *spa, vdev_t *vd)
367{
368 zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE);
369}