Print this page
8074 need to add FMA event for SSD wearout
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/fm/libdiskstatus/common/libdiskstatus.c
+++ new/usr/src/lib/fm/libdiskstatus/common/libdiskstatus.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 + * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
24 25 */
25 26
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 -
28 27 /*
29 28 * Disk status library
30 29 *
31 30 * This library is responsible for querying health and other status information
32 31 * from disk drives. It is intended to be a generic interface, however only
33 32 * SCSI (and therefore SATA) disks are currently supported. The library is
34 33 * capable of detecting the following status conditions:
35 34 *
36 - * - Predictive failure
37 - * - Overtemp
38 - * - Self-test failure
35 + * - Predictive failure
36 + * - Overtemp
37 + * - Self-test failure
38 + * - Solid State Media wearout
39 39 */
40 40
41 41 #include <assert.h>
42 42 #include <errno.h>
43 43 #include <fcntl.h>
44 44 #include <libdevinfo.h>
45 45 #include <libdiskstatus.h>
46 46 #include <stdlib.h>
47 47 #include <string.h>
48 48 #include <sys/fm/io/scsi.h>
49 49 #include <sys/stat.h>
50 50 #include <unistd.h>
51 51
52 52 #include "ds_impl.h"
53 53 #include "ds_scsi.h"
54 54
55 55 static ds_transport_t *ds_transports[] = {
56 56 &ds_scsi_sim_transport,
57 57 &ds_scsi_uscsi_transport
58 58 };
59 59
60 60 #define NTRANSPORTS (sizeof (ds_transports) / sizeof (ds_transports[0]))
61 61
62 62 /*
63 63 * Open a handle to a disk. This will fail if the device cannot be opened, or
64 64 * if no suitable transport exists for communicating with the device.
65 65 */
66 66 disk_status_t *
67 67 disk_status_open(const char *path, int *error)
68 68 {
69 69 disk_status_t *dsp;
70 70 ds_transport_t *t;
71 71 int i;
72 72
73 73 if ((dsp = calloc(sizeof (disk_status_t), 1)) == NULL) {
74 74 *error = EDS_NOMEM;
75 75 return (NULL);
76 76 }
77 77
78 78 if ((dsp->ds_fd = open(path, O_RDWR)) < 0) {
79 79 *error = EDS_CANT_OPEN;
80 80 free(dsp);
81 81 return (NULL);
82 82 }
83 83
84 84 if ((dsp->ds_path = strdup(path)) == NULL) {
85 85 *error = EDS_NOMEM;
86 86 disk_status_close(dsp);
87 87 return (NULL);
88 88 }
89 89
90 90 for (i = 0; i < NTRANSPORTS; i++) {
91 91 t = ds_transports[i];
92 92
93 93 dsp->ds_transport = t;
94 94
95 95 nvlist_free(dsp->ds_state);
96 96 dsp->ds_state = NULL;
97 97 if (nvlist_alloc(&dsp->ds_state, NV_UNIQUE_NAME, 0) != 0) {
98 98 *error = EDS_NOMEM;
99 99 disk_status_close(dsp);
100 100 return (NULL);
101 101 }
102 102
103 103 if ((dsp->ds_data = t->dt_open(dsp)) == NULL) {
104 104 if (dsp->ds_error != EDS_NO_TRANSPORT) {
105 105 *error = dsp->ds_error;
106 106 disk_status_close(dsp);
107 107 return (NULL);
108 108 }
109 109 } else {
110 110 dsp->ds_error = 0;
111 111 break;
112 112 }
113 113 }
114 114
115 115 if (dsp->ds_error == EDS_NO_TRANSPORT) {
116 116 *error = dsp->ds_error;
117 117 disk_status_close(dsp);
118 118 return (NULL);
119 119 }
120 120
121 121 return (dsp);
122 122 }
123 123
↓ open down ↓ |
75 lines elided |
↑ open up ↑ |
124 124 /*
125 125 * Close a handle to a disk.
126 126 */
127 127 void
128 128 disk_status_close(disk_status_t *dsp)
129 129 {
130 130 nvlist_free(dsp->ds_state);
131 131 nvlist_free(dsp->ds_predfail);
132 132 nvlist_free(dsp->ds_overtemp);
133 133 nvlist_free(dsp->ds_testfail);
134 + nvlist_free(dsp->ds_ssmwearout);
134 135 if (dsp->ds_data)
135 136 dsp->ds_transport->dt_close(dsp->ds_data);
136 137 (void) close(dsp->ds_fd);
137 138 free(dsp->ds_path);
138 139 free(dsp);
139 140 }
140 141
141 142 void
142 143 disk_status_set_debug(boolean_t value)
143 144 {
144 145 ds_debug = value;
145 146 }
146 147
147 148 /*
148 149 * Query basic information
149 150 */
150 151 const char *
151 152 disk_status_path(disk_status_t *dsp)
152 153 {
153 154 return (dsp->ds_path);
154 155 }
155 156
156 157 int
157 158 disk_status_errno(disk_status_t *dsp)
158 159 {
159 160 return (dsp->ds_error);
160 161 }
161 162
162 163 nvlist_t *
163 164 disk_status_get(disk_status_t *dsp)
164 165 {
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
165 166 nvlist_t *nvl = NULL;
166 167 nvlist_t *faults = NULL;
167 168 int err;
168 169
169 170 /*
170 171 * Scan (or rescan) the current device.
171 172 */
172 173 nvlist_free(dsp->ds_testfail);
173 174 nvlist_free(dsp->ds_predfail);
174 175 nvlist_free(dsp->ds_overtemp);
176 + nvlist_free(dsp->ds_ssmwearout);
177 + dsp->ds_ssmwearout = NULL;
175 178 dsp->ds_testfail = dsp->ds_overtemp = dsp->ds_predfail = NULL;
176 179 dsp->ds_faults = 0;
177 180
178 181 /*
179 182 * Even if there is an I/O failure when trying to scan the device, we
180 183 * can still return the current state.
181 184 */
182 185 if (dsp->ds_transport->dt_scan(dsp->ds_data) != 0 &&
183 186 dsp->ds_error != EDS_IO)
184 187 return (NULL);
185 188
186 189 if ((err = nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0)) != 0)
187 190 goto nverror;
188 191
189 192 if ((err = nvlist_add_string(nvl, "protocol", "scsi")) != 0 ||
190 193 (err = nvlist_add_nvlist(nvl, "status", dsp->ds_state)) != 0)
191 194 goto nverror;
192 195
193 196 /*
194 197 * Construct the list of faults.
195 198 */
196 199 if ((err = nvlist_alloc(&faults, NV_UNIQUE_NAME, 0)) != 0)
197 200 goto nverror;
198 201
199 202 if (dsp->ds_predfail != NULL) {
200 203 if ((err = nvlist_add_boolean_value(faults,
201 204 FM_EREPORT_SCSI_PREDFAIL,
202 205 (dsp->ds_faults & DS_FAULT_PREDFAIL) != 0)) != 0 ||
203 206 (err = nvlist_add_nvlist(nvl, FM_EREPORT_SCSI_PREDFAIL,
204 207 dsp->ds_predfail)) != 0)
205 208 goto nverror;
206 209 }
207 210
208 211 if (dsp->ds_testfail != NULL) {
209 212 if ((err = nvlist_add_boolean_value(faults,
210 213 FM_EREPORT_SCSI_TESTFAIL,
211 214 (dsp->ds_faults & DS_FAULT_TESTFAIL) != 0)) != 0 ||
212 215 (err = nvlist_add_nvlist(nvl, FM_EREPORT_SCSI_TESTFAIL,
213 216 dsp->ds_testfail)) != 0)
214 217 goto nverror;
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
215 218 }
216 219
217 220 if (dsp->ds_overtemp != NULL) {
218 221 if ((err = nvlist_add_boolean_value(faults,
219 222 FM_EREPORT_SCSI_OVERTEMP,
220 223 (dsp->ds_faults & DS_FAULT_OVERTEMP) != 0)) != 0 ||
221 224 (err = nvlist_add_nvlist(nvl, FM_EREPORT_SCSI_OVERTEMP,
222 225 dsp->ds_overtemp)) != 0)
223 226 goto nverror;
224 227 }
228 +
229 + if (dsp->ds_ssmwearout != NULL) {
230 + if ((err = nvlist_add_boolean_value(faults,
231 + FM_EREPORT_SCSI_SSMWEAROUT,
232 + (dsp->ds_faults & DS_FAULT_SSMWEAROUT) != 0)) != 0 ||
233 + (err = nvlist_add_nvlist(nvl, FM_EREPORT_SCSI_SSMWEAROUT,
234 + dsp->ds_ssmwearout)) != 0)
235 + goto nverror;
236 + }
225 237
226 238 if ((err = nvlist_add_nvlist(nvl, "faults", faults)) != 0)
227 239 goto nverror;
228 240
229 241 nvlist_free(faults);
230 242 return (nvl);
231 243
232 244 nverror:
233 245 assert(err == ENOMEM);
234 246 nvlist_free(nvl);
235 247 nvlist_free(faults);
236 248 (void) ds_set_errno(dsp, EDS_NOMEM);
237 249 return (NULL);
238 250 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX