24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * CDDL HEADER START
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * The contents of this file are subject to the terms of the
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Common Development and Distribution License (the "License").
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * You may not use this file except in compliance with the License.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * See the License for the specific language governing permissions
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * and limitations under the License.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * When distributing Covered Code, include this CDDL HEADER in each
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * If applicable, add the following below this CDDL HEADER, with the
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * fields enclosed by brackets "[]" replaced with your own identifying
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * information: Portions Copyright [yyyy] [name of copyright owner]
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * CDDL HEADER END
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Use is subject to license terms.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock#pragma ident "%Z%%M% %I% %E% SMI"
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Disk status library
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * This library is responsible for querying health and other status information
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * from disk drives. It is intended to be a generic interface, however only
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * SCSI (and therefore SATA) disks are currently supported. The library is
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * capable of detecting the following status conditions:
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * - Predictive failure
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * - Overtemp
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * - Self-test failure
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock#define NTRANSPORTS (sizeof (ds_transports) / sizeof (ds_transports[0]))
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Open a handle to a disk. This will fail if the device cannot be opened, or
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * if no suitable transport exists for communicating with the device.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock if ((dsp = calloc(sizeof (disk_status_t), 1)) == NULL) {
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock for (i = 0; i < NTRANSPORTS; i++) {
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock if (nvlist_alloc(&dsp->ds_state, NV_UNIQUE_NAME, 0) != 0) {
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Close a handle to a disk.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Query basic information
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrockconst char *
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Scan (or rescan) the current device.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock dsp->ds_testfail = dsp->ds_overtemp = dsp->ds_predfail = NULL;
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Even if there is an I/O failure when trying to scan the device, we
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * can still return the current state.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock if (dsp->ds_transport->dt_scan(dsp->ds_data) != 0 &&
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock if ((err = nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0)) != 0)
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock if ((err = nvlist_add_string(nvl, "protocol", "scsi")) != 0 ||
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock (err = nvlist_add_nvlist(nvl, "status", dsp->ds_state)) != 0)
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock * Construct the list of faults.
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock if ((err = nvlist_alloc(&faults, NV_UNIQUE_NAME, 0)) != 0)
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock (dsp->ds_faults & DS_FAULT_PREDFAIL) != 0)) != 0 ||
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock (err = nvlist_add_nvlist(nvl, FM_EREPORT_SCSI_PREDFAIL,
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock (dsp->ds_faults & DS_FAULT_TESTFAIL) != 0)) != 0 ||
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock (err = nvlist_add_nvlist(nvl, FM_EREPORT_SCSI_TESTFAIL,
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock (dsp->ds_faults & DS_FAULT_OVERTEMP) != 0)) != 0 ||
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock (err = nvlist_add_nvlist(nvl, FM_EREPORT_SCSI_OVERTEMP,
24db46411fd54f70c35b94bb952eb7ba040e43b4eschrock if ((err = nvlist_add_nvlist(nvl, "faults", faults)) != 0)