1ea8dc4b6Seschrock /* 2ea8dc4b6Seschrock * CDDL HEADER START 3ea8dc4b6Seschrock * 4ea8dc4b6Seschrock * The contents of this file are subject to the terms of the 5ea8dc4b6Seschrock * Common Development and Distribution License (the "License"). 6ea8dc4b6Seschrock * You may not use this file except in compliance with the License. 7ea8dc4b6Seschrock * 8ea8dc4b6Seschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9ea8dc4b6Seschrock * or http://www.opensolaris.org/os/licensing. 10ea8dc4b6Seschrock * See the License for the specific language governing permissions 11ea8dc4b6Seschrock * and limitations under the License. 12ea8dc4b6Seschrock * 13ea8dc4b6Seschrock * When distributing Covered Code, include this CDDL HEADER in each 14ea8dc4b6Seschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15ea8dc4b6Seschrock * If applicable, add the following below this CDDL HEADER, with the 16ea8dc4b6Seschrock * fields enclosed by brackets "[]" replaced with your own identifying 17ea8dc4b6Seschrock * information: Portions Copyright [yyyy] [name of copyright owner] 18ea8dc4b6Seschrock * 19ea8dc4b6Seschrock * CDDL HEADER END 20ea8dc4b6Seschrock */ 21ea8dc4b6Seschrock /* 226809eb4eSEric Schrock * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23ea8dc4b6Seschrock * Use is subject to license terms. 24ea8dc4b6Seschrock */ 25ea8dc4b6Seschrock 26cd0837ccSGeorge Wilson /* 27cd0837ccSGeorge Wilson * Copyright (c) 2012 by Delphix. All rights reserved. 28cd0837ccSGeorge Wilson */ 29cd0837ccSGeorge Wilson 30ea8dc4b6Seschrock #include <sys/spa.h> 31ea8dc4b6Seschrock #include <sys/spa_impl.h> 32ea8dc4b6Seschrock #include <sys/vdev.h> 33ea8dc4b6Seschrock #include <sys/vdev_impl.h> 34ea8dc4b6Seschrock #include <sys/zio.h> 3522fe2c88SJonathan Adams #include <sys/zio_checksum.h> 36ea8dc4b6Seschrock 37ea8dc4b6Seschrock #include <sys/fm/fs/zfs.h> 38ea8dc4b6Seschrock #include <sys/fm/protocol.h> 39ea8dc4b6Seschrock #include <sys/fm/util.h> 40ea8dc4b6Seschrock #include <sys/sysevent.h> 41ea8dc4b6Seschrock 42ea8dc4b6Seschrock /* 43ea8dc4b6Seschrock * This general routine is responsible for generating all the different ZFS 44ea8dc4b6Seschrock * ereports. The payload is dependent on the class, and which arguments are 45ea8dc4b6Seschrock * supplied to the function: 46ea8dc4b6Seschrock * 47*5711d393Sloli * EREPORT POOL VDEV IO 48*5711d393Sloli * block X X X 49*5711d393Sloli * data X X 50*5711d393Sloli * device X X 51*5711d393Sloli * pool X 52ea8dc4b6Seschrock * 53ea8dc4b6Seschrock * If we are in a loading state, all errors are chained together by the same 5432b87932Sek * SPA-wide ENA (Error Numeric Association). 55ea8dc4b6Seschrock * 56ea8dc4b6Seschrock * For isolated I/O requests, we get the ENA from the zio_t. The propagation 57ea8dc4b6Seschrock * gets very complicated due to RAID-Z, gang blocks, and vdev caching. We want 58ea8dc4b6Seschrock * to chain together all ereports associated with a logical piece of data. For 59ea8dc4b6Seschrock * read I/Os, there are basically three 'types' of I/O, which form a roughly 60ea8dc4b6Seschrock * layered diagram: 61ea8dc4b6Seschrock * 62ea8dc4b6Seschrock * +---------------+ 63*5711d393Sloli * | Aggregate I/O | No associated logical data or device 64*5711d393Sloli * +---------------+ 65ea8dc4b6Seschrock * | 66ea8dc4b6Seschrock * V 67*5711d393Sloli * +---------------+ Reads associated with a piece of logical data. 68*5711d393Sloli * | Read I/O | This includes reads on behalf of RAID-Z, 69*5711d393Sloli * +---------------+ mirrors, gang blocks, retries, etc. 70ea8dc4b6Seschrock * | 71ea8dc4b6Seschrock * V 72*5711d393Sloli * +---------------+ Reads associated with a particular device, but 73*5711d393Sloli * | Physical I/O | no logical data. Issued as part of vdev caching 74*5711d393Sloli * +---------------+ and I/O aggregation. 75ea8dc4b6Seschrock * 76ea8dc4b6Seschrock * Note that 'physical I/O' here is not the same terminology as used in the rest 77ea8dc4b6Seschrock * of ZIO. Typically, 'physical I/O' simply means that there is no attached 78ea8dc4b6Seschrock * blockpointer. But I/O with no associated block pointer can still be related 79ea8dc4b6Seschrock * to a logical piece of data (i.e. RAID-Z requests). 80ea8dc4b6Seschrock * 81ea8dc4b6Seschrock * Purely physical I/O always have unique ENAs. They are not related to a 82ea8dc4b6Seschrock * particular piece of logical data, and therefore cannot be chained together. 83ea8dc4b6Seschrock * We still generate an ereport, but the DE doesn't correlate it with any 84ea8dc4b6Seschrock * logical piece of data. When such an I/O fails, the delegated I/O requests 85ea8dc4b6Seschrock * will issue a retry, which will trigger the 'real' ereport with the correct 86ea8dc4b6Seschrock * ENA. 87ea8dc4b6Seschrock * 88ea8dc4b6Seschrock * We keep track of the ENA for a ZIO chain through the 'io_logical' member. 89ea8dc4b6Seschrock * When a new logical I/O is issued, we set this to point to itself. Child I/Os 90ea8dc4b6Seschrock * then inherit this pointer, so that when it is first set subsequent failures 91e14bb325SJeff Bonwick * will use the same ENA. For vdev cache fill and queue aggregation I/O, 92e14bb325SJeff Bonwick * this pointer is set to NULL, and no ereport will be generated (since it 93e14bb325SJeff Bonwick * doesn't actually correspond to any particular device or piece of data, 94e14bb325SJeff Bonwick * and the caller will always retry without caching or queueing anyway). 9522fe2c88SJonathan Adams * 9622fe2c88SJonathan Adams * For checksum errors, we want to include more information about the actual 9722fe2c88SJonathan Adams * error which occurs. Accordingly, we build an ereport when the error is 9822fe2c88SJonathan Adams * noticed, but instead of sending it in immediately, we hang it off of the 9922fe2c88SJonathan Adams * io_cksum_report field of the logical IO. When the logical IO completes 10022fe2c88SJonathan Adams * (successfully or not), zfs_ereport_finish_checksum() is called with the 10122fe2c88SJonathan Adams * good and bad versions of the buffer (if available), and we annotate the 10222fe2c88SJonathan Adams * ereport with information about the differences. 103ea8dc4b6Seschrock */ 10422fe2c88SJonathan Adams #ifdef _KERNEL 10522fe2c88SJonathan Adams static void 10622fe2c88SJonathan Adams zfs_ereport_start(nvlist_t **ereport_out, nvlist_t **detector_out, 107eb633035STom Caputi const char *subclass, spa_t *spa, vdev_t *vd, const zbookmark_phys_t *zb, 108eb633035STom Caputi zio_t *zio, uint64_t stateoroffset, uint64_t size) 109ea8dc4b6Seschrock { 110ea8dc4b6Seschrock nvlist_t *ereport, *detector; 11122fe2c88SJonathan Adams 112ea8dc4b6Seschrock uint64_t ena; 113ea8dc4b6Seschrock char class[64]; 114ea8dc4b6Seschrock 115ea8dc4b6Seschrock /* 116468c413aSTim Haley * If we are doing a spa_tryimport() or in recovery mode, 117468c413aSTim Haley * ignore errors. 118ea8dc4b6Seschrock */ 119b16da2e2SGeorge Wilson if (spa_load_state(spa) == SPA_LOAD_TRYIMPORT || 120b16da2e2SGeorge Wilson spa_load_state(spa) == SPA_LOAD_RECOVER) 121ea8dc4b6Seschrock return; 122ea8dc4b6Seschrock 123ea8dc4b6Seschrock /* 124ea8dc4b6Seschrock * If we are in the middle of opening a pool, and the previous attempt 125ea8dc4b6Seschrock * failed, don't bother logging any new ereports - we're just going to 126ea8dc4b6Seschrock * get the same diagnosis anyway. 127ea8dc4b6Seschrock */ 128b16da2e2SGeorge Wilson if (spa_load_state(spa) != SPA_LOAD_NONE && 129ea8dc4b6Seschrock spa->spa_last_open_failed) 130ea8dc4b6Seschrock return; 131ea8dc4b6Seschrock 132bf82a41bSeschrock if (zio != NULL) { 133bf82a41bSeschrock /* 134bf82a41bSeschrock * If this is not a read or write zio, ignore the error. This 135bf82a41bSeschrock * can occur if the DKIOCFLUSHWRITECACHE ioctl fails. 136bf82a41bSeschrock */ 137bf82a41bSeschrock if (zio->io_type != ZIO_TYPE_READ && 138bf82a41bSeschrock zio->io_type != ZIO_TYPE_WRITE) 139bf82a41bSeschrock return; 140bf82a41bSeschrock 141bf82a41bSeschrock /* 142bf82a41bSeschrock * Ignore any errors from speculative I/Os, as failure is an 143bf82a41bSeschrock * expected result. 144bf82a41bSeschrock */ 145bf82a41bSeschrock if (zio->io_flags & ZIO_FLAG_SPECULATIVE) 146bf82a41bSeschrock return; 14751ece835Seschrock 1488956713aSEric Schrock /* 1498956713aSEric Schrock * If this I/O is not a retry I/O, don't post an ereport. 1508956713aSEric Schrock * Otherwise, we risk making bad diagnoses based on B_FAILFAST 1518956713aSEric Schrock * I/Os. 1528956713aSEric Schrock */ 1538956713aSEric Schrock if (zio->io_error == EIO && 1548956713aSEric Schrock !(zio->io_flags & ZIO_FLAG_IO_RETRY)) 1558956713aSEric Schrock return; 1568956713aSEric Schrock 1576809eb4eSEric Schrock if (vd != NULL) { 1586809eb4eSEric Schrock /* 1596809eb4eSEric Schrock * If the vdev has already been marked as failing due 1606809eb4eSEric Schrock * to a failed probe, then ignore any subsequent I/O 1616809eb4eSEric Schrock * errors, as the DE will automatically fault the vdev 1626809eb4eSEric Schrock * on the first such failure. This also catches cases 1636809eb4eSEric Schrock * where vdev_remove_wanted is set and the device has 1646809eb4eSEric Schrock * not yet been asynchronously placed into the REMOVED 1656809eb4eSEric Schrock * state. 1666809eb4eSEric Schrock */ 1671d713200SEric Schrock if (zio->io_vd == vd && !vdev_accessible(vd, zio)) 1686809eb4eSEric Schrock return; 1696809eb4eSEric Schrock 1706809eb4eSEric Schrock /* 1716809eb4eSEric Schrock * Ignore checksum errors for reads from DTL regions of 1726809eb4eSEric Schrock * leaf vdevs. 1736809eb4eSEric Schrock */ 1746809eb4eSEric Schrock if (zio->io_type == ZIO_TYPE_READ && 1756809eb4eSEric Schrock zio->io_error == ECKSUM && 1766809eb4eSEric Schrock vd->vdev_ops->vdev_op_leaf && 1776809eb4eSEric Schrock vdev_dtl_contains(vd, DTL_MISSING, zio->io_txg, 1)) 1786809eb4eSEric Schrock return; 1796809eb4eSEric Schrock } 180bf82a41bSeschrock } 181b468a217Seschrock 1821d713200SEric Schrock /* 1831d713200SEric Schrock * For probe failure, we want to avoid posting ereports if we've 1841d713200SEric Schrock * already removed the device in the meantime. 1851d713200SEric Schrock */ 1861d713200SEric Schrock if (vd != NULL && 1871d713200SEric Schrock strcmp(subclass, FM_EREPORT_ZFS_PROBE_FAILURE) == 0 && 1881d713200SEric Schrock (vd->vdev_remove_wanted || vd->vdev_state == VDEV_STATE_REMOVED)) 1891d713200SEric Schrock return; 1901d713200SEric Schrock 191ea8dc4b6Seschrock if ((ereport = fm_nvlist_create(NULL)) == NULL) 192ea8dc4b6Seschrock return; 193ea8dc4b6Seschrock 194ea8dc4b6Seschrock if ((detector = fm_nvlist_create(NULL)) == NULL) { 195ea8dc4b6Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 196ea8dc4b6Seschrock return; 197ea8dc4b6Seschrock } 198ea8dc4b6Seschrock 199ea8dc4b6Seschrock /* 200ea8dc4b6Seschrock * Serialize ereport generation 201ea8dc4b6Seschrock */ 202ea8dc4b6Seschrock mutex_enter(&spa->spa_errlist_lock); 203ea8dc4b6Seschrock 204ea8dc4b6Seschrock /* 205ea8dc4b6Seschrock * Determine the ENA to use for this event. If we are in a loading 206ea8dc4b6Seschrock * state, use a SPA-wide ENA. Otherwise, if we are in an I/O state, use 207ea8dc4b6Seschrock * a root zio-wide ENA. Otherwise, simply use a unique ENA. 208ea8dc4b6Seschrock */ 209b16da2e2SGeorge Wilson if (spa_load_state(spa) != SPA_LOAD_NONE) { 210ea8dc4b6Seschrock if (spa->spa_ena == 0) 211ea8dc4b6Seschrock spa->spa_ena = fm_ena_generate(0, FM_ENA_FMT1); 212ea8dc4b6Seschrock ena = spa->spa_ena; 213ea8dc4b6Seschrock } else if (zio != NULL && zio->io_logical != NULL) { 214ea8dc4b6Seschrock if (zio->io_logical->io_ena == 0) 215ea8dc4b6Seschrock zio->io_logical->io_ena = 216ea8dc4b6Seschrock fm_ena_generate(0, FM_ENA_FMT1); 217ea8dc4b6Seschrock ena = zio->io_logical->io_ena; 218ea8dc4b6Seschrock } else { 219ea8dc4b6Seschrock ena = fm_ena_generate(0, FM_ENA_FMT1); 220ea8dc4b6Seschrock } 221ea8dc4b6Seschrock 222ea8dc4b6Seschrock /* 223ea8dc4b6Seschrock * Construct the full class, detector, and other standard FMA fields. 224ea8dc4b6Seschrock */ 225ea8dc4b6Seschrock (void) snprintf(class, sizeof (class), "%s.%s", 226ea8dc4b6Seschrock ZFS_ERROR_CLASS, subclass); 227ea8dc4b6Seschrock 228ea8dc4b6Seschrock fm_fmri_zfs_set(detector, FM_ZFS_SCHEME_VERSION, spa_guid(spa), 229ea8dc4b6Seschrock vd != NULL ? vd->vdev_guid : 0); 230ea8dc4b6Seschrock 231ea8dc4b6Seschrock fm_ereport_set(ereport, FM_EREPORT_VERSION, class, ena, detector, NULL); 232ea8dc4b6Seschrock 233ea8dc4b6Seschrock /* 234ea8dc4b6Seschrock * Construct the per-ereport payload, depending on which parameters are 235ea8dc4b6Seschrock * passed in. 236ea8dc4b6Seschrock */ 237ea8dc4b6Seschrock 238ea8dc4b6Seschrock /* 239ea8dc4b6Seschrock * Generic payload members common to all ereports. 240ea8dc4b6Seschrock */ 241ea8dc4b6Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL, 242e14bb325SJeff Bonwick DATA_TYPE_STRING, spa_name(spa), FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, 243ea8dc4b6Seschrock DATA_TYPE_UINT64, spa_guid(spa), 244ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_CONTEXT, DATA_TYPE_INT32, 245b16da2e2SGeorge Wilson spa_load_state(spa), NULL); 246ea8dc4b6Seschrock 24732b87932Sek if (spa != NULL) { 24832b87932Sek fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_POOL_FAILMODE, 24932b87932Sek DATA_TYPE_STRING, 25032b87932Sek spa_get_failmode(spa) == ZIO_FAILURE_MODE_WAIT ? 25132b87932Sek FM_EREPORT_FAILMODE_WAIT : 25232b87932Sek spa_get_failmode(spa) == ZIO_FAILURE_MODE_CONTINUE ? 25332b87932Sek FM_EREPORT_FAILMODE_CONTINUE : FM_EREPORT_FAILMODE_PANIC, 25432b87932Sek NULL); 25532b87932Sek } 25632b87932Sek 257ea8dc4b6Seschrock if (vd != NULL) { 258ea8dc4b6Seschrock vdev_t *pvd = vd->vdev_parent; 259ea8dc4b6Seschrock 260ea8dc4b6Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, 261ea8dc4b6Seschrock DATA_TYPE_UINT64, vd->vdev_guid, 262ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_TYPE, 263ea8dc4b6Seschrock DATA_TYPE_STRING, vd->vdev_ops->vdev_op_type, NULL); 2646809eb4eSEric Schrock if (vd->vdev_path != NULL) 265ea8dc4b6Seschrock fm_payload_set(ereport, 266ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_PATH, 267ea8dc4b6Seschrock DATA_TYPE_STRING, vd->vdev_path, NULL); 2686809eb4eSEric Schrock if (vd->vdev_devid != NULL) 269ea8dc4b6Seschrock fm_payload_set(ereport, 270ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_DEVID, 271ea8dc4b6Seschrock DATA_TYPE_STRING, vd->vdev_devid, NULL); 2726809eb4eSEric Schrock if (vd->vdev_fru != NULL) 2736809eb4eSEric Schrock fm_payload_set(ereport, 2746809eb4eSEric Schrock FM_EREPORT_PAYLOAD_ZFS_VDEV_FRU, 2756809eb4eSEric Schrock DATA_TYPE_STRING, vd->vdev_fru, NULL); 276*5711d393Sloli if (vd->vdev_ashift) 277*5711d393Sloli fm_payload_set(ereport, 278*5711d393Sloli FM_EREPORT_PAYLOAD_ZFS_VDEV_ASHIFT, 279*5711d393Sloli DATA_TYPE_UINT64, vd->vdev_ashift, NULL); 280ea8dc4b6Seschrock 281ea8dc4b6Seschrock if (pvd != NULL) { 282ea8dc4b6Seschrock fm_payload_set(ereport, 283ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_GUID, 284ea8dc4b6Seschrock DATA_TYPE_UINT64, pvd->vdev_guid, 285ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_TYPE, 286ea8dc4b6Seschrock DATA_TYPE_STRING, pvd->vdev_ops->vdev_op_type, 287ea8dc4b6Seschrock NULL); 288ea8dc4b6Seschrock if (pvd->vdev_path) 289ea8dc4b6Seschrock fm_payload_set(ereport, 290ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH, 291c25056deSgw DATA_TYPE_STRING, pvd->vdev_path, NULL); 292ea8dc4b6Seschrock if (pvd->vdev_devid) 293ea8dc4b6Seschrock fm_payload_set(ereport, 294ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID, 295ea8dc4b6Seschrock DATA_TYPE_STRING, pvd->vdev_devid, NULL); 296ea8dc4b6Seschrock } 297ea8dc4b6Seschrock } 298ea8dc4b6Seschrock 299ea8dc4b6Seschrock if (zio != NULL) { 300ea8dc4b6Seschrock /* 301ea8dc4b6Seschrock * Payload common to all I/Os. 302ea8dc4b6Seschrock */ 303ea8dc4b6Seschrock fm_payload_set(ereport, FM_EREPORT_PAYLOAD_ZFS_ZIO_ERR, 304ea8dc4b6Seschrock DATA_TYPE_INT32, zio->io_error, NULL); 305ea8dc4b6Seschrock 306ea8dc4b6Seschrock /* 307ea8dc4b6Seschrock * If the 'size' parameter is non-zero, it indicates this is a 308ea8dc4b6Seschrock * RAID-Z or other I/O where the physical offset and length are 309ea8dc4b6Seschrock * provided for us, instead of within the zio_t. 310ea8dc4b6Seschrock */ 311ea8dc4b6Seschrock if (vd != NULL) { 312ea8dc4b6Seschrock if (size) 313ea8dc4b6Seschrock fm_payload_set(ereport, 314ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 315ea8dc4b6Seschrock DATA_TYPE_UINT64, stateoroffset, 316ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 317c3c6d682Seschrock DATA_TYPE_UINT64, size, NULL); 318ea8dc4b6Seschrock else 319ea8dc4b6Seschrock fm_payload_set(ereport, 320ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_OFFSET, 321ea8dc4b6Seschrock DATA_TYPE_UINT64, zio->io_offset, 322ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_ZIO_SIZE, 323c3c6d682Seschrock DATA_TYPE_UINT64, zio->io_size, NULL); 324ea8dc4b6Seschrock } 325ea8dc4b6Seschrock } else if (vd != NULL) { 326ea8dc4b6Seschrock /* 327ea8dc4b6Seschrock * If we have a vdev but no zio, this is a device fault, and the 328ea8dc4b6Seschrock * 'stateoroffset' parameter indicates the previous state of the 329ea8dc4b6Seschrock * vdev. 330ea8dc4b6Seschrock */ 331ea8dc4b6Seschrock fm_payload_set(ereport, 332ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_PREV_STATE, 333ea8dc4b6Seschrock DATA_TYPE_UINT64, stateoroffset, NULL); 334ea8dc4b6Seschrock } 335468c413aSTim Haley 336eb633035STom Caputi /* 337eb633035STom Caputi * Payload for I/Os with corresponding logical information. 338eb633035STom Caputi */ 339eb633035STom Caputi if (zb != NULL && (zio == NULL || zio->io_logical != NULL)) 340eb633035STom Caputi fm_payload_set(ereport, 341eb633035STom Caputi FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJSET, 342eb633035STom Caputi DATA_TYPE_UINT64, zb->zb_objset, 343eb633035STom Caputi FM_EREPORT_PAYLOAD_ZFS_ZIO_OBJECT, 344eb633035STom Caputi DATA_TYPE_UINT64, zb->zb_object, 345eb633035STom Caputi FM_EREPORT_PAYLOAD_ZFS_ZIO_LEVEL, 346eb633035STom Caputi DATA_TYPE_INT64, zb->zb_level, 347eb633035STom Caputi FM_EREPORT_PAYLOAD_ZFS_ZIO_BLKID, 348eb633035STom Caputi DATA_TYPE_UINT64, zb->zb_blkid, NULL); 349eb633035STom Caputi 350ea8dc4b6Seschrock mutex_exit(&spa->spa_errlist_lock); 351ea8dc4b6Seschrock 35222fe2c88SJonathan Adams *ereport_out = ereport; 35322fe2c88SJonathan Adams *detector_out = detector; 35422fe2c88SJonathan Adams } 35522fe2c88SJonathan Adams 35622fe2c88SJonathan Adams /* if it's <= 128 bytes, save the corruption directly */ 35722fe2c88SJonathan Adams #define ZFM_MAX_INLINE (128 / sizeof (uint64_t)) 35822fe2c88SJonathan Adams 35922fe2c88SJonathan Adams #define MAX_RANGES 16 36022fe2c88SJonathan Adams 36122fe2c88SJonathan Adams typedef struct zfs_ecksum_info { 36222fe2c88SJonathan Adams /* histograms of set and cleared bits by bit number in a 64-bit word */ 363a6c1eb3cSAndriy Gapon uint32_t zei_histogram_set[sizeof (uint64_t) * NBBY]; 364a6c1eb3cSAndriy Gapon uint32_t zei_histogram_cleared[sizeof (uint64_t) * NBBY]; 36522fe2c88SJonathan Adams 36622fe2c88SJonathan Adams /* inline arrays of bits set and cleared. */ 36722fe2c88SJonathan Adams uint64_t zei_bits_set[ZFM_MAX_INLINE]; 36822fe2c88SJonathan Adams uint64_t zei_bits_cleared[ZFM_MAX_INLINE]; 36922fe2c88SJonathan Adams 37022fe2c88SJonathan Adams /* 37122fe2c88SJonathan Adams * for each range, the number of bits set and cleared. The Hamming 37222fe2c88SJonathan Adams * distance between the good and bad buffers is the sum of them all. 37322fe2c88SJonathan Adams */ 37422fe2c88SJonathan Adams uint32_t zei_range_sets[MAX_RANGES]; 37522fe2c88SJonathan Adams uint32_t zei_range_clears[MAX_RANGES]; 37622fe2c88SJonathan Adams 37722fe2c88SJonathan Adams struct zei_ranges { 37822fe2c88SJonathan Adams uint32_t zr_start; 37922fe2c88SJonathan Adams uint32_t zr_end; 38022fe2c88SJonathan Adams } zei_ranges[MAX_RANGES]; 38122fe2c88SJonathan Adams 38222fe2c88SJonathan Adams size_t zei_range_count; 38322fe2c88SJonathan Adams uint32_t zei_mingap; 38422fe2c88SJonathan Adams uint32_t zei_allowed_mingap; 38522fe2c88SJonathan Adams 38622fe2c88SJonathan Adams } zfs_ecksum_info_t; 38722fe2c88SJonathan Adams 38822fe2c88SJonathan Adams static void 389a6c1eb3cSAndriy Gapon update_histogram(uint64_t value_arg, uint32_t *hist, uint32_t *count) 39022fe2c88SJonathan Adams { 39122fe2c88SJonathan Adams size_t i; 39222fe2c88SJonathan Adams size_t bits = 0; 39322fe2c88SJonathan Adams uint64_t value = BE_64(value_arg); 39422fe2c88SJonathan Adams 39522fe2c88SJonathan Adams /* We store the bits in big-endian (largest-first) order */ 39622fe2c88SJonathan Adams for (i = 0; i < 64; i++) { 39722fe2c88SJonathan Adams if (value & (1ull << i)) { 39822fe2c88SJonathan Adams hist[63 - i]++; 39922fe2c88SJonathan Adams ++bits; 40022fe2c88SJonathan Adams } 40122fe2c88SJonathan Adams } 40222fe2c88SJonathan Adams /* update the count of bits changed */ 40322fe2c88SJonathan Adams *count += bits; 40422fe2c88SJonathan Adams } 40522fe2c88SJonathan Adams 40622fe2c88SJonathan Adams /* 40722fe2c88SJonathan Adams * We've now filled up the range array, and need to increase "mingap" and 40822fe2c88SJonathan Adams * shrink the range list accordingly. zei_mingap is always the smallest 40922fe2c88SJonathan Adams * distance between array entries, so we set the new_allowed_gap to be 41022fe2c88SJonathan Adams * one greater than that. We then go through the list, joining together 41122fe2c88SJonathan Adams * any ranges which are closer than the new_allowed_gap. 41222fe2c88SJonathan Adams * 41322fe2c88SJonathan Adams * By construction, there will be at least one. We also update zei_mingap 41422fe2c88SJonathan Adams * to the new smallest gap, to prepare for our next invocation. 41522fe2c88SJonathan Adams */ 41622fe2c88SJonathan Adams static void 41722fe2c88SJonathan Adams shrink_ranges(zfs_ecksum_info_t *eip) 41822fe2c88SJonathan Adams { 41922fe2c88SJonathan Adams uint32_t mingap = UINT32_MAX; 42022fe2c88SJonathan Adams uint32_t new_allowed_gap = eip->zei_mingap + 1; 42122fe2c88SJonathan Adams 42222fe2c88SJonathan Adams size_t idx, output; 42322fe2c88SJonathan Adams size_t max = eip->zei_range_count; 42422fe2c88SJonathan Adams 42522fe2c88SJonathan Adams struct zei_ranges *r = eip->zei_ranges; 42622fe2c88SJonathan Adams 42722fe2c88SJonathan Adams ASSERT3U(eip->zei_range_count, >, 0); 42822fe2c88SJonathan Adams ASSERT3U(eip->zei_range_count, <=, MAX_RANGES); 42922fe2c88SJonathan Adams 43022fe2c88SJonathan Adams output = idx = 0; 43122fe2c88SJonathan Adams while (idx < max - 1) { 43222fe2c88SJonathan Adams uint32_t start = r[idx].zr_start; 43322fe2c88SJonathan Adams uint32_t end = r[idx].zr_end; 43422fe2c88SJonathan Adams 43522fe2c88SJonathan Adams while (idx < max - 1) { 43622fe2c88SJonathan Adams idx++; 43722fe2c88SJonathan Adams 43822fe2c88SJonathan Adams uint32_t nstart = r[idx].zr_start; 43922fe2c88SJonathan Adams uint32_t nend = r[idx].zr_end; 44022fe2c88SJonathan Adams 44122fe2c88SJonathan Adams uint32_t gap = nstart - end; 44222fe2c88SJonathan Adams if (gap < new_allowed_gap) { 44322fe2c88SJonathan Adams end = nend; 44422fe2c88SJonathan Adams continue; 44522fe2c88SJonathan Adams } 44622fe2c88SJonathan Adams if (gap < mingap) 44722fe2c88SJonathan Adams mingap = gap; 44822fe2c88SJonathan Adams break; 44922fe2c88SJonathan Adams } 45022fe2c88SJonathan Adams r[output].zr_start = start; 45122fe2c88SJonathan Adams r[output].zr_end = end; 45222fe2c88SJonathan Adams output++; 45322fe2c88SJonathan Adams } 45422fe2c88SJonathan Adams ASSERT3U(output, <, eip->zei_range_count); 45522fe2c88SJonathan Adams eip->zei_range_count = output; 45622fe2c88SJonathan Adams eip->zei_mingap = mingap; 45722fe2c88SJonathan Adams eip->zei_allowed_mingap = new_allowed_gap; 45822fe2c88SJonathan Adams } 45922fe2c88SJonathan Adams 46022fe2c88SJonathan Adams static void 46122fe2c88SJonathan Adams add_range(zfs_ecksum_info_t *eip, int start, int end) 46222fe2c88SJonathan Adams { 46322fe2c88SJonathan Adams struct zei_ranges *r = eip->zei_ranges; 46422fe2c88SJonathan Adams size_t count = eip->zei_range_count; 46522fe2c88SJonathan Adams 46622fe2c88SJonathan Adams if (count >= MAX_RANGES) { 46722fe2c88SJonathan Adams shrink_ranges(eip); 46822fe2c88SJonathan Adams count = eip->zei_range_count; 46922fe2c88SJonathan Adams } 47022fe2c88SJonathan Adams if (count == 0) { 47122fe2c88SJonathan Adams eip->zei_mingap = UINT32_MAX; 47222fe2c88SJonathan Adams eip->zei_allowed_mingap = 1; 47322fe2c88SJonathan Adams } else { 47422fe2c88SJonathan Adams int gap = start - r[count - 1].zr_end; 47522fe2c88SJonathan Adams 47622fe2c88SJonathan Adams if (gap < eip->zei_allowed_mingap) { 47722fe2c88SJonathan Adams r[count - 1].zr_end = end; 47822fe2c88SJonathan Adams return; 47922fe2c88SJonathan Adams } 48022fe2c88SJonathan Adams if (gap < eip->zei_mingap) 48122fe2c88SJonathan Adams eip->zei_mingap = gap; 48222fe2c88SJonathan Adams } 48322fe2c88SJonathan Adams r[count].zr_start = start; 48422fe2c88SJonathan Adams r[count].zr_end = end; 48522fe2c88SJonathan Adams eip->zei_range_count++; 48622fe2c88SJonathan Adams } 48722fe2c88SJonathan Adams 48822fe2c88SJonathan Adams static size_t 48922fe2c88SJonathan Adams range_total_size(zfs_ecksum_info_t *eip) 49022fe2c88SJonathan Adams { 49122fe2c88SJonathan Adams struct zei_ranges *r = eip->zei_ranges; 49222fe2c88SJonathan Adams size_t count = eip->zei_range_count; 49322fe2c88SJonathan Adams size_t result = 0; 49422fe2c88SJonathan Adams size_t idx; 49522fe2c88SJonathan Adams 49622fe2c88SJonathan Adams for (idx = 0; idx < count; idx++) 49722fe2c88SJonathan Adams result += (r[idx].zr_end - r[idx].zr_start); 49822fe2c88SJonathan Adams 49922fe2c88SJonathan Adams return (result); 50022fe2c88SJonathan Adams } 50122fe2c88SJonathan Adams 50222fe2c88SJonathan Adams static zfs_ecksum_info_t * 50322fe2c88SJonathan Adams annotate_ecksum(nvlist_t *ereport, zio_bad_cksum_t *info, 504eb633035STom Caputi const abd_t *goodabd, const abd_t *badabd, size_t size, 50522fe2c88SJonathan Adams boolean_t drop_if_identical) 50622fe2c88SJonathan Adams { 507eb633035STom Caputi const uint64_t *good; 508eb633035STom Caputi const uint64_t *bad; 50922fe2c88SJonathan Adams 51022fe2c88SJonathan Adams uint64_t allset = 0; 51122fe2c88SJonathan Adams uint64_t allcleared = 0; 51222fe2c88SJonathan Adams 51322fe2c88SJonathan Adams size_t nui64s = size / sizeof (uint64_t); 51422fe2c88SJonathan Adams 51522fe2c88SJonathan Adams size_t inline_size; 51622fe2c88SJonathan Adams int no_inline = 0; 51722fe2c88SJonathan Adams size_t idx; 51822fe2c88SJonathan Adams size_t range; 51922fe2c88SJonathan Adams 52022fe2c88SJonathan Adams size_t offset = 0; 52122fe2c88SJonathan Adams ssize_t start = -1; 52222fe2c88SJonathan Adams 52322fe2c88SJonathan Adams zfs_ecksum_info_t *eip = kmem_zalloc(sizeof (*eip), KM_SLEEP); 52422fe2c88SJonathan Adams 52522fe2c88SJonathan Adams /* don't do any annotation for injected checksum errors */ 52622fe2c88SJonathan Adams if (info != NULL && info->zbc_injected) 52722fe2c88SJonathan Adams return (eip); 52822fe2c88SJonathan Adams 52922fe2c88SJonathan Adams if (info != NULL && info->zbc_has_cksum) { 53022fe2c88SJonathan Adams fm_payload_set(ereport, 53122fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_CKSUM_EXPECTED, 53222fe2c88SJonathan Adams DATA_TYPE_UINT64_ARRAY, 53322fe2c88SJonathan Adams sizeof (info->zbc_expected) / sizeof (uint64_t), 53422fe2c88SJonathan Adams (uint64_t *)&info->zbc_expected, 53522fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_CKSUM_ACTUAL, 53622fe2c88SJonathan Adams DATA_TYPE_UINT64_ARRAY, 53722fe2c88SJonathan Adams sizeof (info->zbc_actual) / sizeof (uint64_t), 53822fe2c88SJonathan Adams (uint64_t *)&info->zbc_actual, 53922fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_CKSUM_ALGO, 54022fe2c88SJonathan Adams DATA_TYPE_STRING, 54122fe2c88SJonathan Adams info->zbc_checksum_name, 54222fe2c88SJonathan Adams NULL); 54322fe2c88SJonathan Adams 54422fe2c88SJonathan Adams if (info->zbc_byteswapped) { 54522fe2c88SJonathan Adams fm_payload_set(ereport, 54622fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_CKSUM_BYTESWAP, 54722fe2c88SJonathan Adams DATA_TYPE_BOOLEAN, 1, 54822fe2c88SJonathan Adams NULL); 54922fe2c88SJonathan Adams } 55022fe2c88SJonathan Adams } 55122fe2c88SJonathan Adams 552eb633035STom Caputi if (badabd == NULL || goodabd == NULL) 55322fe2c88SJonathan Adams return (eip); 55422fe2c88SJonathan Adams 555a6c1eb3cSAndriy Gapon ASSERT3U(nui64s, <=, UINT32_MAX); 55622fe2c88SJonathan Adams ASSERT3U(size, ==, nui64s * sizeof (uint64_t)); 55722fe2c88SJonathan Adams ASSERT3U(size, <=, SPA_MAXBLOCKSIZE); 55822fe2c88SJonathan Adams ASSERT3U(size, <=, UINT32_MAX); 55922fe2c88SJonathan Adams 560eb633035STom Caputi good = (const uint64_t *) abd_borrow_buf_copy((abd_t *)goodabd, size); 561eb633035STom Caputi bad = (const uint64_t *) abd_borrow_buf_copy((abd_t *)badabd, size); 562eb633035STom Caputi 56322fe2c88SJonathan Adams /* build up the range list by comparing the two buffers. */ 56422fe2c88SJonathan Adams for (idx = 0; idx < nui64s; idx++) { 56522fe2c88SJonathan Adams if (good[idx] == bad[idx]) { 56622fe2c88SJonathan Adams if (start == -1) 56722fe2c88SJonathan Adams continue; 56822fe2c88SJonathan Adams 56922fe2c88SJonathan Adams add_range(eip, start, idx); 57022fe2c88SJonathan Adams start = -1; 57122fe2c88SJonathan Adams } else { 57222fe2c88SJonathan Adams if (start != -1) 57322fe2c88SJonathan Adams continue; 57422fe2c88SJonathan Adams 57522fe2c88SJonathan Adams start = idx; 57622fe2c88SJonathan Adams } 57722fe2c88SJonathan Adams } 57822fe2c88SJonathan Adams if (start != -1) 57922fe2c88SJonathan Adams add_range(eip, start, idx); 58022fe2c88SJonathan Adams 58122fe2c88SJonathan Adams /* See if it will fit in our inline buffers */ 58222fe2c88SJonathan Adams inline_size = range_total_size(eip); 58322fe2c88SJonathan Adams if (inline_size > ZFM_MAX_INLINE) 58422fe2c88SJonathan Adams no_inline = 1; 58522fe2c88SJonathan Adams 58622fe2c88SJonathan Adams /* 58722fe2c88SJonathan Adams * If there is no change and we want to drop if the buffers are 58822fe2c88SJonathan Adams * identical, do so. 58922fe2c88SJonathan Adams */ 59022fe2c88SJonathan Adams if (inline_size == 0 && drop_if_identical) { 59122fe2c88SJonathan Adams kmem_free(eip, sizeof (*eip)); 592eb633035STom Caputi abd_return_buf((abd_t *)goodabd, (void *)good, size); 593eb633035STom Caputi abd_return_buf((abd_t *)badabd, (void *)bad, size); 59422fe2c88SJonathan Adams return (NULL); 59522fe2c88SJonathan Adams } 59622fe2c88SJonathan Adams 59722fe2c88SJonathan Adams /* 59822fe2c88SJonathan Adams * Now walk through the ranges, filling in the details of the 59922fe2c88SJonathan Adams * differences. Also convert our uint64_t-array offsets to byte 60022fe2c88SJonathan Adams * offsets. 60122fe2c88SJonathan Adams */ 60222fe2c88SJonathan Adams for (range = 0; range < eip->zei_range_count; range++) { 60322fe2c88SJonathan Adams size_t start = eip->zei_ranges[range].zr_start; 60422fe2c88SJonathan Adams size_t end = eip->zei_ranges[range].zr_end; 60522fe2c88SJonathan Adams 60622fe2c88SJonathan Adams for (idx = start; idx < end; idx++) { 60722fe2c88SJonathan Adams uint64_t set, cleared; 60822fe2c88SJonathan Adams 60922fe2c88SJonathan Adams // bits set in bad, but not in good 61022fe2c88SJonathan Adams set = ((~good[idx]) & bad[idx]); 61122fe2c88SJonathan Adams // bits set in good, but not in bad 61222fe2c88SJonathan Adams cleared = (good[idx] & (~bad[idx])); 61322fe2c88SJonathan Adams 61422fe2c88SJonathan Adams allset |= set; 61522fe2c88SJonathan Adams allcleared |= cleared; 61622fe2c88SJonathan Adams 61722fe2c88SJonathan Adams if (!no_inline) { 61822fe2c88SJonathan Adams ASSERT3U(offset, <, inline_size); 61922fe2c88SJonathan Adams eip->zei_bits_set[offset] = set; 62022fe2c88SJonathan Adams eip->zei_bits_cleared[offset] = cleared; 62122fe2c88SJonathan Adams offset++; 62222fe2c88SJonathan Adams } 62322fe2c88SJonathan Adams 62422fe2c88SJonathan Adams update_histogram(set, eip->zei_histogram_set, 62522fe2c88SJonathan Adams &eip->zei_range_sets[range]); 62622fe2c88SJonathan Adams update_histogram(cleared, eip->zei_histogram_cleared, 62722fe2c88SJonathan Adams &eip->zei_range_clears[range]); 62822fe2c88SJonathan Adams } 62922fe2c88SJonathan Adams 63022fe2c88SJonathan Adams /* convert to byte offsets */ 63122fe2c88SJonathan Adams eip->zei_ranges[range].zr_start *= sizeof (uint64_t); 63222fe2c88SJonathan Adams eip->zei_ranges[range].zr_end *= sizeof (uint64_t); 63322fe2c88SJonathan Adams } 634eb633035STom Caputi 635eb633035STom Caputi abd_return_buf((abd_t *)goodabd, (void *)good, size); 636eb633035STom Caputi abd_return_buf((abd_t *)badabd, (void *)bad, size); 637eb633035STom Caputi 63822fe2c88SJonathan Adams eip->zei_allowed_mingap *= sizeof (uint64_t); 63922fe2c88SJonathan Adams inline_size *= sizeof (uint64_t); 64022fe2c88SJonathan Adams 64122fe2c88SJonathan Adams /* fill in ereport */ 64222fe2c88SJonathan Adams fm_payload_set(ereport, 64322fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_BAD_OFFSET_RANGES, 64422fe2c88SJonathan Adams DATA_TYPE_UINT32_ARRAY, 2 * eip->zei_range_count, 64522fe2c88SJonathan Adams (uint32_t *)eip->zei_ranges, 64622fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_BAD_RANGE_MIN_GAP, 64722fe2c88SJonathan Adams DATA_TYPE_UINT32, eip->zei_allowed_mingap, 64822fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_BAD_RANGE_SETS, 64922fe2c88SJonathan Adams DATA_TYPE_UINT32_ARRAY, eip->zei_range_count, eip->zei_range_sets, 65022fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_BAD_RANGE_CLEARS, 65122fe2c88SJonathan Adams DATA_TYPE_UINT32_ARRAY, eip->zei_range_count, eip->zei_range_clears, 65222fe2c88SJonathan Adams NULL); 65322fe2c88SJonathan Adams 65422fe2c88SJonathan Adams if (!no_inline) { 65522fe2c88SJonathan Adams fm_payload_set(ereport, 65622fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_BAD_SET_BITS, 65722fe2c88SJonathan Adams DATA_TYPE_UINT8_ARRAY, 65822fe2c88SJonathan Adams inline_size, (uint8_t *)eip->zei_bits_set, 65922fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_BAD_CLEARED_BITS, 66022fe2c88SJonathan Adams DATA_TYPE_UINT8_ARRAY, 66122fe2c88SJonathan Adams inline_size, (uint8_t *)eip->zei_bits_cleared, 66222fe2c88SJonathan Adams NULL); 66322fe2c88SJonathan Adams } else { 66422fe2c88SJonathan Adams fm_payload_set(ereport, 66522fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_BAD_SET_HISTOGRAM, 666a6c1eb3cSAndriy Gapon DATA_TYPE_UINT32_ARRAY, 66722fe2c88SJonathan Adams NBBY * sizeof (uint64_t), eip->zei_histogram_set, 66822fe2c88SJonathan Adams FM_EREPORT_PAYLOAD_ZFS_BAD_CLEARED_HISTOGRAM, 669a6c1eb3cSAndriy Gapon DATA_TYPE_UINT32_ARRAY, 67022fe2c88SJonathan Adams NBBY * sizeof (uint64_t), eip->zei_histogram_cleared, 67122fe2c88SJonathan Adams NULL); 67222fe2c88SJonathan Adams } 67322fe2c88SJonathan Adams return (eip); 67422fe2c88SJonathan Adams } 67522fe2c88SJonathan Adams #endif 67622fe2c88SJonathan Adams 67722fe2c88SJonathan Adams void 678eb633035STom Caputi zfs_ereport_post(const char *subclass, spa_t *spa, vdev_t *vd, 679eb633035STom Caputi const struct zbookmark_phys *zb, zio_t *zio, uint64_t stateoroffset, 680eb633035STom Caputi uint64_t size) 68122fe2c88SJonathan Adams { 68222fe2c88SJonathan Adams #ifdef _KERNEL 68322fe2c88SJonathan Adams nvlist_t *ereport = NULL; 68422fe2c88SJonathan Adams nvlist_t *detector = NULL; 68522fe2c88SJonathan Adams 686eb633035STom Caputi zfs_ereport_start(&ereport, &detector, subclass, spa, vd, 687eb633035STom Caputi zb, zio, stateoroffset, size); 68822fe2c88SJonathan Adams 68922fe2c88SJonathan Adams if (ereport == NULL) 69022fe2c88SJonathan Adams return; 69122fe2c88SJonathan Adams 692ea8dc4b6Seschrock fm_ereport_post(ereport, EVCH_SLEEP); 693ea8dc4b6Seschrock 694ea8dc4b6Seschrock fm_nvlist_destroy(ereport, FM_NVA_FREE); 695ea8dc4b6Seschrock fm_nvlist_destroy(detector, FM_NVA_FREE); 696ea8dc4b6Seschrock #endif 697ea8dc4b6Seschrock } 698ea8dc4b6Seschrock 69922fe2c88SJonathan Adams void 700eb633035STom Caputi zfs_ereport_start_checksum(spa_t *spa, vdev_t *vd, const zbookmark_phys_t *zb, 70122fe2c88SJonathan Adams struct zio *zio, uint64_t offset, uint64_t length, void *arg, 70222fe2c88SJonathan Adams zio_bad_cksum_t *info) 70322fe2c88SJonathan Adams { 70422fe2c88SJonathan Adams zio_cksum_report_t *report = kmem_zalloc(sizeof (*report), KM_SLEEP); 70522fe2c88SJonathan Adams 70622fe2c88SJonathan Adams if (zio->io_vsd != NULL) 70722fe2c88SJonathan Adams zio->io_vsd_ops->vsd_cksum_report(zio, report, arg); 70822fe2c88SJonathan Adams else 70922fe2c88SJonathan Adams zio_vsd_default_cksum_report(zio, report, arg); 71022fe2c88SJonathan Adams 71122fe2c88SJonathan Adams /* copy the checksum failure information if it was provided */ 71222fe2c88SJonathan Adams if (info != NULL) { 71322fe2c88SJonathan Adams report->zcr_ckinfo = kmem_zalloc(sizeof (*info), KM_SLEEP); 71422fe2c88SJonathan Adams bcopy(info, report->zcr_ckinfo, sizeof (*info)); 71522fe2c88SJonathan Adams } 71622fe2c88SJonathan Adams 717b24ab676SJeff Bonwick report->zcr_align = 1ULL << vd->vdev_top->vdev_ashift; 71822fe2c88SJonathan Adams report->zcr_length = length; 71922fe2c88SJonathan Adams 72022fe2c88SJonathan Adams #ifdef _KERNEL 72122fe2c88SJonathan Adams zfs_ereport_start(&report->zcr_ereport, &report->zcr_detector, 722eb633035STom Caputi FM_EREPORT_ZFS_CHECKSUM, spa, vd, zb, zio, offset, length); 72322fe2c88SJonathan Adams 72422fe2c88SJonathan Adams if (report->zcr_ereport == NULL) { 72522fe2c88SJonathan Adams report->zcr_free(report->zcr_cbdata, report->zcr_cbinfo); 726cd0837ccSGeorge Wilson if (report->zcr_ckinfo != NULL) { 727cd0837ccSGeorge Wilson kmem_free(report->zcr_ckinfo, 728cd0837ccSGeorge Wilson sizeof (*report->zcr_ckinfo)); 729cd0837ccSGeorge Wilson } 73022fe2c88SJonathan Adams kmem_free(report, sizeof (*report)); 73122fe2c88SJonathan Adams return; 73222fe2c88SJonathan Adams } 73322fe2c88SJonathan Adams #endif 73422fe2c88SJonathan Adams 73522fe2c88SJonathan Adams mutex_enter(&spa->spa_errlist_lock); 73622fe2c88SJonathan Adams report->zcr_next = zio->io_logical->io_cksum_report; 73722fe2c88SJonathan Adams zio->io_logical->io_cksum_report = report; 73822fe2c88SJonathan Adams mutex_exit(&spa->spa_errlist_lock); 73922fe2c88SJonathan Adams } 74022fe2c88SJonathan Adams 74122fe2c88SJonathan Adams void 742eb633035STom Caputi zfs_ereport_finish_checksum(zio_cksum_report_t *report, const abd_t *good_data, 743eb633035STom Caputi const abd_t *bad_data, boolean_t drop_if_identical) 74422fe2c88SJonathan Adams { 74522fe2c88SJonathan Adams #ifdef _KERNEL 74622fe2c88SJonathan Adams zfs_ecksum_info_t *info = NULL; 74722fe2c88SJonathan Adams info = annotate_ecksum(report->zcr_ereport, report->zcr_ckinfo, 74822fe2c88SJonathan Adams good_data, bad_data, report->zcr_length, drop_if_identical); 74922fe2c88SJonathan Adams 75022fe2c88SJonathan Adams if (info != NULL) 75122fe2c88SJonathan Adams fm_ereport_post(report->zcr_ereport, EVCH_SLEEP); 75222fe2c88SJonathan Adams 75322fe2c88SJonathan Adams fm_nvlist_destroy(report->zcr_ereport, FM_NVA_FREE); 75422fe2c88SJonathan Adams fm_nvlist_destroy(report->zcr_detector, FM_NVA_FREE); 75522fe2c88SJonathan Adams report->zcr_ereport = report->zcr_detector = NULL; 75622fe2c88SJonathan Adams 75722fe2c88SJonathan Adams if (info != NULL) 75822fe2c88SJonathan Adams kmem_free(info, sizeof (*info)); 75922fe2c88SJonathan Adams #endif 76022fe2c88SJonathan Adams } 76122fe2c88SJonathan Adams 76222fe2c88SJonathan Adams void 76322fe2c88SJonathan Adams zfs_ereport_free_checksum(zio_cksum_report_t *rpt) 76422fe2c88SJonathan Adams { 76522fe2c88SJonathan Adams #ifdef _KERNEL 76622fe2c88SJonathan Adams if (rpt->zcr_ereport != NULL) { 76722fe2c88SJonathan Adams fm_nvlist_destroy(rpt->zcr_ereport, 76822fe2c88SJonathan Adams FM_NVA_FREE); 76922fe2c88SJonathan Adams fm_nvlist_destroy(rpt->zcr_detector, 77022fe2c88SJonathan Adams FM_NVA_FREE); 77122fe2c88SJonathan Adams } 77222fe2c88SJonathan Adams #endif 77322fe2c88SJonathan Adams rpt->zcr_free(rpt->zcr_cbdata, rpt->zcr_cbinfo); 77422fe2c88SJonathan Adams 77522fe2c88SJonathan Adams if (rpt->zcr_ckinfo != NULL) 77622fe2c88SJonathan Adams kmem_free(rpt->zcr_ckinfo, sizeof (*rpt->zcr_ckinfo)); 77722fe2c88SJonathan Adams 77822fe2c88SJonathan Adams kmem_free(rpt, sizeof (*rpt)); 77922fe2c88SJonathan Adams } 78022fe2c88SJonathan Adams 78122fe2c88SJonathan Adams void 78222fe2c88SJonathan Adams zfs_ereport_send_interim_checksum(zio_cksum_report_t *report) 78322fe2c88SJonathan Adams { 78422fe2c88SJonathan Adams #ifdef _KERNEL 78522fe2c88SJonathan Adams fm_ereport_post(report->zcr_ereport, EVCH_SLEEP); 78622fe2c88SJonathan Adams #endif 78722fe2c88SJonathan Adams } 78822fe2c88SJonathan Adams 78922fe2c88SJonathan Adams void 790eb633035STom Caputi zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd, const zbookmark_phys_t *zb, 79122fe2c88SJonathan Adams struct zio *zio, uint64_t offset, uint64_t length, 792eb633035STom Caputi const abd_t *good_data, const abd_t *bad_data, zio_bad_cksum_t *zbc) 79322fe2c88SJonathan Adams { 79422fe2c88SJonathan Adams #ifdef _KERNEL 79522fe2c88SJonathan Adams nvlist_t *ereport = NULL; 79622fe2c88SJonathan Adams nvlist_t *detector = NULL; 79722fe2c88SJonathan Adams zfs_ecksum_info_t *info; 79822fe2c88SJonathan Adams 799eb633035STom Caputi zfs_ereport_start(&ereport, &detector, FM_EREPORT_ZFS_CHECKSUM, 800eb633035STom Caputi spa, vd, zb, zio, offset, length); 80122fe2c88SJonathan Adams 80222fe2c88SJonathan Adams if (ereport == NULL) 80322fe2c88SJonathan Adams return; 80422fe2c88SJonathan Adams 80522fe2c88SJonathan Adams info = annotate_ecksum(ereport, zbc, good_data, bad_data, length, 80622fe2c88SJonathan Adams B_FALSE); 80722fe2c88SJonathan Adams 80822fe2c88SJonathan Adams if (info != NULL) 80922fe2c88SJonathan Adams fm_ereport_post(ereport, EVCH_SLEEP); 81022fe2c88SJonathan Adams 81122fe2c88SJonathan Adams fm_nvlist_destroy(ereport, FM_NVA_FREE); 81222fe2c88SJonathan Adams fm_nvlist_destroy(detector, FM_NVA_FREE); 81322fe2c88SJonathan Adams 81422fe2c88SJonathan Adams if (info != NULL) 81522fe2c88SJonathan Adams kmem_free(info, sizeof (*info)); 81622fe2c88SJonathan Adams #endif 81722fe2c88SJonathan Adams } 81822fe2c88SJonathan Adams 8193d7072f8Seschrock static void 8203d7072f8Seschrock zfs_post_common(spa_t *spa, vdev_t *vd, const char *name) 821ea8dc4b6Seschrock { 822ea8dc4b6Seschrock #ifdef _KERNEL 823ea8dc4b6Seschrock nvlist_t *resource; 824ea8dc4b6Seschrock char class[64]; 825ea8dc4b6Seschrock 826b16da2e2SGeorge Wilson if (spa_load_state(spa) == SPA_LOAD_TRYIMPORT) 8271d713200SEric Schrock return; 8281d713200SEric Schrock 829ea8dc4b6Seschrock if ((resource = fm_nvlist_create(NULL)) == NULL) 830ea8dc4b6Seschrock return; 831ea8dc4b6Seschrock 832ea8dc4b6Seschrock (void) snprintf(class, sizeof (class), "%s.%s.%s", FM_RSRC_RESOURCE, 8333d7072f8Seschrock ZFS_ERROR_CLASS, name); 834ea8dc4b6Seschrock VERIFY(nvlist_add_uint8(resource, FM_VERSION, FM_RSRC_VERSION) == 0); 835ea8dc4b6Seschrock VERIFY(nvlist_add_string(resource, FM_CLASS, class) == 0); 836ea8dc4b6Seschrock VERIFY(nvlist_add_uint64(resource, 837ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_POOL_GUID, spa_guid(spa)) == 0); 838ea8dc4b6Seschrock if (vd) 839ea8dc4b6Seschrock VERIFY(nvlist_add_uint64(resource, 840ea8dc4b6Seschrock FM_EREPORT_PAYLOAD_ZFS_VDEV_GUID, vd->vdev_guid) == 0); 841ea8dc4b6Seschrock 842ea8dc4b6Seschrock fm_ereport_post(resource, EVCH_SLEEP); 843ea8dc4b6Seschrock 844ea8dc4b6Seschrock fm_nvlist_destroy(resource, FM_NVA_FREE); 845ea8dc4b6Seschrock #endif 846ea8dc4b6Seschrock } 8473d7072f8Seschrock 8483d7072f8Seschrock /* 8493d7072f8Seschrock * The 'resource.fs.zfs.removed' event is an internal signal that the given vdev 8503d7072f8Seschrock * has been removed from the system. This will cause the DE to ignore any 8513d7072f8Seschrock * recent I/O errors, inferring that they are due to the asynchronous device 8523d7072f8Seschrock * removal. 8533d7072f8Seschrock */ 8543d7072f8Seschrock void 8553d7072f8Seschrock zfs_post_remove(spa_t *spa, vdev_t *vd) 8563d7072f8Seschrock { 8573d7072f8Seschrock zfs_post_common(spa, vd, FM_RESOURCE_REMOVED); 8583d7072f8Seschrock } 8593d7072f8Seschrock 8603d7072f8Seschrock /* 8613d7072f8Seschrock * The 'resource.fs.zfs.autoreplace' event is an internal signal that the pool 8623d7072f8Seschrock * has the 'autoreplace' property set, and therefore any broken vdevs will be 8633d7072f8Seschrock * handled by higher level logic, and no vdev fault should be generated. 8643d7072f8Seschrock */ 8653d7072f8Seschrock void 8663d7072f8Seschrock zfs_post_autoreplace(spa_t *spa, vdev_t *vd) 8673d7072f8Seschrock { 8683d7072f8Seschrock zfs_post_common(spa, vd, FM_RESOURCE_AUTOREPLACE); 8693d7072f8Seschrock } 870069f55e2SEric Schrock 871069f55e2SEric Schrock /* 872069f55e2SEric Schrock * The 'resource.fs.zfs.statechange' event is an internal signal that the 873069f55e2SEric Schrock * given vdev has transitioned its state to DEGRADED or HEALTHY. This will 874069f55e2SEric Schrock * cause the retire agent to repair any outstanding fault management cases 875069f55e2SEric Schrock * open because the device was not found (fault.fs.zfs.device). 876069f55e2SEric Schrock */ 877069f55e2SEric Schrock void 878069f55e2SEric Schrock zfs_post_state_change(spa_t *spa, vdev_t *vd) 879069f55e2SEric Schrock { 880069f55e2SEric Schrock zfs_post_common(spa, vd, FM_RESOURCE_STATECHANGE); 881069f55e2SEric Schrock } 882