* Attempts to read the device header on the provided L2ARC device and writes * it to `hdr'. On success, this function returns 0, otherwise the appropriate * error code is returned. */
| 9994 | * error code is returned. |
| 9995 | */ |
| 9996 | static int |
| 9997 | l2arc_dev_hdr_read(l2arc_dev_t *dev) |
| 9998 | { |
| 9999 | int err; |
| 10000 | uint64_t guid; |
| 10001 | l2arc_dev_hdr_phys_t *l2dhdr = dev->l2ad_dev_hdr; |
| 10002 | const uint64_t l2dhdr_asize = dev->l2ad_dev_hdr_asize; |
| 10003 | abd_t *abd; |
| 10004 | |
| 10005 | guid = spa_guid(dev->l2ad_vdev->vdev_spa); |
| 10006 | |
| 10007 | abd = abd_get_from_buf(l2dhdr, l2dhdr_asize); |
| 10008 | |
| 10009 | err = zio_wait(zio_read_phys(NULL, dev->l2ad_vdev, |
| 10010 | VDEV_LABEL_START_SIZE, l2dhdr_asize, abd, |
| 10011 | ZIO_CHECKSUM_LABEL, NULL, NULL, ZIO_PRIORITY_SYNC_READ, |
| 10012 | ZIO_FLAG_DONT_CACHE | ZIO_FLAG_CANFAIL | |
| 10013 | ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY | |
| 10014 | ZIO_FLAG_SPECULATIVE, B_FALSE)); |
| 10015 | |
| 10016 | abd_put(abd); |
| 10017 | |
| 10018 | if (err != 0) { |
| 10019 | ARCSTAT_BUMP(arcstat_l2_rebuild_abort_dh_errors); |
| 10020 | zfs_dbgmsg("L2ARC IO error (%d) while reading device header, " |
| 10021 | "vdev guid: %llu", err, dev->l2ad_vdev->vdev_guid); |
| 10022 | return (err); |
| 10023 | } |
| 10024 | |
| 10025 | if (l2dhdr->dh_magic == BSWAP_64(L2ARC_DEV_HDR_MAGIC)) |
| 10026 | byteswap_uint64_array(l2dhdr, sizeof (*l2dhdr)); |
| 10027 | |
| 10028 | if (l2dhdr->dh_magic != L2ARC_DEV_HDR_MAGIC || |
| 10029 | l2dhdr->dh_spa_guid != guid || |
| 10030 | l2dhdr->dh_vdev_guid != dev->l2ad_vdev->vdev_guid || |
| 10031 | l2dhdr->dh_version != L2ARC_PERSISTENT_VERSION || |
| 10032 | l2dhdr->dh_log_entries != dev->l2ad_log_entries || |
| 10033 | l2dhdr->dh_end != dev->l2ad_end || |
| 10034 | !l2arc_range_check_overlap(dev->l2ad_start, dev->l2ad_end, |
| 10035 | l2dhdr->dh_evict) || |
| 10036 | (l2dhdr->dh_trim_state != VDEV_TRIM_COMPLETE && |
| 10037 | l2arc_trim_ahead > 0)) { |
| 10038 | /* |
| 10039 | * Attempt to rebuild a device containing no actual dev hdr |
| 10040 | * or containing a header from some other pool or from another |
| 10041 | * version of persistent L2ARC. |
| 10042 | */ |
| 10043 | ARCSTAT_BUMP(arcstat_l2_rebuild_abort_unsupported); |
| 10044 | return (SET_ERROR(ENOTSUP)); |
| 10045 | } |
| 10046 | |
| 10047 | return (0); |
| 10048 | } |
| 10049 | |
| 10050 | /* |
| 10051 | * Reads L2ARC log blocks from storage and validates their contents. |
no test coverage detected