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 /* 221544Seschrock * Copyright 2006 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 1201544Seschrock * only generate errors from the final failure. 1211544Seschrock */ 1221544Seschrock if (zio && zio_should_retry(zio)) 1231544Seschrock return; 1241544Seschrock 1251773Seschrock /* 1261773Seschrock * If this is not a read or write zio, ignore the error. This can occur 1271773Seschrock * if the DKIOCFLUSHWRITECACHE ioctl fails. 1281773Seschrock */ 1291773Seschrock if (zio && zio->io_type != ZIO_TYPE_READ && 1301773Seschrock zio->io_type != ZIO_TYPE_WRITE) 1311773Seschrock return; 1321773Seschrock 1331544Seschrock if ((ereport = fm_nvlist_create(NULL)) == NULL) 1341544Seschrock return; 1351544Seschrock 1361544Seschrock if ((detector = fm_nvlist_create(NULL)) == NULL) { 1371544Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 1381544Seschrock return; 1391544Seschrock } 1401544Seschrock 1411544Seschrock /* 1421544Seschrock * Serialize ereport generation 1431544Seschrock */ 1441544Seschrock mutex_enter(&spa->spa_errlist_lock); 1451544Seschrock 1461544Seschrock /* 1471544Seschrock * Determine the ENA to use for this event. If we are in a loading 1481544Seschrock * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use 1491544Seschrock * a root zio-wide ENA. Otherwise, simply use a unique ENA. 1501544Seschrock */ 1511544Seschrock if (spa->spa_load_state != SPA_LOAD_NONE) { 1521544Seschrock if (spa->spa_ena == 0) 1531544Seschrock spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1); 1541544Seschrock ena = spa->spa_ena; 1551544Seschrock } else if (zio != NULL && zio->io_logical != NULL) { 1561544Seschrock if (zio->io_logical->io_ena == 0) 1571544Seschrock zio->io_logical->io_ena = 1581544Seschrock fm_ena_generate(0, FM_ENA_FMT1); 1591544Seschrock ena = zio->io_logical->io_ena; 1601544Seschrock } else { 1611544Seschrock ena = fm_ena_generate(0, FM_ENA_FMT1); 1621544Seschrock } 1631544Seschrock 1641544Seschrock /* 1651544Seschrock * Construct the full class, detector, and other standard FMA fields. 1661544Seschrock */ 1671544Seschrock (void) snprintf(class, sizeof (class), "%s.%s", 1681544Seschrock ZFS_ERROR_CLASS, subclass); 1691544Seschrock 1701544Seschrock fm_fmri_zfs_set(detector, FM_ZFS_SCHEME_VERSION, spa_guid(spa), 1711544Seschrock vd != NULL ? vd->vdev_guid : 0); 1721544Seschrock 1731544Seschrock fm_ereport_set(ereport, FM_EREPORT_VERSION, class, ena, detector, NULL); 1741544Seschrock 1751544Seschrock /* 1761544Seschrock * Construct the per-ereport payload, depending on which parameters are 1771544Seschrock * passed in. 1781544Seschrock */ 1791544Seschrock 1801544Seschrock /* 1811544Seschrock * Generic payload members common to all ereports. 1821544Seschrock * 1831544Seschrock * The direct reference to spa_name is used rather than spa_name() 1841544Seschrock * because of the asynchronous nature of the zio pipeline. spa_name() 1851544Seschrock * asserts that the config lock is held in some form. This is always 1861544Seschrock * the case in I/O context, but because the check for RW_WRITER compares 1871544Seschrock * against 'curthread', we may be in an asynchronous context and blow 1881544Seschrock * this assert. Rather than loosen this assert, we acknowledge that all 1891544Seschrock * contexts in which this function is called (pool open, I/O) are safe, 1901544Seschrock * and dereference the name directly. 1911544Seschrock */ 1921544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL, 1931544Seschrock DATA_TYPE_STRING, spa->spa_name, FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, 1941544Seschrock DATA_TYPE_UINT64, spa_guid(spa), 1951544Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, DATA_TYPE_INT32, 1961544Seschrock spa->spa_load_state, NULL); 1971544Seschrock 1981544Seschrock if (vd != NULL) { 1991544Seschrock vdev_t *pvd = vd->vdev_parent; 2001544Seschrock 2011544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, 2021544Seschrock DATA_TYPE_UINT64, vd->vdev_guid, 2031544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE, 2041544Seschrock DATA_TYPE_STRING, vd->vdev_ops->vdev_op_type, NULL); 2051544Seschrock if (vd->vdev_path) 2061544Seschrock fm_payload_set(ereport, 2071544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, 2081544Seschrock DATA_TYPE_STRING, vd->vdev_path, NULL); 2091544Seschrock if (vd->vdev_devid) 2101544Seschrock fm_payload_set(ereport, 2111544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, 2121544Seschrock DATA_TYPE_STRING, vd->vdev_devid, NULL); 2131544Seschrock 2141544Seschrock if (pvd != NULL) { 2151544Seschrock fm_payload_set(ereport, 2161544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, 2171544Seschrock DATA_TYPE_UINT64, pvd->vdev_guid, 2181544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE, 2191544Seschrock DATA_TYPE_STRING, pvd->vdev_ops->vdev_op_type, 2201544Seschrock NULL); 2211544Seschrock if (pvd->vdev_path) 2221544Seschrock fm_payload_set(ereport, 2231544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH, 2241544Seschrock DATA_TYPE_STRING, vd->vdev_path, NULL); 2251544Seschrock if (pvd->vdev_devid) 2261544Seschrock fm_payload_set(ereport, 2271544Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID, 2281544Seschrock DATA_TYPE_STRING, pvd->vdev_devid, NULL); 2291544Seschrock } 2301544Seschrock } 2311544Seschrock 2321544Seschrock if (zio != NULL) { 2331544Seschrock /* 2341544Seschrock * Payload common to all I/Os. 2351544Seschrock */ 2361544Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR, 2371544Seschrock DATA_TYPE_INT32, zio->io_error, NULL); 2381544Seschrock 2391544Seschrock /* 2401544Seschrock * If the 'size' parameter is non-zero, it indicates this is a 2411544Seschrock * RAID-Z or other I/O where the physical offset and length are 2421544Seschrock * provided for us, instead of within the zio_t. 2431544Seschrock */ 2441544Seschrock if (vd != NULL) { 2451544Seschrock if (size) 2461544Seschrock fm_payload_set(ereport, 2471544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 2481544Seschrock DATA_TYPE_UINT64, stateoroffset, 2491544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 250*1955Seschrock DATA_TYPE_UINT64, size, NULL); 2511544Seschrock else 2521544Seschrock fm_payload_set(ereport, 2531544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 2541544Seschrock DATA_TYPE_UINT64, zio->io_offset, 2551544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 256*1955Seschrock DATA_TYPE_UINT64, zio->io_size, NULL); 2571544Seschrock } 2581544Seschrock 2591544Seschrock /* 2601544Seschrock * Payload for I/Os with corresponding logical information. 2611544Seschrock */ 2621544Seschrock if (zio->io_logical != NULL) 2631544Seschrock fm_payload_set(ereport, 2641544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET, 2651544Seschrock DATA_TYPE_UINT64, 2661544Seschrock zio->io_logical->io_bookmark.zb_objset, 2671544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT, 2681544Seschrock DATA_TYPE_UINT64, 2691544Seschrock zio->io_logical->io_bookmark.zb_object, 2701544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL, 2711544Seschrock DATA_TYPE_INT32, 2721544Seschrock zio->io_logical->io_bookmark.zb_level, 2731544Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID, 2741544Seschrock DATA_TYPE_UINT64, 275*1955Seschrock zio->io_logical->io_bookmark.zb_blkid, NULL); 2761544Seschrock } else if (vd != NULL) { 2771544Seschrock /* 2781544Seschrock * If we have a vdev but no zio, this is a device fault, and the 2791544Seschrock * 'stateoroffset' parameter indicates the previous state of the 2801544Seschrock * vdev. 2811544Seschrock */ 2821544Seschrock fm_payload_set(ereport, 2831544Seschrock FM_EREPORT_PAYLOAD_ZFS_PREV_STATE, 2841544Seschrock DATA_TYPE_UINT64, stateoroffset, NULL); 2851544Seschrock } 2861544Seschrock mutex_exit(&spa->spa_errlist_lock); 2871544Seschrock 2881544Seschrock fm_ereport_post(ereport, EVCH_SLEEP); 2891544Seschrock 2901544Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 2911544Seschrock fm_nvlist_destroy(detector, FM_NVA_FREE); 2921544Seschrock #endif 2931544Seschrock } 2941544Seschrock 2951544Seschrock /* 2961544Seschrock * The 'resource.fs.zfs.ok' event is an internal signal that the associated 2971544Seschrock * resource (pool or disk) has been identified by ZFS as healthy. This will 2981544Seschrock * then trigger the DE to close the associated case, if any. 2991544Seschrock */ 3001544Seschrock void 3011544Seschrock zfs_post_ok(spa_t *spa, vdev_t *vd) 3021544Seschrock { 3031544Seschrock #ifdef _KERNEL 3041544Seschrock nvlist_t *resource; 3051544Seschrock char class[64]; 3061544Seschrock 3071544Seschrock if ((resource = fm_nvlist_create(NULL)) == NULL) 3081544Seschrock return; 3091544Seschrock 3101544Seschrock (void) snprintf(class, sizeof (class), "%s.%s.%s", FM_RSRC_RESOURCE, 3111544Seschrock ZFS_ERROR_CLASS, FM_RESOURCE_OK); 3121544Seschrock VERIFY(nvlist_add_uint8(resource, FM_VERSION, FM_RSRC_VERSION) == 0); 3131544Seschrock VERIFY(nvlist_add_string(resource, FM_CLASS, class) == 0); 3141544Seschrock VERIFY(nvlist_add_uint64(resource, 3151544Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, spa_guid(spa)) == 0); 3161544Seschrock if (vd) 3171544Seschrock VERIFY(nvlist_add_uint64(resource, 3181544Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, vd->vdev_guid) == 0); 3191544Seschrock 3201544Seschrock fm_ereport_post(resource, EVCH_SLEEP); 3211544Seschrock 3221544Seschrock fm_nvlist_destroy(resource, FM_NVA_FREE); 3231544Seschrock #endif 3241544Seschrock } 325