xref: /onnv-gate/usr/src/uts/common/fs/zfs/zfs_fm.c (revision 4831:41ec732c6d9f)
11544Seschrock /*
21544Seschrock  * CDDL HEADER START
31544Seschrock  *
41544Seschrock  * The contents of this file are subject to the terms of the
51544Seschrock  * Common Development and Distribution License (the "License").
61544Seschrock  * You may not use this file except in compliance with the License.
71544Seschrock  *
81544Seschrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91544Seschrock  * or http://www.opensolaris.org/os/licensing.
101544Seschrock  * See the License for the specific language governing permissions
111544Seschrock  * and limitations under the License.
121544Seschrock  *
131544Seschrock  * When distributing Covered Code, include this CDDL HEADER in each
141544Seschrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151544Seschrock  * If applicable, add the following below this CDDL HEADER, with the
161544Seschrock  * fields enclosed by brackets "[]" replaced with your own identifying
171544Seschrock  * information: Portions Copyright [yyyy] [name of copyright owner]
181544Seschrock  *
191544Seschrock  * CDDL HEADER END
201544Seschrock  */
211544Seschrock /*
224451Seschrock  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
231544Seschrock  * Use is subject to license terms.
241544Seschrock  */
251544Seschrock 
261544Seschrock #pragma ident	"%Z%%M%	%I%	%E% SMI"
271544Seschrock 
281544Seschrock #include <sys/spa.h>
291544Seschrock #include <sys/spa_impl.h>
301544Seschrock #include <sys/vdev.h>
311544Seschrock #include <sys/vdev_impl.h>
321544Seschrock #include <sys/zio.h>
331544Seschrock 
341544Seschrock #include <sys/fm/fs/zfs.h>
351544Seschrock #include <sys/fm/protocol.h>
361544Seschrock #include <sys/fm/util.h>
371544Seschrock #include <sys/sysevent.h>
381544Seschrock 
391544Seschrock /*
401544Seschrock  * This general routine is responsible for generating all the different ZFS
411544Seschrock  * ereports.  The payload is dependent on the class, and which arguments are
421544Seschrock  * supplied to the function:
431544Seschrock  *
441544Seschrock  * 	EREPORT			POOL	VDEV	IO
451544Seschrock  * 	block			X	X	X
461544Seschrock  * 	data			X		X
471544Seschrock  * 	device			X	X
481544Seschrock  * 	pool			X
491544Seschrock  *
501544Seschrock  * If we are in a loading state, all errors are chained together by the same
511544Seschrock  * SPA-wide ENA.
521544Seschrock  *
531544Seschrock  * For isolated I/O requests, we get the ENA from the zio_t. The propagation
541544Seschrock  * gets very complicated due to RAID-Z, gang blocks, and vdev caching.  We want
551544Seschrock  * to chain together all ereports associated with a logical piece of data.  For
561544Seschrock  * read I/Os, there  are basically three 'types' of I/O, which form a roughly
571544Seschrock  * layered diagram:
581544Seschrock  *
591544Seschrock  *      +---------------+
601544Seschrock  * 	| Aggregate I/O |	No associated logical data or device
611544Seschrock  * 	+---------------+
621544Seschrock  *              |
631544Seschrock  *              V
641544Seschrock  * 	+---------------+	Reads associated with a piece of logical data.
651544Seschrock  * 	|   Read I/O    |	This includes reads on behalf of RAID-Z,
661544Seschrock  * 	+---------------+       mirrors, gang blocks, retries, etc.
671544Seschrock  *              |
681544Seschrock  *              V
691544Seschrock  * 	+---------------+	Reads associated with a particular device, but
701544Seschrock  * 	| Physical I/O  |	no logical data.  Issued as part of vdev caching
711544Seschrock  * 	+---------------+	and I/O aggregation.
721544Seschrock  *
731544Seschrock  * Note that 'physical I/O' here is not the same terminology as used in the rest
741544Seschrock  * of ZIO.  Typically, 'physical I/O' simply means that there is no attached
751544Seschrock  * blockpointer.  But I/O with no associated block pointer can still be related
761544Seschrock  * to a logical piece of data (i.e. RAID-Z requests).
771544Seschrock  *
781544Seschrock  * Purely physical I/O always have unique ENAs.  They are not related to a
791544Seschrock  * particular piece of logical data, and therefore cannot be chained together.
801544Seschrock  * We still generate an ereport, but the DE doesn't correlate it with any
811544Seschrock  * logical piece of data.  When such an I/O fails, the delegated I/O requests
821544Seschrock  * will issue a retry, which will trigger the 'real' ereport with the correct
831544Seschrock  * ENA.
841544Seschrock  *
851544Seschrock  * We keep track of the ENA for a ZIO chain through the 'io_logical' member.
861544Seschrock  * When a new logical I/O is issued, we set this to point to itself.  Child I/Os
871544Seschrock  * then inherit this pointer, so that when it is first set subsequent failures
881544Seschrock  * will use the same ENA.  If a physical I/O is issued (by passing the
891544Seschrock  * ZIO_FLAG_NOBOOKMARK flag), then this pointer is reset, guaranteeing that a
901544Seschrock  * unique ENA will be generated.  For an aggregate I/O, this pointer is set to
911544Seschrock  * NULL, and no ereport will be generated (since it doesn't actually correspond
921544Seschrock  * to any particular device or piece of data).
931544Seschrock  */
941544Seschrock void
951544Seschrock zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd, zio_t *zio,
961544Seschrock     uint64_t stateoroffset, uint64_t size)
971544Seschrock {
981544Seschrock #ifdef _KERNEL
991544Seschrock 	nvlist_t *ereport, *detector;
1001544Seschrock 	uint64_t ena;
1011544Seschrock 	char class[64];
1021544Seschrock 
1031544Seschrock 	/*
1041544Seschrock 	 * If we are doing a spa_tryimport(), ignore errors.
1051544Seschrock 	 */
1061544Seschrock 	if (spa->spa_load_state == SPA_LOAD_TRYIMPORT)
1071544Seschrock 		return;
1081544Seschrock 
1091544Seschrock 	/*
1101544Seschrock 	 * If we are in the middle of opening a pool, and the previous attempt
1111544Seschrock 	 * failed, don't bother logging any new ereports - we're just going to
1121544Seschrock 	 * get the same diagnosis anyway.
1131544Seschrock 	 */
1141544Seschrock 	if (spa->spa_load_state != SPA_LOAD_NONE &&
1151544Seschrock 	    spa->spa_last_open_failed)
1161544Seschrock 		return;
1171544Seschrock 
1181544Seschrock 	/*
1191544Seschrock 	 * Ignore any errors from I/Os that we are going to retry anyway - we
1204451Seschrock 	 * only generate errors from the final failure.  Checksum errors are
1214451Seschrock 	 * generated after the pipeline stage responsible for retrying the I/O
1224451Seschrock 	 * (VDEV_IO_ASSESS), so this only applies to standard I/O errors.
1231544Seschrock 	 */
1244451Seschrock 	if (zio && zio_should_retry(zio) && zio->io_error != ECKSUM)
1251544Seschrock 		return;
1261544Seschrock 
1271773Seschrock 	/*
1281773Seschrock 	 * If this is not a read or write zio, ignore the error.  This can occur
1291773Seschrock 	 * if the DKIOCFLUSHWRITECACHE ioctl fails.
1301773Seschrock 	 */
1311773Seschrock 	if (zio && zio->io_type != ZIO_TYPE_READ &&
1321773Seschrock 	    zio->io_type != ZIO_TYPE_WRITE)
1331773Seschrock 		return;
1341773Seschrock 
1351544Seschrock 	if ((ereport = fm_nvlist_create(NULL)) == NULL)
1361544Seschrock 		return;
1371544Seschrock 
1381544Seschrock 	if ((detector = fm_nvlist_create(NULL)) == NULL) {
1391544Seschrock 		fm_nvlist_destroy(ereport, FM_NVA_FREE);
1401544Seschrock 		return;
1411544Seschrock 	}
1421544Seschrock 
1431544Seschrock 	/*
1441544Seschrock 	 * Serialize ereport generation
1451544Seschrock 	 */
1461544Seschrock 	mutex_enter(&spa->spa_errlist_lock);
1471544Seschrock 
1481544Seschrock 	/*
1491544Seschrock 	 * Determine the ENA to use for this event.  If we are in a loading
1501544Seschrock 	 * state, use a SPA-wide ENA.  Otherwise, if we are in an I/O state, use
1511544Seschrock 	 * a root zio-wide ENA.  Otherwise, simply use a unique ENA.
1521544Seschrock 	 */
1531544Seschrock 	if (spa->spa_load_state != SPA_LOAD_NONE) {
1541544Seschrock 		if (spa->spa_ena == 0)
1551544Seschrock 			spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1);
1561544Seschrock 		ena = spa->spa_ena;
1571544Seschrock 	} else if (zio != NULL && zio->io_logical != NULL) {
1581544Seschrock 		if (zio->io_logical->io_ena == 0)
1591544Seschrock 			zio->io_logical->io_ena =
1601544Seschrock 			    fm_ena_generate(0, FM_ENA_FMT1);
1611544Seschrock 		ena = zio->io_logical->io_ena;
1621544Seschrock 	} else {
1631544Seschrock 		ena = fm_ena_generate(0, FM_ENA_FMT1);
1641544Seschrock 	}
1651544Seschrock 
1661544Seschrock 	/*
1671544Seschrock 	 * Construct the full class, detector, and other standard FMA fields.
1681544Seschrock 	 */
1691544Seschrock 	(void) snprintf(class, sizeof (class), "%s.%s",
1701544Seschrock 	    ZFS_ERROR_CLASS, subclass);
1711544Seschrock 
1721544Seschrock 	fm_fmri_zfs_set(detector, FM_ZFS_SCHEME_VERSION, spa_guid(spa),
1731544Seschrock 	    vd != NULL ? vd->vdev_guid : 0);
1741544Seschrock 
1751544Seschrock 	fm_ereport_set(ereport, FM_EREPORT_VERSION, class, ena, detector, NULL);
1761544Seschrock 
1771544Seschrock 	/*
1781544Seschrock 	 * Construct the per-ereport payload, depending on which parameters are
1791544Seschrock 	 * passed in.
1801544Seschrock 	 */
1811544Seschrock 
1821544Seschrock 	/*
1831544Seschrock 	 * Generic payload members common to all ereports.
1841544Seschrock 	 *
1851544Seschrock 	 * The direct reference to spa_name is used rather than spa_name()
1861544Seschrock 	 * because of the asynchronous nature of the zio pipeline.  spa_name()
1871544Seschrock 	 * asserts that the config lock is held in some form.  This is always
1881544Seschrock 	 * the case in I/O context, but because the check for RW_WRITER compares
1891544Seschrock 	 * against 'curthread', we may be in an asynchronous context and blow
1901544Seschrock 	 * this assert.  Rather than loosen this assert, we acknowledge that all
1911544Seschrock 	 * contexts in which this function is called (pool open, I/O) are safe,
1921544Seschrock 	 * and dereference the name directly.
1931544Seschrock 	 */
1941544Seschrock 	fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL,
1951544Seschrock 	    DATA_TYPE_STRING, spa->spa_name, FM_EREPORT_PAYLOAD_ZFS_POOL_GUID,
1961544Seschrock 	    DATA_TYPE_UINT64, spa_guid(spa),
1971544Seschrock 	    FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, DATA_TYPE_INT32,
1981544Seschrock 	    spa->spa_load_state, NULL);
1991544Seschrock 
2001544Seschrock 	if (vd != NULL) {
2011544Seschrock 		vdev_t *pvd = vd->vdev_parent;
2021544Seschrock 
2031544Seschrock 		fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID,
2041544Seschrock 		    DATA_TYPE_UINT64, vd->vdev_guid,
2051544Seschrock 		    FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE,
2061544Seschrock 		    DATA_TYPE_STRING, vd->vdev_ops->vdev_op_type, NULL);
2071544Seschrock 		if (vd->vdev_path)
2081544Seschrock 			fm_payload_set(ereport,
2091544Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH,
2101544Seschrock 			    DATA_TYPE_STRING, vd->vdev_path, NULL);
2111544Seschrock 		if (vd->vdev_devid)
2121544Seschrock 			fm_payload_set(ereport,
2131544Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID,
2141544Seschrock 			    DATA_TYPE_STRING, vd->vdev_devid, NULL);
2151544Seschrock 
2161544Seschrock 		if (pvd != NULL) {
2171544Seschrock 			fm_payload_set(ereport,
2181544Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID,
2191544Seschrock 			    DATA_TYPE_UINT64, pvd->vdev_guid,
2201544Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE,
2211544Seschrock 			    DATA_TYPE_STRING, pvd->vdev_ops->vdev_op_type,
2221544Seschrock 			    NULL);
2231544Seschrock 			if (pvd->vdev_path)
2241544Seschrock 				fm_payload_set(ereport,
2251544Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH,
226*4831Sgw25295 				    DATA_TYPE_STRING, pvd->vdev_path, NULL);
2271544Seschrock 			if (pvd->vdev_devid)
2281544Seschrock 				fm_payload_set(ereport,
2291544Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID,
2301544Seschrock 				    DATA_TYPE_STRING, pvd->vdev_devid, NULL);
2311544Seschrock 		}
2321544Seschrock 	}
2331544Seschrock 
2341544Seschrock 	if (zio != NULL) {
2351544Seschrock 		/*
2361544Seschrock 		 * Payload common to all I/Os.
2371544Seschrock 		 */
2381544Seschrock 		fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR,
2391544Seschrock 		    DATA_TYPE_INT32, zio->io_error, NULL);
2401544Seschrock 
2411544Seschrock 		/*
2421544Seschrock 		 * If the 'size' parameter is non-zero, it indicates this is a
2431544Seschrock 		 * RAID-Z or other I/O where the physical offset and length are
2441544Seschrock 		 * provided for us, instead of within the zio_t.
2451544Seschrock 		 */
2461544Seschrock 		if (vd != NULL) {
2471544Seschrock 			if (size)
2481544Seschrock 				fm_payload_set(ereport,
2491544Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
2501544Seschrock 				    DATA_TYPE_UINT64, stateoroffset,
2511544Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
2521955Seschrock 				    DATA_TYPE_UINT64, size, NULL);
2531544Seschrock 			else
2541544Seschrock 				fm_payload_set(ereport,
2551544Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET,
2561544Seschrock 				    DATA_TYPE_UINT64, zio->io_offset,
2571544Seschrock 				    FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE,
2581955Seschrock 				    DATA_TYPE_UINT64, zio->io_size, NULL);
2591544Seschrock 		}
2601544Seschrock 
2611544Seschrock 		/*
2621544Seschrock 		 * Payload for I/Os with corresponding logical information.
2631544Seschrock 		 */
2641544Seschrock 		if (zio->io_logical != NULL)
2651544Seschrock 			fm_payload_set(ereport,
2661544Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT,
2671544Seschrock 			    DATA_TYPE_UINT64,
2681544Seschrock 			    zio->io_logical->io_bookmark.zb_object,
2691544Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL,
270*4831Sgw25295 			    DATA_TYPE_INT64,
2711544Seschrock 			    zio->io_logical->io_bookmark.zb_level,
2721544Seschrock 			    FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID,
2731544Seschrock 			    DATA_TYPE_UINT64,
2741955Seschrock 			    zio->io_logical->io_bookmark.zb_blkid, NULL);
2751544Seschrock 	} else if (vd != NULL) {
2761544Seschrock 		/*
2771544Seschrock 		 * If we have a vdev but no zio, this is a device fault, and the
2781544Seschrock 		 * 'stateoroffset' parameter indicates the previous state of the
2791544Seschrock 		 * vdev.
2801544Seschrock 		 */
2811544Seschrock 		fm_payload_set(ereport,
2821544Seschrock 		    FM_EREPORT_PAYLOAD_ZFS_PREV_STATE,
2831544Seschrock 		    DATA_TYPE_UINT64, stateoroffset, NULL);
2841544Seschrock 	}
2851544Seschrock 	mutex_exit(&spa->spa_errlist_lock);
2861544Seschrock 
2871544Seschrock 	fm_ereport_post(ereport, EVCH_SLEEP);
2881544Seschrock 
2891544Seschrock 	fm_nvlist_destroy(ereport, FM_NVA_FREE);
2901544Seschrock 	fm_nvlist_destroy(detector, FM_NVA_FREE);
2911544Seschrock #endif
2921544Seschrock }
2931544Seschrock 
2944451Seschrock static void
2954451Seschrock zfs_post_common(spa_t *spa, vdev_t *vd, const char *name)
2961544Seschrock {
2971544Seschrock #ifdef _KERNEL
2981544Seschrock 	nvlist_t *resource;
2991544Seschrock 	char class[64];
3001544Seschrock 
3011544Seschrock 	if ((resource = fm_nvlist_create(NULL)) == NULL)
3021544Seschrock 		return;
3031544Seschrock 
3041544Seschrock 	(void) snprintf(class, sizeof (class), "%s.%s.%s", FM_RSRC_RESOURCE,
3054451Seschrock 	    ZFS_ERROR_CLASS, name);
3061544Seschrock 	VERIFY(nvlist_add_uint8(resource, FM_VERSION, FM_RSRC_VERSION) == 0);
3071544Seschrock 	VERIFY(nvlist_add_string(resource, FM_CLASS, class) == 0);
3081544Seschrock 	VERIFY(nvlist_add_uint64(resource,
3091544Seschrock 	    FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, spa_guid(spa)) == 0);
3101544Seschrock 	if (vd)
3111544Seschrock 		VERIFY(nvlist_add_uint64(resource,
3121544Seschrock 		    FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, vd->vdev_guid) == 0);
3131544Seschrock 
3141544Seschrock 	fm_ereport_post(resource, EVCH_SLEEP);
3151544Seschrock 
3161544Seschrock 	fm_nvlist_destroy(resource, FM_NVA_FREE);
3171544Seschrock #endif
3181544Seschrock }
3194451Seschrock 
3204451Seschrock /*
3214451Seschrock  * The 'resource.fs.zfs.ok' event is an internal signal that the associated
3224451Seschrock  * resource (pool or disk) has been identified by ZFS as healthy.  This will
3234451Seschrock  * then trigger the DE to close the associated case, if any.
3244451Seschrock  */
3254451Seschrock void
3264451Seschrock zfs_post_ok(spa_t *spa, vdev_t *vd)
3274451Seschrock {
3284451Seschrock 	zfs_post_common(spa, vd, FM_RESOURCE_OK);
3294451Seschrock }
3304451Seschrock 
3314451Seschrock /*
3324451Seschrock  * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev
3334451Seschrock  * has been removed from the system.  This will cause the DE to ignore any
3344451Seschrock  * recent I/O errors, inferring that they are due to the asynchronous device
3354451Seschrock  * removal.
3364451Seschrock  */
3374451Seschrock void
3384451Seschrock zfs_post_remove(spa_t *spa, vdev_t *vd)
3394451Seschrock {
3404451Seschrock 	zfs_post_common(spa, vd, FM_RESOURCE_REMOVED);
3414451Seschrock }
3424451Seschrock 
3434451Seschrock /*
3444451Seschrock  * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool
3454451Seschrock  * has the 'autoreplace' property set, and therefore any broken vdevs will be
3464451Seschrock  * handled by higher level logic, and no vdev fault should be generated.
3474451Seschrock  */
3484451Seschrock void
3494451Seschrock zfs_post_autoreplace(spa_t *spa, vdev_t *vd)
3504451Seschrock {
3514451Seschrock 	zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE);
3524451Seschrock }
353