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 /* 22*9425SEric.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 131*9425SEric.Schrock@Sun.COM if (vd != NULL) { 132*9425SEric.Schrock@Sun.COM /* 133*9425SEric.Schrock@Sun.COM * If the vdev has already been marked as failing due 134*9425SEric.Schrock@Sun.COM * to a failed probe, then ignore any subsequent I/O 135*9425SEric.Schrock@Sun.COM * errors, as the DE will automatically fault the vdev 136*9425SEric.Schrock@Sun.COM * on the first such failure. This also catches cases 137*9425SEric.Schrock@Sun.COM * where vdev_remove_wanted is set and the device has 138*9425SEric.Schrock@Sun.COM * not yet been asynchronously placed into the REMOVED 139*9425SEric.Schrock@Sun.COM * state. 140*9425SEric.Schrock@Sun.COM */ 141*9425SEric.Schrock@Sun.COM if (zio->io_vd == vd && 142*9425SEric.Schrock@Sun.COM !vdev_accessible(vd, zio) && 143*9425SEric.Schrock@Sun.COM strcmp(subclass, FM_EREPORT_ZFS_PROBE_FAILURE) != 0) 144*9425SEric.Schrock@Sun.COM return; 145*9425SEric.Schrock@Sun.COM 146*9425SEric.Schrock@Sun.COM /* 147*9425SEric.Schrock@Sun.COM * Ignore checksum errors for reads from DTL regions of 148*9425SEric.Schrock@Sun.COM * leaf vdevs. 149*9425SEric.Schrock@Sun.COM */ 150*9425SEric.Schrock@Sun.COM if (zio->io_type == ZIO_TYPE_READ && 151*9425SEric.Schrock@Sun.COM zio->io_error == ECKSUM && 152*9425SEric.Schrock@Sun.COM vd->vdev_ops->vdev_op_leaf && 153*9425SEric.Schrock@Sun.COM vdev_dtl_contains(vd, DTL_MISSING, zio->io_txg, 1)) 154*9425SEric.Schrock@Sun.COM return; 155*9425SEric.Schrock@Sun.COM } 1566673Seschrock } 1571773Seschrock 1581544Seschrock if ((ereport = fm_nvlist_create(NULL)) == NULL) 1591544Seschrock return; 1601544Seschrock 1611544Seschrock if ((detector = fm_nvlist_create(NULL)) == NULL) { 1621544Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 1631544Seschrock return; 1641544Seschrock } 1651544Seschrock 1661544Seschrock /* 1671544Seschrock * Serialize ereport generation 1681544Seschrock */ 1691544Seschrock mutex_enter(&spa->spa_errlist_lock); 1701544Seschrock 1711544Seschrock /* 1721544Seschrock * Determine the ENA to use for this event. If we are in a loading 1731544Seschrock * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use 1741544Seschrock * a root zio-wide ENA. Otherwise, simply use a unique ENA. 1751544Seschrock */ 1761544Seschrock if (spa->spa_load_state != SPA_LOAD_NONE) { 1771544Seschrock if (spa->spa_ena == 0) 1781544Seschrock spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1); 1791544Seschrock ena = spa->spa_ena; 1801544Seschrock } else if (zio != NULL && zio->io_logical != NULL) { 1811544Seschrock if (zio->io_logical->io_ena == 0) 1821544Seschrock zio->io_logical->io_ena = 1831544Seschrock fm_ena_generate(0, FM_ENA_FMT1); 1841544Seschrock ena = zio->io_logical->io_ena; 1851544Seschrock } else { 1861544Seschrock ena = fm_ena_generate(0, FM_ENA_FMT1); 1871544Seschrock } 1881544Seschrock 1891544Seschrock /* 1901544Seschrock * Construct the full class, detector, and other standard FMA fields. 1911544Seschrock */ 1921544Seschrock (void) snprintf(class, sizeof (class), "%s.%s", 1931544Seschrock ZFS_ERROR_CLASS, subclass); 1941544Seschrock 1951544Seschrock fm_fmri_zfs_set(detector, FM_ZFS_SCHEME_VERSION, spa_guid(spa), 1961544Seschrock vd != NULL ? vd->vdev_guid : 0); 1971544Seschrock 1981544Seschrock fm_ereport_set(ereport, FM_EREPORT_VERSION, class, ena, detector, NULL); 1991544Seschrock 2001544Seschrock /* 2011544Seschrock * Construct the per-ereport payload, depending on which parameters are 2021544Seschrock * passed in. 2031544Seschrock */ 2041544Seschrock 2051544Seschrock /* 2061544Seschrock * Generic payload members common to all ereports. 2071544Seschrock */ 2081544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL, 2097754SJeff.Bonwick@Sun.COM DATA_TYPE_STRING, spa_name(spa), FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, 2101544Seschrock DATA_TYPE_UINT64, spa_guid(spa), 2111544Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, DATA_TYPE_INT32, 212*9425SEric.Schrock@Sun.COM spa->spa_load_state, NULL); 2131544Seschrock 2146523Sek110237 if (spa != NULL) { 2156523Sek110237 fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE, 2166523Sek110237 DATA_TYPE_STRING, 2176523Sek110237 spa_get_failmode(spa) == ZIO_FAILURE_MODE_WAIT ? 2186523Sek110237 FM_EREPORT_FAILMODE_WAIT : 2196523Sek110237 spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE ? 2206523Sek110237 FM_EREPORT_FAILMODE_CONTINUE : FM_EREPORT_FAILMODE_PANIC, 2216523Sek110237 NULL); 2226523Sek110237 } 2236523Sek110237 2241544Seschrock if (vd != NULL) { 2251544Seschrock vdev_t *pvd = vd->vdev_parent; 2261544Seschrock 2271544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, 2281544Seschrock DATA_TYPE_UINT64, vd->vdev_guid, 2291544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE, 2301544Seschrock DATA_TYPE_STRING, vd->vdev_ops->vdev_op_type, NULL); 231*9425SEric.Schrock@Sun.COM if (vd->vdev_path != NULL) 2321544Seschrock fm_payload_set(ereport, 2331544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, 2341544Seschrock DATA_TYPE_STRING, vd->vdev_path, NULL); 235*9425SEric.Schrock@Sun.COM if (vd->vdev_devid != NULL) 2361544Seschrock fm_payload_set(ereport, 2371544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, 2381544Seschrock DATA_TYPE_STRING, vd->vdev_devid, NULL); 239*9425SEric.Schrock@Sun.COM if (vd->vdev_fru != NULL) 240*9425SEric.Schrock@Sun.COM fm_payload_set(ereport, 241*9425SEric.Schrock@Sun.COM FM_EREPORT_PAYLOAD_ZFS_VDEV_FRU, 242*9425SEric.Schrock@Sun.COM DATA_TYPE_STRING, vd->vdev_fru, NULL); 2431544Seschrock 2441544Seschrock if (pvd != NULL) { 2451544Seschrock fm_payload_set(ereport, 2461544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, 2471544Seschrock DATA_TYPE_UINT64, pvd->vdev_guid, 2481544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE, 2491544Seschrock DATA_TYPE_STRING, pvd->vdev_ops->vdev_op_type, 2501544Seschrock NULL); 2511544Seschrock if (pvd->vdev_path) 2521544Seschrock fm_payload_set(ereport, 2531544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH, 2544831Sgw25295 DATA_TYPE_STRING, pvd->vdev_path, NULL); 2551544Seschrock if (pvd->vdev_devid) 2561544Seschrock fm_payload_set(ereport, 2571544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID, 2581544Seschrock DATA_TYPE_STRING, pvd->vdev_devid, NULL); 2591544Seschrock } 2601544Seschrock } 2611544Seschrock 2621544Seschrock if (zio != NULL) { 2631544Seschrock /* 2641544Seschrock * Payload common to all I/Os. 2651544Seschrock */ 2661544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR, 2671544Seschrock DATA_TYPE_INT32, zio->io_error, NULL); 2681544Seschrock 2691544Seschrock /* 2701544Seschrock * If the 'size' parameter is non-zero, it indicates this is a 2711544Seschrock * RAID-Z or other I/O where the physical offset and length are 2721544Seschrock * provided for us, instead of within the zio_t. 2731544Seschrock */ 2741544Seschrock if (vd != NULL) { 2751544Seschrock if (size) 2761544Seschrock fm_payload_set(ereport, 2771544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 2781544Seschrock DATA_TYPE_UINT64, stateoroffset, 2791544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 2801955Seschrock DATA_TYPE_UINT64, size, NULL); 2811544Seschrock else 2821544Seschrock fm_payload_set(ereport, 2831544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 2841544Seschrock DATA_TYPE_UINT64, zio->io_offset, 2851544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 2861955Seschrock DATA_TYPE_UINT64, zio->io_size, NULL); 2871544Seschrock } 2881544Seschrock 2891544Seschrock /* 2901544Seschrock * Payload for I/Os with corresponding logical information. 2911544Seschrock */ 2921544Seschrock if (zio->io_logical != NULL) 2931544Seschrock fm_payload_set(ereport, 2946423Sgw25295 FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET, 2956423Sgw25295 DATA_TYPE_UINT64, 2966423Sgw25295 zio->io_logical->io_bookmark.zb_objset, 2971544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT, 2981544Seschrock DATA_TYPE_UINT64, 2991544Seschrock zio->io_logical->io_bookmark.zb_object, 3001544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL, 3014831Sgw25295 DATA_TYPE_INT64, 3021544Seschrock zio->io_logical->io_bookmark.zb_level, 3031544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID, 3041544Seschrock DATA_TYPE_UINT64, 3051955Seschrock zio->io_logical->io_bookmark.zb_blkid, NULL); 3061544Seschrock } else if (vd != NULL) { 3071544Seschrock /* 3081544Seschrock * If we have a vdev but no zio, this is a device fault, and the 3091544Seschrock * 'stateoroffset' parameter indicates the previous state of the 3101544Seschrock * vdev. 3111544Seschrock */ 3121544Seschrock fm_payload_set(ereport, 3131544Seschrock FM_EREPORT_PAYLOAD_ZFS_PREV_STATE, 3141544Seschrock DATA_TYPE_UINT64, stateoroffset, NULL); 3151544Seschrock } 3161544Seschrock mutex_exit(&spa->spa_errlist_lock); 3171544Seschrock 3181544Seschrock fm_ereport_post(ereport, EVCH_SLEEP); 3191544Seschrock 3201544Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 3211544Seschrock fm_nvlist_destroy(detector, FM_NVA_FREE); 3221544Seschrock #endif 3231544Seschrock } 3241544Seschrock 3254451Seschrock static void 3264451Seschrock zfs_post_common(spa_t *spa, vdev_t *vd, const char *name) 3271544Seschrock { 3281544Seschrock #ifdef _KERNEL 3291544Seschrock nvlist_t *resource; 3301544Seschrock char class[64]; 3311544Seschrock 3321544Seschrock if ((resource = fm_nvlist_create(NULL)) == NULL) 3331544Seschrock return; 3341544Seschrock 3351544Seschrock (void) snprintf(class, sizeof (class), "%s.%s.%s", FM_RSRC_RESOURCE, 3364451Seschrock ZFS_ERROR_CLASS, name); 3371544Seschrock VERIFY(nvlist_add_uint8(resource, FM_VERSION, FM_RSRC_VERSION) == 0); 3381544Seschrock VERIFY(nvlist_add_string(resource, FM_CLASS, class) == 0); 3391544Seschrock VERIFY(nvlist_add_uint64(resource, 3401544Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, spa_guid(spa)) == 0); 3411544Seschrock if (vd) 3421544Seschrock VERIFY(nvlist_add_uint64(resource, 3431544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, vd->vdev_guid) == 0); 3441544Seschrock 3451544Seschrock fm_ereport_post(resource, EVCH_SLEEP); 3461544Seschrock 3471544Seschrock fm_nvlist_destroy(resource, FM_NVA_FREE); 3481544Seschrock #endif 3491544Seschrock } 3504451Seschrock 3514451Seschrock /* 3524451Seschrock * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev 3534451Seschrock * has been removed from the system. This will cause the DE to ignore any 3544451Seschrock * recent I/O errors, inferring that they are due to the asynchronous device 3554451Seschrock * removal. 3564451Seschrock */ 3574451Seschrock void 3584451Seschrock zfs_post_remove(spa_t *spa, vdev_t *vd) 3594451Seschrock { 3604451Seschrock zfs_post_common(spa, vd, FM_RESOURCE_REMOVED); 3614451Seschrock } 3624451Seschrock 3634451Seschrock /* 3644451Seschrock * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool 3654451Seschrock * has the 'autoreplace' property set, and therefore any broken vdevs will be 3664451Seschrock * handled by higher level logic, and no vdev fault should be generated. 3674451Seschrock */ 3684451Seschrock void 3694451Seschrock zfs_post_autoreplace(spa_t *spa, vdev_t *vd) 3704451Seschrock { 3714451Seschrock zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE); 3724451Seschrock } 373