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 /* 229425SEric.Schrock@Sun.COM * Copyright 2009 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 867754SJeff.Bonwick@Sun.COM * will use the same ENA. For vdev cache fill and queue aggregation I/O, 877754SJeff.Bonwick@Sun.COM * this pointer is set to NULL, and no ereport will be generated (since it 887754SJeff.Bonwick@Sun.COM * doesn't actually correspond to any particular device or piece of data, 897754SJeff.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]; 991544Seschrock 1001544Seschrock /* 1011544Seschrock * If we are doing a spa_tryimport(), ignore errors. 1021544Seschrock */ 1031544Seschrock if (spa->spa_load_state == SPA_LOAD_TRYIMPORT) 1041544Seschrock return; 1051544Seschrock 1061544Seschrock /* 1071544Seschrock * If we are in the middle of opening a pool, and the previous attempt 1081544Seschrock * failed, don't bother logging any new ereports - we're just going to 1091544Seschrock * get the same diagnosis anyway. 1101544Seschrock */ 1111544Seschrock if (spa->spa_load_state != SPA_LOAD_NONE && 1121544Seschrock spa->spa_last_open_failed) 1131544Seschrock return; 1141544Seschrock 1156673Seschrock if (zio != NULL) { 1166673Seschrock /* 1176673Seschrock * If this is not a read or write zio, ignore the error. This 1186673Seschrock * can occur if the DKIOCFLUSHWRITECACHE ioctl fails. 1196673Seschrock */ 1206673Seschrock if (zio->io_type != ZIO_TYPE_READ && 1216673Seschrock zio->io_type != ZIO_TYPE_WRITE) 1226673Seschrock return; 1236673Seschrock 1246673Seschrock /* 1256673Seschrock * Ignore any errors from speculative I/Os, as failure is an 1266673Seschrock * expected result. 1276673Seschrock */ 1286673Seschrock if (zio->io_flags & ZIO_FLAG_SPECULATIVE) 1296673Seschrock return; 1306976Seschrock 1319725SEric.Schrock@Sun.COM /* 1329725SEric.Schrock@Sun.COM * If this I/O is not a retry I/O, don't post an ereport. 1339725SEric.Schrock@Sun.COM * Otherwise, we risk making bad diagnoses based on B_FAILFAST 1349725SEric.Schrock@Sun.COM * I/Os. 1359725SEric.Schrock@Sun.COM */ 1369725SEric.Schrock@Sun.COM if (zio->io_error == EIO && 1379725SEric.Schrock@Sun.COM !(zio->io_flags & ZIO_FLAG_IO_RETRY)) 1389725SEric.Schrock@Sun.COM return; 1399725SEric.Schrock@Sun.COM 1409425SEric.Schrock@Sun.COM if (vd != NULL) { 1419425SEric.Schrock@Sun.COM /* 1429425SEric.Schrock@Sun.COM * If the vdev has already been marked as failing due 1439425SEric.Schrock@Sun.COM * to a failed probe, then ignore any subsequent I/O 1449425SEric.Schrock@Sun.COM * errors, as the DE will automatically fault the vdev 1459425SEric.Schrock@Sun.COM * on the first such failure. This also catches cases 1469425SEric.Schrock@Sun.COM * where vdev_remove_wanted is set and the device has 1479425SEric.Schrock@Sun.COM * not yet been asynchronously placed into the REMOVED 1489425SEric.Schrock@Sun.COM * state. 1499425SEric.Schrock@Sun.COM */ 150*10575SEric.Schrock@Sun.COM if (zio->io_vd == vd && !vdev_accessible(vd, zio)) 1519425SEric.Schrock@Sun.COM return; 1529425SEric.Schrock@Sun.COM 1539425SEric.Schrock@Sun.COM /* 1549425SEric.Schrock@Sun.COM * Ignore checksum errors for reads from DTL regions of 1559425SEric.Schrock@Sun.COM * leaf vdevs. 1569425SEric.Schrock@Sun.COM */ 1579425SEric.Schrock@Sun.COM if (zio->io_type == ZIO_TYPE_READ && 1589425SEric.Schrock@Sun.COM zio->io_error == ECKSUM && 1599425SEric.Schrock@Sun.COM vd->vdev_ops->vdev_op_leaf && 1609425SEric.Schrock@Sun.COM vdev_dtl_contains(vd, DTL_MISSING, zio->io_txg, 1)) 1619425SEric.Schrock@Sun.COM return; 1629425SEric.Schrock@Sun.COM } 1636673Seschrock } 1641773Seschrock 165*10575SEric.Schrock@Sun.COM /* 166*10575SEric.Schrock@Sun.COM * For probe failure, we want to avoid posting ereports if we've 167*10575SEric.Schrock@Sun.COM * already removed the device in the meantime. 168*10575SEric.Schrock@Sun.COM */ 169*10575SEric.Schrock@Sun.COM if (vd != NULL && 170*10575SEric.Schrock@Sun.COM strcmp(subclass, FM_EREPORT_ZFS_PROBE_FAILURE) == 0 && 171*10575SEric.Schrock@Sun.COM (vd->vdev_remove_wanted || vd->vdev_state == VDEV_STATE_REMOVED)) 172*10575SEric.Schrock@Sun.COM return; 173*10575SEric.Schrock@Sun.COM 1741544Seschrock if ((ereport = fm_nvlist_create(NULL)) == NULL) 1751544Seschrock return; 1761544Seschrock 1771544Seschrock if ((detector = fm_nvlist_create(NULL)) == NULL) { 1781544Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 1791544Seschrock return; 1801544Seschrock } 1811544Seschrock 1821544Seschrock /* 1831544Seschrock * Serialize ereport generation 1841544Seschrock */ 1851544Seschrock mutex_enter(&spa->spa_errlist_lock); 1861544Seschrock 1871544Seschrock /* 1881544Seschrock * Determine the ENA to use for this event. If we are in a loading 1891544Seschrock * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use 1901544Seschrock * a root zio-wide ENA. Otherwise, simply use a unique ENA. 1911544Seschrock */ 1921544Seschrock if (spa->spa_load_state != SPA_LOAD_NONE) { 1931544Seschrock if (spa->spa_ena == 0) 1941544Seschrock spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1); 1951544Seschrock ena = spa->spa_ena; 1961544Seschrock } else if (zio != NULL && zio->io_logical != NULL) { 1971544Seschrock if (zio->io_logical->io_ena == 0) 1981544Seschrock zio->io_logical->io_ena = 1991544Seschrock fm_ena_generate(0, FM_ENA_FMT1); 2001544Seschrock ena = zio->io_logical->io_ena; 2011544Seschrock } else { 2021544Seschrock ena = fm_ena_generate(0, FM_ENA_FMT1); 2031544Seschrock } 2041544Seschrock 2051544Seschrock /* 2061544Seschrock * Construct the full class, detector, and other standard FMA fields. 2071544Seschrock */ 2081544Seschrock (void) snprintf(class, sizeof (class), "%s.%s", 2091544Seschrock ZFS_ERROR_CLASS, subclass); 2101544Seschrock 2111544Seschrock fm_fmri_zfs_set(detector, FM_ZFS_SCHEME_VERSION, spa_guid(spa), 2121544Seschrock vd != NULL ? vd->vdev_guid : 0); 2131544Seschrock 2141544Seschrock fm_ereport_set(ereport, FM_EREPORT_VERSION, class, ena, detector, NULL); 2151544Seschrock 2161544Seschrock /* 2171544Seschrock * Construct the per-ereport payload, depending on which parameters are 2181544Seschrock * passed in. 2191544Seschrock */ 2201544Seschrock 2211544Seschrock /* 2221544Seschrock * Generic payload members common to all ereports. 2231544Seschrock */ 2241544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL, 2257754SJeff.Bonwick@Sun.COM DATA_TYPE_STRING, spa_name(spa), FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, 2261544Seschrock DATA_TYPE_UINT64, spa_guid(spa), 2271544Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, DATA_TYPE_INT32, 2289425SEric.Schrock@Sun.COM spa->spa_load_state, NULL); 2291544Seschrock 2306523Sek110237 if (spa != NULL) { 2316523Sek110237 fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE, 2326523Sek110237 DATA_TYPE_STRING, 2336523Sek110237 spa_get_failmode(spa) == ZIO_FAILURE_MODE_WAIT ? 2346523Sek110237 FM_EREPORT_FAILMODE_WAIT : 2356523Sek110237 spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE ? 2366523Sek110237 FM_EREPORT_FAILMODE_CONTINUE : FM_EREPORT_FAILMODE_PANIC, 2376523Sek110237 NULL); 2386523Sek110237 } 2396523Sek110237 2401544Seschrock if (vd != NULL) { 2411544Seschrock vdev_t *pvd = vd->vdev_parent; 2421544Seschrock 2431544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, 2441544Seschrock DATA_TYPE_UINT64, vd->vdev_guid, 2451544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE, 2461544Seschrock DATA_TYPE_STRING, vd->vdev_ops->vdev_op_type, NULL); 2479425SEric.Schrock@Sun.COM if (vd->vdev_path != NULL) 2481544Seschrock fm_payload_set(ereport, 2491544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, 2501544Seschrock DATA_TYPE_STRING, vd->vdev_path, NULL); 2519425SEric.Schrock@Sun.COM if (vd->vdev_devid != NULL) 2521544Seschrock fm_payload_set(ereport, 2531544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, 2541544Seschrock DATA_TYPE_STRING, vd->vdev_devid, NULL); 2559425SEric.Schrock@Sun.COM if (vd->vdev_fru != NULL) 2569425SEric.Schrock@Sun.COM fm_payload_set(ereport, 2579425SEric.Schrock@Sun.COM FM_EREPORT_PAYLOAD_ZFS_VDEV_FRU, 2589425SEric.Schrock@Sun.COM DATA_TYPE_STRING, vd->vdev_fru, NULL); 2591544Seschrock 2601544Seschrock if (pvd != NULL) { 2611544Seschrock fm_payload_set(ereport, 2621544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, 2631544Seschrock DATA_TYPE_UINT64, pvd->vdev_guid, 2641544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE, 2651544Seschrock DATA_TYPE_STRING, pvd->vdev_ops->vdev_op_type, 2661544Seschrock NULL); 2671544Seschrock if (pvd->vdev_path) 2681544Seschrock fm_payload_set(ereport, 2691544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH, 2704831Sgw25295 DATA_TYPE_STRING, pvd->vdev_path, NULL); 2711544Seschrock if (pvd->vdev_devid) 2721544Seschrock fm_payload_set(ereport, 2731544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID, 2741544Seschrock DATA_TYPE_STRING, pvd->vdev_devid, NULL); 2751544Seschrock } 2761544Seschrock } 2771544Seschrock 2781544Seschrock if (zio != NULL) { 2791544Seschrock /* 2801544Seschrock * Payload common to all I/Os. 2811544Seschrock */ 2821544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR, 2831544Seschrock DATA_TYPE_INT32, zio->io_error, NULL); 2841544Seschrock 2851544Seschrock /* 2861544Seschrock * If the 'size' parameter is non-zero, it indicates this is a 2871544Seschrock * RAID-Z or other I/O where the physical offset and length are 2881544Seschrock * provided for us, instead of within the zio_t. 2891544Seschrock */ 2901544Seschrock if (vd != NULL) { 2911544Seschrock if (size) 2921544Seschrock fm_payload_set(ereport, 2931544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 2941544Seschrock DATA_TYPE_UINT64, stateoroffset, 2951544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 2961955Seschrock DATA_TYPE_UINT64, size, NULL); 2971544Seschrock else 2981544Seschrock fm_payload_set(ereport, 2991544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 3001544Seschrock DATA_TYPE_UINT64, zio->io_offset, 3011544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 3021955Seschrock DATA_TYPE_UINT64, zio->io_size, NULL); 3031544Seschrock } 3041544Seschrock 3051544Seschrock /* 3061544Seschrock * Payload for I/Os with corresponding logical information. 3071544Seschrock */ 3081544Seschrock if (zio->io_logical != NULL) 3091544Seschrock fm_payload_set(ereport, 3106423Sgw25295 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET, 3116423Sgw25295 DATA_TYPE_UINT64, 3126423Sgw25295 zio->io_logical->io_bookmark.zb_objset, 3131544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT, 3141544Seschrock DATA_TYPE_UINT64, 3151544Seschrock zio->io_logical->io_bookmark.zb_object, 3161544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL, 3174831Sgw25295 DATA_TYPE_INT64, 3181544Seschrock zio->io_logical->io_bookmark.zb_level, 3191544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID, 3201544Seschrock DATA_TYPE_UINT64, 3211955Seschrock zio->io_logical->io_bookmark.zb_blkid, NULL); 3221544Seschrock } else if (vd != NULL) { 3231544Seschrock /* 3241544Seschrock * If we have a vdev but no zio, this is a device fault, and the 3251544Seschrock * 'stateoroffset' parameter indicates the previous state of the 3261544Seschrock * vdev. 3271544Seschrock */ 3281544Seschrock fm_payload_set(ereport, 3291544Seschrock FM_EREPORT_PAYLOAD_ZFS_PREV_STATE, 3301544Seschrock DATA_TYPE_UINT64, stateoroffset, NULL); 3311544Seschrock } 3321544Seschrock mutex_exit(&spa->spa_errlist_lock); 3331544Seschrock 3341544Seschrock fm_ereport_post(ereport, EVCH_SLEEP); 3351544Seschrock 3361544Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 3371544Seschrock fm_nvlist_destroy(detector, FM_NVA_FREE); 3381544Seschrock #endif 3391544Seschrock } 3401544Seschrock 3414451Seschrock static void 3424451Seschrock zfs_post_common(spa_t *spa, vdev_t *vd, const char *name) 3431544Seschrock { 3441544Seschrock #ifdef _KERNEL 3451544Seschrock nvlist_t *resource; 3461544Seschrock char class[64]; 3471544Seschrock 348*10575SEric.Schrock@Sun.COM if (spa->spa_load_state == SPA_LOAD_TRYIMPORT) 349*10575SEric.Schrock@Sun.COM return; 350*10575SEric.Schrock@Sun.COM 3511544Seschrock if ((resource = fm_nvlist_create(NULL)) == NULL) 3521544Seschrock return; 3531544Seschrock 3541544Seschrock (void) snprintf(class, sizeof (class), "%s.%s.%s", FM_RSRC_RESOURCE, 3554451Seschrock ZFS_ERROR_CLASS, name); 3561544Seschrock VERIFY(nvlist_add_uint8(resource, FM_VERSION, FM_RSRC_VERSION) == 0); 3571544Seschrock VERIFY(nvlist_add_string(resource, FM_CLASS, class) == 0); 3581544Seschrock VERIFY(nvlist_add_uint64(resource, 3591544Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, spa_guid(spa)) == 0); 3601544Seschrock if (vd) 3611544Seschrock VERIFY(nvlist_add_uint64(resource, 3621544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, vd->vdev_guid) == 0); 3631544Seschrock 3641544Seschrock fm_ereport_post(resource, EVCH_SLEEP); 3651544Seschrock 3661544Seschrock fm_nvlist_destroy(resource, FM_NVA_FREE); 3671544Seschrock #endif 3681544Seschrock } 3694451Seschrock 3704451Seschrock /* 3714451Seschrock * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev 3724451Seschrock * has been removed from the system. This will cause the DE to ignore any 3734451Seschrock * recent I/O errors, inferring that they are due to the asynchronous device 3744451Seschrock * removal. 3754451Seschrock */ 3764451Seschrock void 3774451Seschrock zfs_post_remove(spa_t *spa, vdev_t *vd) 3784451Seschrock { 3794451Seschrock zfs_post_common(spa, vd, FM_RESOURCE_REMOVED); 3804451Seschrock } 3814451Seschrock 3824451Seschrock /* 3834451Seschrock * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool 3844451Seschrock * has the 'autoreplace' property set, and therefore any broken vdevs will be 3854451Seschrock * handled by higher level logic, and no vdev fault should be generated. 3864451Seschrock */ 3874451Seschrock void 3884451Seschrock zfs_post_autoreplace(spa_t *spa, vdev_t *vd) 3894451Seschrock { 3904451Seschrock zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE); 3914451Seschrock } 392