xref: /illumos-gate/usr/src/uts/common/fs/zfs/zfs_fm.c (revision 8956713aded83a741173fcd4f9ef1c83521fbea9)
1ea8dc4b6Seschrock /*
2ea8dc4b6Seschrock  * CDDL HEADER START
3ea8dc4b6Seschrock  *
4ea8dc4b6Seschrock  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7ea8dc4b6Seschrock  *
8ea8dc4b6Seschrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9ea8dc4b6Seschrock  * or http://www.opensolaris.org/os/licensing.
10ea8dc4b6Seschrock  * See the License for the specific language governing permissions
11ea8dc4b6Seschrock  * and limitations under the License.
12ea8dc4b6Seschrock  *
13ea8dc4b6Seschrock  * When distributing Covered Code, include this CDDL HEADER in each
14ea8dc4b6Seschrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15ea8dc4b6Seschrock  * If applicable, add the following below this CDDL HEADER, with the
16ea8dc4b6Seschrock  * fields enclosed by brackets "[]" replaced with your own identifying
17ea8dc4b6Seschrock  * information: Portions Copyright [yyyy] [name of copyright owner]
18ea8dc4b6Seschrock  *
19ea8dc4b6Seschrock  * CDDL HEADER END
20ea8dc4b6Seschrock  */
21ea8dc4b6Seschrock /*
226809eb4eSEric Schrock  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23ea8dc4b6Seschrock  * Use is subject to license terms.
24ea8dc4b6Seschrock  */
25ea8dc4b6Seschrock 
26ea8dc4b6Seschrock #include <sys/spa.h>
27ea8dc4b6Seschrock #include <sys/spa_impl.h>
28ea8dc4b6Seschrock #include <sys/vdev.h>
29ea8dc4b6Seschrock #include <sys/vdev_impl.h>
30ea8dc4b6Seschrock #include <sys/zio.h>
31ea8dc4b6Seschrock 
32ea8dc4b6Seschrock #include <sys/fm/fs/zfs.h>
33ea8dc4b6Seschrock #include <sys/fm/protocol.h>
34ea8dc4b6Seschrock #include <sys/fm/util.h>
35ea8dc4b6Seschrock #include <sys/sysevent.h>
36ea8dc4b6Seschrock 
37ea8dc4b6Seschrock /*
38ea8dc4b6Seschrock  * This general routine is responsible for generating all the different ZFS
39ea8dc4b6Seschrock  * ereports.  The payload is dependent on the class, and which arguments are
40ea8dc4b6Seschrock  * supplied to the function:
41ea8dc4b6Seschrock  *
42ea8dc4b6Seschrock  * 	EREPORT			POOL	VDEV	IO
43ea8dc4b6Seschrock  * 	block			X	X	X
44ea8dc4b6Seschrock  * 	data			X		X
45ea8dc4b6Seschrock  * 	device			X	X
46ea8dc4b6Seschrock  * 	pool			X
47ea8dc4b6Seschrock  *
48ea8dc4b6Seschrock  * If we are in a loading state, all errors are chained together by the same
4932b87932Sek  * SPA-wide ENA (Error Numeric Association).
50ea8dc4b6Seschrock  *
51ea8dc4b6Seschrock  * For isolated I/O requests, we get the ENA from the zio_t. The propagation
52ea8dc4b6Seschrock  * gets very complicated due to RAID-Z, gang blocks, and vdev caching.  We want
53ea8dc4b6Seschrock  * to chain together all ereports associated with a logical piece of data.  For
54ea8dc4b6Seschrock  * read I/Os, there  are basically three 'types' of I/O, which form a roughly
55ea8dc4b6Seschrock  * layered diagram:
56ea8dc4b6Seschrock  *
57ea8dc4b6Seschrock  *      +---------------+
58ea8dc4b6Seschrock  * 	| Aggregate I/O |	No associated logical data or device
59ea8dc4b6Seschrock  * 	+---------------+
60ea8dc4b6Seschrock  *              |
61ea8dc4b6Seschrock  *              V
62ea8dc4b6Seschrock  * 	+---------------+	Reads associated with a piece of logical data.
63ea8dc4b6Seschrock  * 	|   Read I/O    |	This includes reads on behalf of RAID-Z,
64ea8dc4b6Seschrock  * 	+---------------+       mirrors, gang blocks, retries, etc.
65ea8dc4b6Seschrock  *              |
66ea8dc4b6Seschrock  *              V
67ea8dc4b6Seschrock  * 	+---------------+	Reads associated with a particular device, but
68ea8dc4b6Seschrock  * 	| Physical I/O  |	no logical data.  Issued as part of vdev caching
69ea8dc4b6Seschrock  * 	+---------------+	and I/O aggregation.
70ea8dc4b6Seschrock  *
71ea8dc4b6Seschrock  * Note that 'physical I/O' here is not the same terminology as used in the rest
72ea8dc4b6Seschrock  * of ZIO.  Typically, 'physical I/O' simply means that there is no attached
73ea8dc4b6Seschrock  * blockpointer.  But I/O with no associated block pointer can still be related
74ea8dc4b6Seschrock  * to a logical piece of data (i.e. RAID-Z requests).
75ea8dc4b6Seschrock  *
76ea8dc4b6Seschrock  * Purely physical I/O always have unique ENAs.  They are not related to a
77ea8dc4b6Seschrock  * particular piece of logical data, and therefore cannot be chained together.
78ea8dc4b6Seschrock  * We still generate an ereport, but the DE doesn't correlate it with any
79ea8dc4b6Seschrock  * logical piece of data.  When such an I/O fails, the delegated I/O requests
80ea8dc4b6Seschrock  * will issue a retry, which will trigger the 'real' ereport with the correct
81ea8dc4b6Seschrock  * ENA.
82ea8dc4b6Seschrock  *
83ea8dc4b6Seschrock  * We keep track of the ENA for a ZIO chain through the 'io_logical' member.
84ea8dc4b6Seschrock  * When a new logical I/O is issued, we set this to point to itself.  Child I/Os
85ea8dc4b6Seschrock  * then inherit this pointer, so that when it is first set subsequent failures
86e14bb325SJeff Bonwick  * will use the same ENA.  For vdev cache fill and queue aggregation I/O,
87e14bb325SJeff Bonwick  * this pointer is set to NULL, and no ereport will be generated (since it
88e14bb325SJeff Bonwick  * doesn't actually correspond to any particular device or piece of data,
89e14bb325SJeff Bonwick  * and the caller will always retry without caching or queueing anyway).
90ea8dc4b6Seschrock  */
91ea8dc4b6Seschrock void
92ea8dc4b6Seschrock zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd, zio_t *zio,
93ea8dc4b6Seschrock     uint64_t stateoroffset, uint64_t size)
94ea8dc4b6Seschrock {
95ea8dc4b6Seschrock #ifdef _KERNEL
96ea8dc4b6Seschrock 	nvlist_t *ereport, *detector;
97ea8dc4b6Seschrock 	uint64_t ena;
98ea8dc4b6Seschrock 	char class[64];
99ea8dc4b6Seschrock 
100ea8dc4b6Seschrock 	/*
101ea8dc4b6Seschrock 	 * If we are doing a spa_tryimport(), ignore errors.
102ea8dc4b6Seschrock 	 */
103ea8dc4b6Seschrock 	if (spa->spa_load_state == SPA_LOAD_TRYIMPORT)
104ea8dc4b6Seschrock 		return;
105ea8dc4b6Seschrock 
106ea8dc4b6Seschrock 	/*
107ea8dc4b6Seschrock 	 * If we are in the middle of opening a pool, and the previous attempt
108ea8dc4b6Seschrock 	 * failed, don't bother logging any new ereports - we're just going to
109ea8dc4b6Seschrock 	 * get the same diagnosis anyway.
110ea8dc4b6Seschrock 	 */
111ea8dc4b6Seschrock 	if (spa->spa_load_state != SPA_LOAD_NONE &&
112ea8dc4b6Seschrock 	    spa->spa_last_open_failed)
113ea8dc4b6Seschrock 		return;
114ea8dc4b6Seschrock 
115bf82a41bSeschrock 	if (zio != NULL) {
116bf82a41bSeschrock 		/*
117bf82a41bSeschrock 		 * If this is not a read or write zio, ignore the error.  This
118bf82a41bSeschrock 		 * can occur if the DKIOCFLUSHWRITECACHE ioctl fails.
119bf82a41bSeschrock 		 */
120bf82a41bSeschrock 		if (zio->io_type != ZIO_TYPE_READ &&
121bf82a41bSeschrock 		    zio->io_type != ZIO_TYPE_WRITE)
122bf82a41bSeschrock 			return;
123bf82a41bSeschrock 
124bf82a41bSeschrock 		/*
125bf82a41bSeschrock 		 * Ignore any errors from speculative I/Os, as failure is an
126bf82a41bSeschrock 		 * expected result.
127bf82a41bSeschrock 		 */
128bf82a41bSeschrock 		if (zio->io_flags & ZIO_FLAG_SPECULATIVE)
129bf82a41bSeschrock 			return;
13051ece835Seschrock 
131*8956713aSEric Schrock 		/*
132*8956713aSEric Schrock 		 * If this I/O is not a retry I/O, don't post an ereport.
133*8956713aSEric Schrock 		 * Otherwise, we risk making bad diagnoses based on B_FAILFAST
134*8956713aSEric Schrock 		 * I/Os.
135*8956713aSEric Schrock 		 */
136*8956713aSEric Schrock 		if (zio->io_error == EIO &&
137*8956713aSEric Schrock 		    !(zio->io_flags & ZIO_FLAG_IO_RETRY))
138*8956713aSEric Schrock 			return;
139*8956713aSEric Schrock 
1406809eb4eSEric Schrock 		if (vd != NULL) {
1416809eb4eSEric Schrock 			/*
1426809eb4eSEric Schrock 			 * If the vdev has already been marked as failing due
1436809eb4eSEric Schrock 			 * to a failed probe, then ignore any subsequent I/O
1446809eb4eSEric Schrock 			 * errors, as the DE will automatically fault the vdev
1456809eb4eSEric Schrock 			 * on the first such failure.  This also catches cases
1466809eb4eSEric Schrock 			 * where vdev_remove_wanted is set and the device has
1476809eb4eSEric Schrock 			 * not yet been asynchronously placed into the REMOVED
1486809eb4eSEric Schrock 			 * state.
1496809eb4eSEric Schrock 			 */
1506809eb4eSEric Schrock 			if (zio->io_vd == vd &&
1516809eb4eSEric Schrock 			    !vdev_accessible(vd, zio) &&
1526809eb4eSEric Schrock 			    strcmp(subclass, FM_EREPORT_ZFS_PROBE_FAILURE) != 0)
1536809eb4eSEric Schrock 				return;
1546809eb4eSEric Schrock 
1556809eb4eSEric Schrock 			/*
1566809eb4eSEric Schrock 			 * Ignore checksum errors for reads from DTL regions of
1576809eb4eSEric Schrock 			 * leaf vdevs.
1586809eb4eSEric Schrock 			 */
1596809eb4eSEric Schrock 			if (zio->io_type == ZIO_TYPE_READ &&
1606809eb4eSEric Schrock 			    zio->io_error == ECKSUM &&
1616809eb4eSEric Schrock 			    vd->vdev_ops->vdev_op_leaf &&
1626809eb4eSEric Schrock 			    vdev_dtl_contains(vd, DTL_MISSING, zio->io_txg, 1))
1636809eb4eSEric Schrock 				return;
1646809eb4eSEric Schrock 		}
165bf82a41bSeschrock 	}
166b468a217Seschrock 
167ea8dc4b6Seschrock 	if ((ereport = fm_nvlist_create(NULL)) == NULL)
168ea8dc4b6Seschrock 		return;
169ea8dc4b6Seschrock 
170ea8dc4b6Seschrock 	if ((detector = fm_nvlist_create(NULL)) == NULL) {
171ea8dc4b6Seschrock 		fm_nvlist_destroy(ereport, FM_NVA_FREE);
172ea8dc4b6Seschrock 		return;
173ea8dc4b6Seschrock 	}
174ea8dc4b6Seschrock 
175ea8dc4b6Seschrock 	/*
176ea8dc4b6Seschrock 	 * Serialize ereport generation
177ea8dc4b6Seschrock 	 */
178ea8dc4b6Seschrock 	mutex_enter(&spa->spa_errlist_lock);
179ea8dc4b6Seschrock 
180ea8dc4b6Seschrock 	/*
181ea8dc4b6Seschrock 	 * Determine the ENA to use for this event.  If we are in a loading
182ea8dc4b6Seschrock 	 * state, use a SPA-wide ENA.  Otherwise, if we are in an I/O state, use
183ea8dc4b6Seschrock 	 * a root zio-wide ENA.  Otherwise, simply use a unique ENA.
184ea8dc4b6Seschrock 	 */
185ea8dc4b6Seschrock 	if (spa->spa_load_state != SPA_LOAD_NONE) {
186ea8dc4b6Seschrock 		if (spa->spa_ena == 0)
187ea8dc4b6Seschrock 			spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1);
188ea8dc4b6Seschrock 		ena = spa->spa_ena;
189ea8dc4b6Seschrock 	} else if (zio != NULL && zio->io_logical != NULL) {
190ea8dc4b6Seschrock 		if (zio->io_logical->io_ena == 0)
191ea8dc4b6Seschrock 			zio->io_logical->io_ena =
192ea8dc4b6Seschrock 			    fm_ena_generate(0, FM_ENA_FMT1);
193ea8dc4b6Seschrock 		ena = zio->io_logical->io_ena;
194ea8dc4b6Seschrock 	} else {
195ea8dc4b6Seschrock 		ena = fm_ena_generate(0, FM_ENA_FMT1);
196ea8dc4b6Seschrock 	}
197ea8dc4b6Seschrock 
198ea8dc4b6Seschrock 	/*
199ea8dc4b6Seschrock 	 * Construct the full class, detector, and other standard FMA fields.
200ea8dc4b6Seschrock 	 */
201ea8dc4b6Seschrock 	(void) snprintf(class, sizeof (class), "%s.%s",
202ea8dc4b6Seschrock 	    ZFS_ERROR_CLASS, subclass);
203ea8dc4b6Seschrock 
204ea8dc4b6Seschrock 	fm_fmri_zfs_set(detector, FM_ZFS_SCHEME_VERSION, spa_guid(spa),
205ea8dc4b6Seschrock 	    vd != NULL ? vd->vdev_guid : 0);
206ea8dc4b6Seschrock 
207ea8dc4b6Seschrock 	fm_ereport_set(ereport, FM_EREPORT_VERSION, class, ena, detector, NULL);
208ea8dc4b6Seschrock 
209ea8dc4b6Seschrock 	/*
210ea8dc4b6Seschrock 	 * Construct the per-ereport payload, depending on which parameters are
211ea8dc4b6Seschrock 	 * passed in.
212ea8dc4b6Seschrock 	 */
213ea8dc4b6Seschrock 
214ea8dc4b6Seschrock 	/*
215ea8dc4b6Seschrock 	 * Generic payload members common to all ereports.
216ea8dc4b6Seschrock 	 */
217ea8dc4b6Seschrock 	fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL,
218e14bb325SJeff Bonwick 	    DATA_TYPE_STRING, spa_name(spa), FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
219ea8dc4b6Seschrock 	    DATA_TYPE_UINT64, spa_guid(spa),
220ea8dc4b6Seschrock 	    FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, DATA_TYPE_INT32,
2216809eb4eSEric Schrock 	    spa->spa_load_state, NULL);
222ea8dc4b6Seschrock 
22332b87932Sek 	if (spa != NULL) {
22432b87932Sek 		fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE,
22532b87932Sek 		    DATA_TYPE_STRING,
22632b87932Sek 		    spa_get_failmode(spa) == ZIO_FAILURE_MODE_WAIT ?
22732b87932Sek 		    FM_EREPORT_FAILMODE_WAIT :
22832b87932Sek 		    spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE ?
22932b87932Sek 		    FM_EREPORT_FAILMODE_CONTINUE : FM_EREPORT_FAILMODE_PANIC,
23032b87932Sek 		    NULL);
23132b87932Sek 	}
23232b87932Sek 
233ea8dc4b6Seschrock 	if (vd != NULL) {
234ea8dc4b6Seschrock 		vdev_t *pvd = vd->vdev_parent;
235ea8dc4b6Seschrock 
236ea8dc4b6Seschrock 		fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
237ea8dc4b6Seschrock 		    DATA_TYPE_UINT64, vd->vdev_guid,
238ea8dc4b6Seschrock 		    FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE,
239ea8dc4b6Seschrock 		    DATA_TYPE_STRING, vd->vdev_ops->vdev_op_type, NULL);
2406809eb4eSEric Schrock 		if (vd->vdev_path != NULL)
241ea8dc4b6Seschrock 			fm_payload_set(ereport,
242ea8dc4b6Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH,
243ea8dc4b6Seschrock 			    DATA_TYPE_STRING, vd->vdev_path, NULL);
2446809eb4eSEric Schrock 		if (vd->vdev_devid != NULL)
245ea8dc4b6Seschrock 			fm_payload_set(ereport,
246ea8dc4b6Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID,
247ea8dc4b6Seschrock 			    DATA_TYPE_STRING, vd->vdev_devid, NULL);
2486809eb4eSEric Schrock 		if (vd->vdev_fru != NULL)
2496809eb4eSEric Schrock 			fm_payload_set(ereport,
2506809eb4eSEric Schrock 			    FM_EREPORT_PAYLOAD_ZFS_VDEV_FRU,
2516809eb4eSEric Schrock 			    DATA_TYPE_STRING, vd->vdev_fru, NULL);
252ea8dc4b6Seschrock 
253ea8dc4b6Seschrock 		if (pvd != NULL) {
254ea8dc4b6Seschrock 			fm_payload_set(ereport,
255ea8dc4b6Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID,
256ea8dc4b6Seschrock 			    DATA_TYPE_UINT64, pvd->vdev_guid,
257ea8dc4b6Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE,
258ea8dc4b6Seschrock 			    DATA_TYPE_STRING, pvd->vdev_ops->vdev_op_type,
259ea8dc4b6Seschrock 			    NULL);
260ea8dc4b6Seschrock 			if (pvd->vdev_path)
261ea8dc4b6Seschrock 				fm_payload_set(ereport,
262ea8dc4b6Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH,
263c25056deSgw 				    DATA_TYPE_STRING, pvd->vdev_path, NULL);
264ea8dc4b6Seschrock 			if (pvd->vdev_devid)
265ea8dc4b6Seschrock 				fm_payload_set(ereport,
266ea8dc4b6Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID,
267ea8dc4b6Seschrock 				    DATA_TYPE_STRING, pvd->vdev_devid, NULL);
268ea8dc4b6Seschrock 		}
269ea8dc4b6Seschrock 	}
270ea8dc4b6Seschrock 
271ea8dc4b6Seschrock 	if (zio != NULL) {
272ea8dc4b6Seschrock 		/*
273ea8dc4b6Seschrock 		 * Payload common to all I/Os.
274ea8dc4b6Seschrock 		 */
275ea8dc4b6Seschrock 		fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR,
276ea8dc4b6Seschrock 		    DATA_TYPE_INT32, zio->io_error, NULL);
277ea8dc4b6Seschrock 
278ea8dc4b6Seschrock 		/*
279ea8dc4b6Seschrock 		 * If the 'size' parameter is non-zero, it indicates this is a
280ea8dc4b6Seschrock 		 * RAID-Z or other I/O where the physical offset and length are
281ea8dc4b6Seschrock 		 * provided for us, instead of within the zio_t.
282ea8dc4b6Seschrock 		 */
283ea8dc4b6Seschrock 		if (vd != NULL) {
284ea8dc4b6Seschrock 			if (size)
285ea8dc4b6Seschrock 				fm_payload_set(ereport,
286ea8dc4b6Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
287ea8dc4b6Seschrock 				    DATA_TYPE_UINT64, stateoroffset,
288ea8dc4b6Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
289c3c6d682Seschrock 				    DATA_TYPE_UINT64, size, NULL);
290ea8dc4b6Seschrock 			else
291ea8dc4b6Seschrock 				fm_payload_set(ereport,
292ea8dc4b6Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
293ea8dc4b6Seschrock 				    DATA_TYPE_UINT64, zio->io_offset,
294ea8dc4b6Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
295c3c6d682Seschrock 				    DATA_TYPE_UINT64, zio->io_size, NULL);
296ea8dc4b6Seschrock 		}
297ea8dc4b6Seschrock 
298ea8dc4b6Seschrock 		/*
299ea8dc4b6Seschrock 		 * Payload for I/Os with corresponding logical information.
300ea8dc4b6Seschrock 		 */
301ea8dc4b6Seschrock 		if (zio->io_logical != NULL)
302ea8dc4b6Seschrock 			fm_payload_set(ereport,
303e7cbe64fSgw 			    FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET,
304e7cbe64fSgw 			    DATA_TYPE_UINT64,
305e7cbe64fSgw 			    zio->io_logical->io_bookmark.zb_objset,
306ea8dc4b6Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT,
307ea8dc4b6Seschrock 			    DATA_TYPE_UINT64,
308ea8dc4b6Seschrock 			    zio->io_logical->io_bookmark.zb_object,
309ea8dc4b6Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL,
310c25056deSgw 			    DATA_TYPE_INT64,
311ea8dc4b6Seschrock 			    zio->io_logical->io_bookmark.zb_level,
312ea8dc4b6Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID,
313ea8dc4b6Seschrock 			    DATA_TYPE_UINT64,
314c3c6d682Seschrock 			    zio->io_logical->io_bookmark.zb_blkid, NULL);
315ea8dc4b6Seschrock 	} else if (vd != NULL) {
316ea8dc4b6Seschrock 		/*
317ea8dc4b6Seschrock 		 * If we have a vdev but no zio, this is a device fault, and the
318ea8dc4b6Seschrock 		 * 'stateoroffset' parameter indicates the previous state of the
319ea8dc4b6Seschrock 		 * vdev.
320ea8dc4b6Seschrock 		 */
321ea8dc4b6Seschrock 		fm_payload_set(ereport,
322ea8dc4b6Seschrock 		    FM_EREPORT_PAYLOAD_ZFS_PREV_STATE,
323ea8dc4b6Seschrock 		    DATA_TYPE_UINT64, stateoroffset, NULL);
324ea8dc4b6Seschrock 	}
325ea8dc4b6Seschrock 	mutex_exit(&spa->spa_errlist_lock);
326ea8dc4b6Seschrock 
327ea8dc4b6Seschrock 	fm_ereport_post(ereport, EVCH_SLEEP);
328ea8dc4b6Seschrock 
329ea8dc4b6Seschrock 	fm_nvlist_destroy(ereport, FM_NVA_FREE);
330ea8dc4b6Seschrock 	fm_nvlist_destroy(detector, FM_NVA_FREE);
331ea8dc4b6Seschrock #endif
332ea8dc4b6Seschrock }
333ea8dc4b6Seschrock 
3343d7072f8Seschrock static void
3353d7072f8Seschrock zfs_post_common(spa_t *spa, vdev_t *vd, const char *name)
336ea8dc4b6Seschrock {
337ea8dc4b6Seschrock #ifdef _KERNEL
338ea8dc4b6Seschrock 	nvlist_t *resource;
339ea8dc4b6Seschrock 	char class[64];
340ea8dc4b6Seschrock 
341ea8dc4b6Seschrock 	if ((resource = fm_nvlist_create(NULL)) == NULL)
342ea8dc4b6Seschrock 		return;
343ea8dc4b6Seschrock 
344ea8dc4b6Seschrock 	(void) snprintf(class, sizeof (class), "%s.%s.%s", FM_RSRC_RESOURCE,
3453d7072f8Seschrock 	    ZFS_ERROR_CLASS, name);
346ea8dc4b6Seschrock 	VERIFY(nvlist_add_uint8(resource, FM_VERSION, FM_RSRC_VERSION) == 0);
347ea8dc4b6Seschrock 	VERIFY(nvlist_add_string(resource, FM_CLASS, class) == 0);
348ea8dc4b6Seschrock 	VERIFY(nvlist_add_uint64(resource,
349ea8dc4b6Seschrock 	    FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, spa_guid(spa)) == 0);
350ea8dc4b6Seschrock 	if (vd)
351ea8dc4b6Seschrock 		VERIFY(nvlist_add_uint64(resource,
352ea8dc4b6Seschrock 		    FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, vd->vdev_guid) == 0);
353ea8dc4b6Seschrock 
354ea8dc4b6Seschrock 	fm_ereport_post(resource, EVCH_SLEEP);
355ea8dc4b6Seschrock 
356ea8dc4b6Seschrock 	fm_nvlist_destroy(resource, FM_NVA_FREE);
357ea8dc4b6Seschrock #endif
358ea8dc4b6Seschrock }
3593d7072f8Seschrock 
3603d7072f8Seschrock /*
3613d7072f8Seschrock  * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev
3623d7072f8Seschrock  * has been removed from the system.  This will cause the DE to ignore any
3633d7072f8Seschrock  * recent I/O errors, inferring that they are due to the asynchronous device
3643d7072f8Seschrock  * removal.
3653d7072f8Seschrock  */
3663d7072f8Seschrock void
3673d7072f8Seschrock zfs_post_remove(spa_t *spa, vdev_t *vd)
3683d7072f8Seschrock {
3693d7072f8Seschrock 	zfs_post_common(spa, vd, FM_RESOURCE_REMOVED);
3703d7072f8Seschrock }
3713d7072f8Seschrock 
3723d7072f8Seschrock /*
3733d7072f8Seschrock  * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool
3743d7072f8Seschrock  * has the 'autoreplace' property set, and therefore any broken vdevs will be
3753d7072f8Seschrock  * handled by higher level logic, and no vdev fault should be generated.
3763d7072f8Seschrock  */
3773d7072f8Seschrock void
3783d7072f8Seschrock zfs_post_autoreplace(spa_t *spa, vdev_t *vd)
3793d7072f8Seschrock {
3803d7072f8Seschrock 	zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE);
3813d7072f8Seschrock }
382