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 /* 226423Sgw25295 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 231544Seschrock * Use is subject to license terms. 241544Seschrock */ 251544Seschrock 261544Seschrock #include <sys/spa.h> 271544Seschrock #include <sys/spa_impl.h> 281544Seschrock #include <sys/vdev.h> 291544Seschrock #include <sys/vdev_impl.h> 301544Seschrock #include <sys/zio.h> 311544Seschrock 321544Seschrock #include <sys/fm/fs/zfs.h> 331544Seschrock #include <sys/fm/protocol.h> 341544Seschrock #include <sys/fm/util.h> 351544Seschrock #include <sys/sysevent.h> 361544Seschrock 371544Seschrock /* 381544Seschrock * This general routine is responsible for generating all the different ZFS 391544Seschrock * ereports. The payload is dependent on the class, and which arguments are 401544Seschrock * supplied to the function: 411544Seschrock * 421544Seschrock * EREPORT POOL VDEV IO 431544Seschrock * block X X X 441544Seschrock * data X X 451544Seschrock * device X X 461544Seschrock * pool X 471544Seschrock * 481544Seschrock * If we are in a loading state, all errors are chained together by the same 496523Sek110237 * SPA-wide ENA (Error Numeric Association). 501544Seschrock * 511544Seschrock * For isolated I/O requests, we get the ENA from the zio_t. The propagation 521544Seschrock * gets very complicated due to RAID-Z, gang blocks, and vdev caching. We want 531544Seschrock * to chain together all ereports associated with a logical piece of data. For 541544Seschrock * read I/Os, there are basically three 'types' of I/O, which form a roughly 551544Seschrock * layered diagram: 561544Seschrock * 571544Seschrock * +---------------+ 581544Seschrock * | Aggregate I/O | No associated logical data or device 591544Seschrock * +---------------+ 601544Seschrock * | 611544Seschrock * V 621544Seschrock * +---------------+ Reads associated with a piece of logical data. 631544Seschrock * | Read I/O | This includes reads on behalf of RAID-Z, 641544Seschrock * +---------------+ mirrors, gang blocks, retries, etc. 651544Seschrock * | 661544Seschrock * V 671544Seschrock * +---------------+ Reads associated with a particular device, but 681544Seschrock * | Physical I/O | no logical data. Issued as part of vdev caching 691544Seschrock * +---------------+ and I/O aggregation. 701544Seschrock * 711544Seschrock * Note that 'physical I/O' here is not the same terminology as used in the rest 721544Seschrock * of ZIO. Typically, 'physical I/O' simply means that there is no attached 731544Seschrock * blockpointer. But I/O with no associated block pointer can still be related 741544Seschrock * to a logical piece of data (i.e. RAID-Z requests). 751544Seschrock * 761544Seschrock * Purely physical I/O always have unique ENAs. They are not related to a 771544Seschrock * particular piece of logical data, and therefore cannot be chained together. 781544Seschrock * We still generate an ereport, but the DE doesn't correlate it with any 791544Seschrock * logical piece of data. When such an I/O fails, the delegated I/O requests 801544Seschrock * will issue a retry, which will trigger the 'real' ereport with the correct 811544Seschrock * ENA. 821544Seschrock * 831544Seschrock * We keep track of the ENA for a ZIO chain through the 'io_logical' member. 841544Seschrock * When a new logical I/O is issued, we set this to point to itself. Child I/Os 851544Seschrock * then inherit this pointer, so that when it is first set subsequent failures 86*7754SJeff.Bonwick@Sun.COM * will use the same ENA. For vdev cache fill and queue aggregation I/O, 87*7754SJeff.Bonwick@Sun.COM * this pointer is set to NULL, and no ereport will be generated (since it 88*7754SJeff.Bonwick@Sun.COM * doesn't actually correspond to any particular device or piece of data, 89*7754SJeff.Bonwick@Sun.COM * and the caller will always retry without caching or queueing anyway). 901544Seschrock */ 911544Seschrock void 921544Seschrock zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd, zio_t *zio, 931544Seschrock uint64_t stateoroffset, uint64_t size) 941544Seschrock { 951544Seschrock #ifdef _KERNEL 961544Seschrock nvlist_t *ereport, *detector; 971544Seschrock uint64_t ena; 981544Seschrock char class[64]; 996643Seschrock int state; 1001544Seschrock 1011544Seschrock /* 1021544Seschrock * If we are doing a spa_tryimport(), ignore errors. 1031544Seschrock */ 1041544Seschrock if (spa->spa_load_state == SPA_LOAD_TRYIMPORT) 1051544Seschrock return; 1061544Seschrock 1071544Seschrock /* 1081544Seschrock * If we are in the middle of opening a pool, and the previous attempt 1091544Seschrock * failed, don't bother logging any new ereports - we're just going to 1101544Seschrock * get the same diagnosis anyway. 1111544Seschrock */ 1121544Seschrock if (spa->spa_load_state != SPA_LOAD_NONE && 1131544Seschrock spa->spa_last_open_failed) 1141544Seschrock return; 1151544Seschrock 1166673Seschrock if (zio != NULL) { 1176673Seschrock /* 1186673Seschrock * If this is not a read or write zio, ignore the error. This 1196673Seschrock * can occur if the DKIOCFLUSHWRITECACHE ioctl fails. 1206673Seschrock */ 1216673Seschrock if (zio->io_type != ZIO_TYPE_READ && 1226673Seschrock zio->io_type != ZIO_TYPE_WRITE) 1236673Seschrock return; 1246673Seschrock 1256673Seschrock /* 1266673Seschrock * Ignore any errors from speculative I/Os, as failure is an 1276673Seschrock * expected result. 1286673Seschrock */ 1296673Seschrock if (zio->io_flags & ZIO_FLAG_SPECULATIVE) 1306673Seschrock return; 1316976Seschrock 1326976Seschrock /* 1336976Seschrock * If the vdev has already been marked as failing due to a 1346976Seschrock * failed probe, then ignore any subsequent I/O errors, as the 1356976Seschrock * DE will automatically fault the vdev on the first such 1366976Seschrock * failure. 1376976Seschrock */ 138*7754SJeff.Bonwick@Sun.COM if (vd != NULL && 139*7754SJeff.Bonwick@Sun.COM (!vdev_readable(vd) || !vdev_writeable(vd)) && 1406976Seschrock strcmp(subclass, FM_EREPORT_ZFS_PROBE_FAILURE) != 0) 1416976Seschrock return; 1426673Seschrock } 1431773Seschrock 1441544Seschrock if ((ereport = fm_nvlist_create(NULL)) == NULL) 1451544Seschrock return; 1461544Seschrock 1471544Seschrock if ((detector = fm_nvlist_create(NULL)) == NULL) { 1481544Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 1491544Seschrock return; 1501544Seschrock } 1511544Seschrock 1521544Seschrock /* 1531544Seschrock * Serialize ereport generation 1541544Seschrock */ 1551544Seschrock mutex_enter(&spa->spa_errlist_lock); 1561544Seschrock 1571544Seschrock /* 1581544Seschrock * Determine the ENA to use for this event. If we are in a loading 1591544Seschrock * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use 1601544Seschrock * a root zio-wide ENA. Otherwise, simply use a unique ENA. 1611544Seschrock */ 1621544Seschrock if (spa->spa_load_state != SPA_LOAD_NONE) { 1631544Seschrock if (spa->spa_ena == 0) 1641544Seschrock spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1); 1651544Seschrock ena = spa->spa_ena; 1661544Seschrock } else if (zio != NULL && zio->io_logical != NULL) { 1671544Seschrock if (zio->io_logical->io_ena == 0) 1681544Seschrock zio->io_logical->io_ena = 1691544Seschrock fm_ena_generate(0, FM_ENA_FMT1); 1701544Seschrock ena = zio->io_logical->io_ena; 1711544Seschrock } else { 1721544Seschrock ena = fm_ena_generate(0, FM_ENA_FMT1); 1731544Seschrock } 1741544Seschrock 1751544Seschrock /* 1761544Seschrock * Construct the full class, detector, and other standard FMA fields. 1771544Seschrock */ 1781544Seschrock (void) snprintf(class, sizeof (class), "%s.%s", 1791544Seschrock ZFS_ERROR_CLASS, subclass); 1801544Seschrock 1811544Seschrock fm_fmri_zfs_set(detector, FM_ZFS_SCHEME_VERSION, spa_guid(spa), 1821544Seschrock vd != NULL ? vd->vdev_guid : 0); 1831544Seschrock 1841544Seschrock fm_ereport_set(ereport, FM_EREPORT_VERSION, class, ena, detector, NULL); 1851544Seschrock 1861544Seschrock /* 1871544Seschrock * Construct the per-ereport payload, depending on which parameters are 1881544Seschrock * passed in. 1891544Seschrock */ 1901544Seschrock 1911544Seschrock /* 1926643Seschrock * If we are importing a faulted pool, then we treat it like an open, 1936643Seschrock * not an import. Otherwise, the DE will ignore all faults during 1946643Seschrock * import, since the default behavior is to mark the devices as 1956643Seschrock * persistently unavailable, not leave them in the faulted state. 1966643Seschrock */ 1976643Seschrock state = spa->spa_import_faulted ? SPA_LOAD_OPEN : spa->spa_load_state; 1986643Seschrock 1996643Seschrock /* 2001544Seschrock * Generic payload members common to all ereports. 2011544Seschrock */ 2021544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL, 203*7754SJeff.Bonwick@Sun.COM DATA_TYPE_STRING, spa_name(spa), FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, 2041544Seschrock DATA_TYPE_UINT64, spa_guid(spa), 2051544Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, DATA_TYPE_INT32, 2066643Seschrock state, NULL); 2071544Seschrock 2086523Sek110237 if (spa != NULL) { 2096523Sek110237 fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE, 2106523Sek110237 DATA_TYPE_STRING, 2116523Sek110237 spa_get_failmode(spa) == ZIO_FAILURE_MODE_WAIT ? 2126523Sek110237 FM_EREPORT_FAILMODE_WAIT : 2136523Sek110237 spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE ? 2146523Sek110237 FM_EREPORT_FAILMODE_CONTINUE : FM_EREPORT_FAILMODE_PANIC, 2156523Sek110237 NULL); 2166523Sek110237 } 2176523Sek110237 2181544Seschrock if (vd != NULL) { 2191544Seschrock vdev_t *pvd = vd->vdev_parent; 2201544Seschrock 2211544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, 2221544Seschrock DATA_TYPE_UINT64, vd->vdev_guid, 2231544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE, 2241544Seschrock DATA_TYPE_STRING, vd->vdev_ops->vdev_op_type, NULL); 2251544Seschrock if (vd->vdev_path) 2261544Seschrock fm_payload_set(ereport, 2271544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, 2281544Seschrock DATA_TYPE_STRING, vd->vdev_path, NULL); 2291544Seschrock if (vd->vdev_devid) 2301544Seschrock fm_payload_set(ereport, 2311544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, 2321544Seschrock DATA_TYPE_STRING, vd->vdev_devid, NULL); 2331544Seschrock 2341544Seschrock if (pvd != NULL) { 2351544Seschrock fm_payload_set(ereport, 2361544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, 2371544Seschrock DATA_TYPE_UINT64, pvd->vdev_guid, 2381544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE, 2391544Seschrock DATA_TYPE_STRING, pvd->vdev_ops->vdev_op_type, 2401544Seschrock NULL); 2411544Seschrock if (pvd->vdev_path) 2421544Seschrock fm_payload_set(ereport, 2431544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH, 2444831Sgw25295 DATA_TYPE_STRING, pvd->vdev_path, NULL); 2451544Seschrock if (pvd->vdev_devid) 2461544Seschrock fm_payload_set(ereport, 2471544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID, 2481544Seschrock DATA_TYPE_STRING, pvd->vdev_devid, NULL); 2491544Seschrock } 2501544Seschrock } 2511544Seschrock 2521544Seschrock if (zio != NULL) { 2531544Seschrock /* 2541544Seschrock * Payload common to all I/Os. 2551544Seschrock */ 2561544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR, 2571544Seschrock DATA_TYPE_INT32, zio->io_error, NULL); 2581544Seschrock 2591544Seschrock /* 2601544Seschrock * If the 'size' parameter is non-zero, it indicates this is a 2611544Seschrock * RAID-Z or other I/O where the physical offset and length are 2621544Seschrock * provided for us, instead of within the zio_t. 2631544Seschrock */ 2641544Seschrock if (vd != NULL) { 2651544Seschrock if (size) 2661544Seschrock fm_payload_set(ereport, 2671544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 2681544Seschrock DATA_TYPE_UINT64, stateoroffset, 2691544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 2701955Seschrock DATA_TYPE_UINT64, size, NULL); 2711544Seschrock else 2721544Seschrock fm_payload_set(ereport, 2731544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 2741544Seschrock DATA_TYPE_UINT64, zio->io_offset, 2751544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 2761955Seschrock DATA_TYPE_UINT64, zio->io_size, NULL); 2771544Seschrock } 2781544Seschrock 2791544Seschrock /* 2801544Seschrock * Payload for I/Os with corresponding logical information. 2811544Seschrock */ 2821544Seschrock if (zio->io_logical != NULL) 2831544Seschrock fm_payload_set(ereport, 2846423Sgw25295 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET, 2856423Sgw25295 DATA_TYPE_UINT64, 2866423Sgw25295 zio->io_logical->io_bookmark.zb_objset, 2871544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT, 2881544Seschrock DATA_TYPE_UINT64, 2891544Seschrock zio->io_logical->io_bookmark.zb_object, 2901544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL, 2914831Sgw25295 DATA_TYPE_INT64, 2921544Seschrock zio->io_logical->io_bookmark.zb_level, 2931544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID, 2941544Seschrock DATA_TYPE_UINT64, 2951955Seschrock zio->io_logical->io_bookmark.zb_blkid, NULL); 2961544Seschrock } else if (vd != NULL) { 2971544Seschrock /* 2981544Seschrock * If we have a vdev but no zio, this is a device fault, and the 2991544Seschrock * 'stateoroffset' parameter indicates the previous state of the 3001544Seschrock * vdev. 3011544Seschrock */ 3021544Seschrock fm_payload_set(ereport, 3031544Seschrock FM_EREPORT_PAYLOAD_ZFS_PREV_STATE, 3041544Seschrock DATA_TYPE_UINT64, stateoroffset, NULL); 3051544Seschrock } 3061544Seschrock mutex_exit(&spa->spa_errlist_lock); 3071544Seschrock 3081544Seschrock fm_ereport_post(ereport, EVCH_SLEEP); 3091544Seschrock 3101544Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 3111544Seschrock fm_nvlist_destroy(detector, FM_NVA_FREE); 3121544Seschrock #endif 3131544Seschrock } 3141544Seschrock 3154451Seschrock static void 3164451Seschrock zfs_post_common(spa_t *spa, vdev_t *vd, const char *name) 3171544Seschrock { 3181544Seschrock #ifdef _KERNEL 3191544Seschrock nvlist_t *resource; 3201544Seschrock char class[64]; 3211544Seschrock 3221544Seschrock if ((resource = fm_nvlist_create(NULL)) == NULL) 3231544Seschrock return; 3241544Seschrock 3251544Seschrock (void) snprintf(class, sizeof (class), "%s.%s.%s", FM_RSRC_RESOURCE, 3264451Seschrock ZFS_ERROR_CLASS, name); 3271544Seschrock VERIFY(nvlist_add_uint8(resource, FM_VERSION, FM_RSRC_VERSION) == 0); 3281544Seschrock VERIFY(nvlist_add_string(resource, FM_CLASS, class) == 0); 3291544Seschrock VERIFY(nvlist_add_uint64(resource, 3301544Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, spa_guid(spa)) == 0); 3311544Seschrock if (vd) 3321544Seschrock VERIFY(nvlist_add_uint64(resource, 3331544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, vd->vdev_guid) == 0); 3341544Seschrock 3351544Seschrock fm_ereport_post(resource, EVCH_SLEEP); 3361544Seschrock 3371544Seschrock fm_nvlist_destroy(resource, FM_NVA_FREE); 3381544Seschrock #endif 3391544Seschrock } 3404451Seschrock 3414451Seschrock /* 3424451Seschrock * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev 3434451Seschrock * has been removed from the system. This will cause the DE to ignore any 3444451Seschrock * recent I/O errors, inferring that they are due to the asynchronous device 3454451Seschrock * removal. 3464451Seschrock */ 3474451Seschrock void 3484451Seschrock zfs_post_remove(spa_t *spa, vdev_t *vd) 3494451Seschrock { 3504451Seschrock zfs_post_common(spa, vd, FM_RESOURCE_REMOVED); 3514451Seschrock } 3524451Seschrock 3534451Seschrock /* 3544451Seschrock * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool 3554451Seschrock * has the 'autoreplace' property set, and therefore any broken vdevs will be 3564451Seschrock * handled by higher level logic, and no vdev fault should be generated. 3574451Seschrock */ 3584451Seschrock void 3594451Seschrock zfs_post_autoreplace(spa_t *spa, vdev_t *vd) 3604451Seschrock { 3614451Seschrock zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE); 3624451Seschrock } 363