Line data Source code
1 : /*
2 : * Copyright (C) 2015 Andrea Mazzoleni
3 : *
4 : * This program is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 3 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * This program is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : #include "portable.h"
19 :
20 : #include "support.h"
21 : #include "state.h"
22 : #include "raid/raid.h"
23 :
24 : /**
25 : * The following are Failure Rate tables computed from the data that
26 : * BackBlaze made available at:
27 : *
28 : * Reliability Data Set For 41,000 Hard Drives Now Open Source
29 : * https://www.backblaze.com/blog/hard-drive-data-feb2015/
30 : *
31 : * Hard Drive Data Sets
32 : * https://www.backblaze.com/hard-drive-test-data.html
33 : *
34 : * Note that in this data:
35 : * - Disks all passed the load-testing and have made it to production,
36 : * and then Dead On Arrival (DOA) failures are excluded.
37 : * - Disks that are predicted to fail by BackBlaze are removed before
38 : * they really fail, not counting as a failure.
39 : *
40 : * The following tables are computed using the data from 2014-02-14 to 2014-12-31
41 : * becasue it's the period when more SMART attributes were gathered.
42 : *
43 : * In this period there are 47322 disk seen, with 1988 removed because failed,
44 : * and with 4121 removed because predicted to fail.
45 : */
46 :
47 : /**
48 : * Number of data point in each table.
49 : */
50 : #define SMART_MEASURES 256
51 :
52 : /*
53 : * Divider for SMART attribute 5
54 : */
55 : static unsigned SMART_5_STEP = 1;
56 :
57 : /*
58 : * Failure rate for 30 days, for a disk
59 : * with SMART attribute 5 at a given value.
60 : */
61 : static double SMART_5_R[SMART_MEASURES] = {
62 : 0.0026, 0.0748, 0.0919, 0.1013, 0.1079,
63 : 0.1137, 0.1194, 0.1235, 0.1301, 0.1398,
64 : 0.1453, 0.1490, 0.1528, 0.1566, 0.1595,
65 : 0.1635, 0.1656, 0.1701, 0.1718, 0.1740,
66 : 0.1762, 0.1787, 0.1808, 0.1833, 0.1858,
67 : 0.1885, 0.1901, 0.1915, 0.1934, 0.1958,
68 : 0.1975, 0.1993, 0.2014, 0.2048, 0.2068,
69 : 0.2088, 0.2109, 0.2120, 0.2137, 0.2160,
70 : 0.2173, 0.2214, 0.2226, 0.2237, 0.2262,
71 : 0.2277, 0.2292, 0.2304, 0.2338, 0.2369,
72 : 0.2381, 0.2396, 0.2411, 0.2427, 0.2445,
73 : 0.2462, 0.2472, 0.2488, 0.2496, 0.2504,
74 : 0.2514, 0.2525, 0.2535, 0.2544, 0.2554,
75 : 0.2571, 0.2583, 0.2601, 0.2622, 0.2631,
76 : 0.2635, 0.2644, 0.2659, 0.2675, 0.2682,
77 : 0.2692, 0.2701, 0.2707, 0.2712, 0.2726,
78 : 0.2745, 0.2767, 0.2778, 0.2784, 0.2800,
79 : 0.2814, 0.2834, 0.2839, 0.2851, 0.2877,
80 : 0.2883, 0.2891, 0.2900, 0.2907, 0.2916,
81 : 0.2934, 0.2950, 0.2969, 0.2975, 0.2983,
82 : 0.2999, 0.3006, 0.3013, 0.3021, 0.3033,
83 : 0.3054, 0.3066, 0.3074, 0.3082, 0.3094,
84 : 0.3106, 0.3112, 0.3120, 0.3137, 0.3141,
85 : 0.3145, 0.3151, 0.3159, 0.3169, 0.3174,
86 : 0.3181, 0.3194, 0.3215, 0.3219, 0.3231,
87 : 0.3234, 0.3237, 0.3242, 0.3255, 0.3270,
88 : 0.3283, 0.3286, 0.3289, 0.3304, 0.3315,
89 : 0.3322, 0.3347, 0.3361, 0.3382, 0.3384,
90 : 0.3395, 0.3398, 0.3401, 0.3405, 0.3411,
91 : 0.3431, 0.3435, 0.3442, 0.3447, 0.3450,
92 : 0.3455, 0.3464, 0.3472, 0.3486, 0.3497,
93 : 0.3501, 0.3509, 0.3517, 0.3531, 0.3535,
94 : 0.3540, 0.3565, 0.3569, 0.3576, 0.3579,
95 : 0.3584, 0.3590, 0.3594, 0.3599, 0.3621,
96 : 0.3627, 0.3642, 0.3649, 0.3655, 0.3658,
97 : 0.3667, 0.3683, 0.3699, 0.3704, 0.3707,
98 : 0.3711, 0.3715, 0.3718, 0.3721, 0.3727,
99 : 0.3740, 0.3744, 0.3748, 0.3753, 0.3756,
100 : 0.3761, 0.3766, 0.3775, 0.3794, 0.3801,
101 : 0.3804, 0.3813, 0.3817, 0.3823, 0.3831,
102 : 0.3847, 0.3875, 0.3881, 0.3886, 0.3890,
103 : 0.3893, 0.3896, 0.3900, 0.3907, 0.3923,
104 : 0.3925, 0.3933, 0.3936, 0.3961, 0.3971,
105 : 0.3981, 0.3989, 0.4007, 0.4012, 0.4018,
106 : 0.4023, 0.4027, 0.4041, 0.4048, 0.4056,
107 : 0.4073, 0.4079, 0.4086, 0.4104, 0.4107,
108 : 0.4109, 0.4112, 0.4118, 0.4133, 0.4139,
109 : 0.4144, 0.4146, 0.4148, 0.4164, 0.4165,
110 : 0.4174, 0.4191, 0.4197, 0.4201, 0.4204,
111 : 0.4210, 0.4213, 0.4216, 0.4221, 0.4231,
112 : 0.4235, 0.4237, 0.4239, 0.4241, 0.4244,
113 : 0.4249,
114 : };
115 :
116 : /*
117 : * Divider for SMART attribute 187
118 : */
119 : static unsigned SMART_187_STEP = 1;
120 :
121 : /*
122 : * Failure rate for 30 days, for a disk
123 : * with SMART attribute 187 at a given value.
124 : */
125 : static double SMART_187_R[SMART_MEASURES] = {
126 : 0.0039, 0.1287, 0.1579, 0.1776, 0.1905,
127 : 0.2013, 0.2226, 0.3263, 0.3612, 0.3869,
128 : 0.4086, 0.4292, 0.4559, 0.5278, 0.5593,
129 : 0.5847, 0.6124, 0.6345, 0.6517, 0.6995,
130 : 0.7308, 0.7541, 0.7814, 0.8122, 0.8306,
131 : 0.8839, 0.9100, 0.9505, 0.9906, 1.0254,
132 : 1.0483, 1.1060, 1.1280, 1.1624, 1.1895,
133 : 1.2138, 1.2452, 1.2864, 1.3120, 1.3369,
134 : 1.3705, 1.3894, 1.4055, 1.4218, 1.4434,
135 : 1.4670, 1.4834, 1.4993, 1.5174, 1.5400,
136 : 1.5572, 1.5689, 1.5808, 1.6198, 1.6346,
137 : 1.6405, 1.6570, 1.6618, 1.6755, 1.6877,
138 : 1.7100, 1.7258, 1.7347, 1.7814, 1.7992,
139 : 1.8126, 1.8225, 1.8269, 1.8341, 1.8463,
140 : 1.8765, 1.8850, 1.9005, 1.9281, 1.9398,
141 : 1.9618, 1.9702, 1.9905, 2.0099, 2.0480,
142 : 2.0565, 2.0611, 2.0709, 2.0846, 2.0895,
143 : 2.0958, 2.1008, 2.1055, 2.1097, 2.1235,
144 : 2.1564, 2.1737, 2.1956, 2.1989, 2.2015,
145 : 2.2148, 2.2355, 2.2769, 2.2940, 2.3045,
146 : 2.3096, 2.3139, 2.3344, 2.3669, 2.3779,
147 : 2.3941, 2.4036, 2.4396, 2.4473, 2.4525,
148 : 2.4656, 2.4762, 2.4787, 2.5672, 2.5732,
149 : 2.5755, 2.5794, 2.5886, 2.6100, 2.6144,
150 : 2.6341, 2.6614, 2.6679, 2.6796, 2.6847,
151 : 2.6872, 2.6910, 2.6934, 2.6995, 2.7110,
152 : 2.7179, 2.7204, 2.7232, 2.7282, 2.7355,
153 : 2.7375, 2.7422, 2.7558, 2.7580, 2.7643,
154 : 2.7767, 2.7770, 2.8016, 2.9292, 2.9294,
155 : 2.9337, 2.9364, 2.9409, 2.9436, 2.9457,
156 : 2.9466, 2.9498, 2.9543, 2.9570, 2.9573,
157 : 2.9663, 2.9708, 2.9833, 2.9859, 2.9895,
158 : 2.9907, 2.9932, 2.9935, 3.0021, 3.0035,
159 : 3.0079, 3.0103, 3.0126, 3.0151, 3.0266,
160 : 3.0288, 3.0320, 3.0330, 3.0343, 3.0373,
161 : 3.0387, 3.0438, 3.0570, 3.0579, 3.0616,
162 : 3.0655, 3.0728, 3.0771, 3.0794, 3.0799,
163 : 3.0812, 3.1769, 3.1805, 3.1819, 3.1860,
164 : 3.1869, 3.2004, 3.2016, 3.2025, 3.2070,
165 : 3.2129, 3.2173, 3.2205, 3.2254, 3.2263,
166 : 3.2300, 3.2413, 3.2543, 3.2580, 3.2595,
167 : 3.2611, 3.2624, 3.2787, 3.2798, 3.2809,
168 : 3.2823, 3.2833, 3.2834, 3.2853, 3.2866,
169 : 3.3332, 3.3580, 3.3595, 3.3625, 3.3631,
170 : 3.3667, 3.3702, 3.3737, 3.3742, 3.3747,
171 : 3.3769, 3.3775, 3.3791, 3.3809, 3.3813,
172 : 3.3814, 3.3822, 3.3827, 3.3828, 3.3833,
173 : 3.3833, 3.3843, 3.3882, 3.3963, 3.4047,
174 : 3.4057, 3.4213, 3.4218, 3.4230, 3.4231,
175 : 3.4240, 3.4262, 3.4283, 3.4283, 3.4288,
176 : 3.4293, 3.4302, 3.4317, 3.4478, 3.4486,
177 : 3.4520,
178 : };
179 :
180 : /*
181 : * Divider for SMART attribute 188
182 : */
183 : static unsigned SMART_188_STEP = 1;
184 :
185 : /*
186 : * Failure rate for 30 days, for a disk
187 : * with SMART attribute 188 at a given value.
188 : */
189 : static double SMART_188_R[SMART_MEASURES] = {
190 : 0.0025, 0.0129, 0.0182, 0.0215, 0.0236,
191 : 0.0257, 0.0279, 0.0308, 0.0341, 0.0382,
192 : 0.0430, 0.0491, 0.0565, 0.0658, 0.0770,
193 : 0.0906, 0.1037, 0.1197, 0.1355, 0.1525,
194 : 0.1686, 0.1864, 0.2011, 0.2157, 0.2281,
195 : 0.2404, 0.2505, 0.2591, 0.2676, 0.2766,
196 : 0.2827, 0.2913, 0.2999, 0.3100, 0.3185,
197 : 0.3298, 0.3361, 0.3446, 0.3506, 0.3665,
198 : 0.3699, 0.3820, 0.3890, 0.4059, 0.4108,
199 : 0.4255, 0.4290, 0.4424, 0.4473, 0.4617,
200 : 0.4667, 0.4770, 0.4829, 0.4977, 0.4997,
201 : 0.5102, 0.5137, 0.5283, 0.5316, 0.5428,
202 : 0.5480, 0.5597, 0.5634, 0.5791, 0.5826,
203 : 0.5929, 0.5945, 0.6025, 0.6102, 0.6175,
204 : 0.6245, 0.6313, 0.6421, 0.6468, 0.6497,
205 : 0.6557, 0.6570, 0.6647, 0.6698, 0.6769,
206 : 0.6849, 0.6884, 0.6925, 0.7025, 0.7073,
207 : 0.7161, 0.7223, 0.7256, 0.7280, 0.7411,
208 : 0.7445, 0.7530, 0.7628, 0.7755, 0.7900,
209 : 0.8006, 0.8050, 0.8098, 0.8132, 0.8192,
210 : 0.8230, 0.8293, 0.8356, 0.8440, 0.8491,
211 : 0.8672, 0.8766, 0.8907, 0.8934, 0.8992,
212 : 0.9062, 0.9111, 0.9209, 0.9290, 0.9329,
213 : 0.9378, 0.9385, 0.9402, 0.9427, 0.9448,
214 : 0.9459, 0.9568, 0.9626, 0.9628, 0.9730,
215 : 0.9765, 0.9797, 0.9825, 0.9873, 0.9902,
216 : 0.9926, 0.9991, 1.0031, 1.0044, 1.0062,
217 : 1.0120, 1.0148, 1.0188, 1.0218, 1.0231,
218 : 1.0249, 1.0277, 1.0335, 1.0355, 1.0417,
219 : 1.0467, 1.0474, 1.0510, 1.0529, 1.0532,
220 : 1.0562, 1.0610, 1.0702, 1.0708, 1.0800,
221 : 1.0804, 1.0845, 1.1120, 1.1191, 1.1225,
222 : 1.1264, 1.1265, 1.1335, 1.1347, 1.1479,
223 : 1.1479, 1.1519, 1.1545, 1.1645, 1.1646,
224 : 1.1647, 1.1649, 1.1678, 1.1713, 1.1723,
225 : 1.1733, 1.1736, 1.1736, 1.1738, 1.1739,
226 : 1.1739, 1.1741, 1.1741, 1.1746, 1.1746,
227 : 1.1748, 1.1750, 1.1760, 1.1794, 1.1854,
228 : 1.1908, 1.1912, 1.1912, 1.1971, 1.2033,
229 : 1.2033, 1.2120, 1.2166, 1.2185, 1.2185,
230 : 1.2189, 1.2211, 1.2226, 1.2234, 1.2320,
231 : 1.2345, 1.2345, 1.2347, 1.2350, 1.2350,
232 : 1.2407, 1.2408, 1.2408, 1.2408, 1.2409,
233 : 1.2460, 1.2518, 1.2519, 1.2519, 1.2519,
234 : 1.2520, 1.2520, 1.2521, 1.2521, 1.2521,
235 : 1.2593, 1.2745, 1.2760, 1.2772, 1.2831,
236 : 1.2833, 1.2890, 1.2906, 1.3166, 1.3201,
237 : 1.3202, 1.3202, 1.3202, 1.3204, 1.3204,
238 : 1.3314, 1.3422, 1.3423, 1.3441, 1.3491,
239 : 1.3583, 1.3602, 1.3606, 1.3636, 1.3650,
240 : 1.3661, 1.3703, 1.3708, 1.3716, 1.3730,
241 : 1.3731,
242 : };
243 :
244 : /*
245 : * Divider for SMART attribute 193
246 : */
247 : static unsigned SMART_193_STEP = 649;
248 :
249 : /*
250 : * Failure rate for 30 days, for a disk
251 : * with SMART attribute 193 at a given value.
252 : */
253 : static double SMART_193_R[SMART_MEASURES] = {
254 : 0.0000, 0.0016, 0.0032, 0.0036, 0.0039,
255 : 0.0042, 0.0046, 0.0049, 0.0052, 0.0054,
256 : 0.0057, 0.0060, 0.0062, 0.0065, 0.0068,
257 : 0.0071, 0.0074, 0.0077, 0.0080, 0.0083,
258 : 0.0086, 0.0091, 0.0094, 0.0098, 0.0101,
259 : 0.0104, 0.0108, 0.0111, 0.0119, 0.0122,
260 : 0.0127, 0.0130, 0.0134, 0.0137, 0.0141,
261 : 0.0144, 0.0146, 0.0152, 0.0155, 0.0159,
262 : 0.0163, 0.0165, 0.0168, 0.0172, 0.0176,
263 : 0.0179, 0.0184, 0.0188, 0.0190, 0.0194,
264 : 0.0197, 0.0201, 0.0204, 0.0207, 0.0209,
265 : 0.0213, 0.0215, 0.0219, 0.0221, 0.0225,
266 : 0.0229, 0.0234, 0.0241, 0.0246, 0.0253,
267 : 0.0263, 0.0278, 0.0286, 0.0293, 0.0298,
268 : 0.0302, 0.0306, 0.0311, 0.0315, 0.0319,
269 : 0.0322, 0.0329, 0.0334, 0.0338, 0.0343,
270 : 0.0348, 0.0352, 0.0358, 0.0362, 0.0367,
271 : 0.0371, 0.0374, 0.0378, 0.0383, 0.0388,
272 : 0.0393, 0.0397, 0.0401, 0.0404, 0.0410,
273 : 0.0416, 0.0422, 0.0428, 0.0436, 0.0443,
274 : 0.0449, 0.0454, 0.0457, 0.0462, 0.0468,
275 : 0.0473, 0.0479, 0.0483, 0.0488, 0.0491,
276 : 0.0493, 0.0497, 0.0500, 0.0504, 0.0507,
277 : 0.0510, 0.0514, 0.0519, 0.0523, 0.0528,
278 : 0.0533, 0.0538, 0.0542, 0.0547, 0.0551,
279 : 0.0556, 0.0560, 0.0565, 0.0572, 0.0577,
280 : 0.0584, 0.0590, 0.0594, 0.0599, 0.0603,
281 : 0.0607, 0.0611, 0.0616, 0.0621, 0.0626,
282 : 0.0632, 0.0639, 0.0647, 0.0655, 0.0661,
283 : 0.0669, 0.0676, 0.0683, 0.0691, 0.0699,
284 : 0.0708, 0.0713, 0.0719, 0.0724, 0.0730,
285 : 0.0736, 0.0745, 0.0751, 0.0759, 0.0769,
286 : 0.0779, 0.0787, 0.0796, 0.0804, 0.0815,
287 : 0.0825, 0.0833, 0.0840, 0.0847, 0.0854,
288 : 0.0859, 0.0865, 0.0873, 0.0881, 0.0890,
289 : 0.0900, 0.0912, 0.0919, 0.0929, 0.0942,
290 : 0.0956, 0.0965, 0.0976, 0.0986, 0.0995,
291 : 0.1006, 0.1019, 0.1031, 0.1038, 0.1045,
292 : 0.1051, 0.1058, 0.1066, 0.1072, 0.1077,
293 : 0.1084, 0.1091, 0.1099, 0.1104, 0.1111,
294 : 0.1118, 0.1127, 0.1135, 0.1142, 0.1149,
295 : 0.1157, 0.1163, 0.1168, 0.1173, 0.1179,
296 : 0.1184, 0.1189, 0.1195, 0.1203, 0.1208,
297 : 0.1213, 0.1223, 0.1231, 0.1240, 0.1246,
298 : 0.1252, 0.1260, 0.1269, 0.1276, 0.1287,
299 : 0.1303, 0.1311, 0.1319, 0.1328, 0.1335,
300 : 0.1341, 0.1348, 0.1362, 0.1373, 0.1380,
301 : 0.1387, 0.1392, 0.1398, 0.1403, 0.1408,
302 : 0.1412, 0.1418, 0.1422, 0.1428, 0.1434,
303 : 0.1439, 0.1445, 0.1451, 0.1457, 0.1464,
304 : 0.1469, 0.1475, 0.1480, 0.1486, 0.1491,
305 : 0.1498,
306 : };
307 :
308 : /*
309 : * Divider for SMART attribute 197
310 : */
311 : static unsigned SMART_197_STEP = 1;
312 :
313 : /*
314 : * Failure rate for 30 days, for a disk
315 : * with SMART attribute 197 at a given value.
316 : */
317 : static double SMART_197_R[SMART_MEASURES] = {
318 : 0.0028, 0.2972, 0.3883, 0.4363, 0.4644,
319 : 0.4813, 0.4948, 0.5051, 0.5499, 0.8535,
320 : 0.8678, 0.8767, 0.8882, 0.8933, 0.9012,
321 : 0.9076, 0.9368, 1.1946, 1.2000, 1.2110,
322 : 1.2177, 1.2305, 1.2385, 1.2447, 1.2699,
323 : 1.4713, 1.4771, 1.4802, 1.4887, 1.5292,
324 : 1.5384, 1.5442, 1.5645, 1.7700, 1.7755,
325 : 1.7778, 1.7899, 1.7912, 1.7991, 1.7998,
326 : 1.8090, 1.9974, 1.9992, 2.0088, 2.0132,
327 : 2.0146, 2.0161, 2.0171, 2.0273, 2.1845,
328 : 2.1866, 2.1877, 2.1900, 2.1922, 2.1944,
329 : 2.1974, 2.2091, 2.3432, 2.3459, 2.3463,
330 : 2.3468, 2.3496, 2.3503, 2.3533, 2.3593,
331 : 2.4604, 2.4606, 2.4609, 2.4612, 2.4620,
332 : 2.4626, 2.4638, 2.4689, 2.5575, 2.5581,
333 : 2.5586, 2.5586, 2.5588, 2.5602, 2.5602,
334 : 2.5648, 2.6769, 2.6769, 2.6769, 2.6794,
335 : 2.6805, 2.6811, 2.6814, 2.6862, 2.7742,
336 : 2.7755, 2.7771, 2.7780, 2.7790, 2.7797,
337 : 2.7807, 2.7871, 2.9466, 2.9478, 2.9492,
338 : 2.9612, 2.9618, 2.9624, 2.9628, 2.9669,
339 : 3.1467, 3.1481, 3.1494, 3.1499, 3.1504,
340 : 3.1507, 3.1509, 3.1532, 3.2675, 3.2681,
341 : 3.2703, 3.2712, 3.2714, 3.2726, 3.2726,
342 : 3.2743, 3.3376, 3.3379, 3.3382, 3.3397,
343 : 3.3403, 3.3410, 3.3410, 3.3429, 3.4052,
344 : 3.4052, 3.4052, 3.4052, 3.4052, 3.4053,
345 : 3.4053, 3.4075, 3.4616, 3.4616, 3.4616,
346 : 3.4616, 3.4616, 3.4616, 3.4620, 3.4634,
347 : 3.4975, 3.4975, 3.4975, 3.4975, 3.4979,
348 : 3.4979, 3.4979, 3.4998, 3.5489, 3.5489,
349 : 3.5489, 3.5489, 3.5489, 3.5493, 3.5497,
350 : 3.5512, 3.5827, 3.5828, 3.5828, 3.5828,
351 : 3.5828, 3.5828, 3.5828, 3.5844, 3.6251,
352 : 3.6251, 3.6251, 3.6267, 3.6267, 3.6271,
353 : 3.6271, 3.6279, 3.6562, 3.6562, 3.6563,
354 : 3.7206, 3.7242, 3.7332, 3.7332, 3.7346,
355 : 3.7548, 3.7548, 3.7553, 3.7576, 3.7581,
356 : 3.7586, 3.7587, 3.7600, 3.7773, 3.7812,
357 : 3.7836, 3.7841, 3.7842, 3.7851, 3.7856,
358 : 3.7876, 3.8890, 3.8890, 3.8890, 3.8890,
359 : 3.8890, 3.8890, 3.8890, 3.8897, 3.9111,
360 : 3.9114, 3.9114, 3.9114, 3.9114, 3.9114,
361 : 3.9114, 3.9126, 3.9440, 3.9440, 3.9440,
362 : 3.9440, 3.9440, 3.9498, 3.9498, 3.9509,
363 : 3.9783, 3.9783, 3.9784, 3.9784, 3.9784,
364 : 3.9784, 4.0012, 4.0019, 4.0406, 4.0413,
365 : 4.0413, 4.0413, 4.0413, 4.0414, 4.0414,
366 : 4.0421, 4.0552, 4.0552, 4.0558, 4.0558,
367 : 4.0558, 4.0558, 4.0558, 4.0563, 4.0753,
368 : 4.0753, 4.0760, 4.1131, 4.1131, 4.1131,
369 : 4.1131,
370 : };
371 :
372 : /*
373 : * Divider for SMART attribute 198
374 : */
375 : static unsigned SMART_198_STEP = 1;
376 :
377 : /*
378 : * Failure rate for 30 days, for a disk
379 : * with SMART attribute 198 at a given value.
380 : */
381 : static double SMART_198_R[SMART_MEASURES] = {
382 : 0.0030, 0.5479, 0.5807, 0.5949, 0.6046,
383 : 0.6086, 0.6139, 0.6224, 0.6639, 1.0308,
384 : 1.0329, 1.0364, 1.0371, 1.0387, 1.0399,
385 : 1.0421, 1.0675, 1.3730, 1.3733, 1.3741,
386 : 1.3741, 1.3752, 1.3794, 1.3800, 1.3985,
387 : 1.6291, 1.6303, 1.6309, 1.6352, 1.6384,
388 : 1.6448, 1.6464, 1.6645, 1.8949, 1.8951,
389 : 1.8962, 1.9073, 1.9073, 1.9152, 1.9161,
390 : 1.9240, 2.1308, 2.1315, 2.1328, 2.1328,
391 : 2.1328, 2.1328, 2.1329, 2.1439, 2.3203,
392 : 2.3205, 2.3205, 2.3205, 2.3205, 2.3205,
393 : 2.3205, 2.3265, 2.4729, 2.4729, 2.4729,
394 : 2.4729, 2.4729, 2.4729, 2.4729, 2.4778,
395 : 2.5900, 2.5900, 2.5901, 2.5901, 2.5901,
396 : 2.5901, 2.5901, 2.5949, 2.6964, 2.6965,
397 : 2.6965, 2.6965, 2.6965, 2.6965, 2.6965,
398 : 2.7010, 2.8328, 2.8328, 2.8328, 2.8329,
399 : 2.8329, 2.8329, 2.8329, 2.8366, 2.9405,
400 : 2.9405, 2.9405, 2.9405, 2.9405, 2.9405,
401 : 2.9405, 2.9442, 3.1344, 3.1344, 3.1346,
402 : 3.1463, 3.1463, 3.1463, 3.1463, 3.1493,
403 : 3.3076, 3.3076, 3.3076, 3.3076, 3.3076,
404 : 3.3077, 3.3077, 3.3097, 3.4456, 3.4456,
405 : 3.4456, 3.4456, 3.4456, 3.4456, 3.4456,
406 : 3.4473, 3.5236, 3.5236, 3.5236, 3.5236,
407 : 3.5236, 3.5236, 3.5236, 3.5249, 3.6004,
408 : 3.6004, 3.6004, 3.6004, 3.6004, 3.6004,
409 : 3.6004, 3.6026, 3.6684, 3.6684, 3.6684,
410 : 3.6684, 3.6684, 3.6684, 3.6684, 3.6697,
411 : 3.7121, 3.7121, 3.7121, 3.7121, 3.7121,
412 : 3.7121, 3.7121, 3.7136, 3.7744, 3.7744,
413 : 3.7744, 3.7744, 3.7744, 3.7745, 3.7745,
414 : 3.7756, 3.8151, 3.8151, 3.8151, 3.8151,
415 : 3.8151, 3.8151, 3.8151, 3.8163, 3.8673,
416 : 3.8673, 3.8673, 3.8673, 3.8673, 3.8673,
417 : 3.8673, 3.8680, 3.9044, 3.9044, 3.9044,
418 : 3.9044, 3.9044, 3.9044, 3.9044, 3.9056,
419 : 3.9297, 3.9297, 3.9297, 3.9297, 3.9297,
420 : 3.9297, 3.9297, 3.9305, 3.9494, 3.9494,
421 : 3.9494, 3.9494, 3.9494, 3.9494, 3.9494,
422 : 3.9514, 4.0725, 4.0725, 4.0725, 4.0725,
423 : 4.0725, 4.0725, 4.0725, 4.0731, 4.0990,
424 : 4.0993, 4.0993, 4.0993, 4.0993, 4.0993,
425 : 4.0993, 4.1004, 4.1385, 4.1385, 4.1385,
426 : 4.1386, 4.1386, 4.1387, 4.1387, 4.1398,
427 : 4.1732, 4.2284, 4.2284, 4.2284, 4.2284,
428 : 4.2284, 4.2284, 4.2290, 4.2781, 4.2781,
429 : 4.2963, 4.2963, 4.2963, 4.2963, 4.2963,
430 : 4.2971, 4.3141, 4.3141, 4.3141, 4.3141,
431 : 4.3141, 4.3141, 4.3141, 4.3146, 4.3393,
432 : 4.3393, 4.3393, 4.3393, 4.3393, 4.3393,
433 : 4.3393,
434 : };
435 :
436 : /**
437 : * Computes the estimated Annual Failure Rate from the specified table.
438 : */
439 72 : static double smart_afr_value(double* tab, unsigned step, uint64_t value)
440 : {
441 72 : value /= step;
442 :
443 72 : if (value >= SMART_MEASURES)
444 0 : value = SMART_MEASURES - 1;
445 :
446 : /* table rates are for a month, so we scale to a year */
447 72 : return 365.0 / 30.0 * tab[value];
448 : }
449 :
450 : /**
451 : * Computes the estimated Annual Failure Rate of a set of SMART attributes.
452 : *
453 : * We define the Annual Failure Rate as the average number of
454 : * failures you expect in a year from a disk slot:
455 : *
456 : * AFR = 8760/MTBF (Mean Time Between Failures in hours).
457 : *
458 : * Note that this definition is different from the one given
459 : * by Seagate, that defines AFR = 1 - exp(-8760/MTBF), that
460 : * instead represents the probability of a failure in the next
461 : * year.
462 : *
463 : * To combine the different AFR from different SMART attributes,
464 : * we use the maximum rate reported, and we do not sum them,
465 : * because the attributes are not independent.
466 : */
467 13 : static double smart_afr(uint64_t* smart)
468 : {
469 13 : double afr = 0;
470 13 : uint64_t mask32 = 0xffffffffU;
471 13 : uint64_t mask16 = 0xffffU;
472 :
473 13 : if (smart[5] != SMART_UNASSIGNED) {
474 12 : double r = smart_afr_value(SMART_5_R, SMART_5_STEP, smart[5] & mask32);
475 12 : if (afr < r)
476 12 : afr = r;
477 : }
478 :
479 13 : if (smart[187] != SMART_UNASSIGNED) {
480 : /* with some disks, only the lower 16 bits are significative */
481 : /* See: http://web.archive.org/web/20130507072056/http://media.kingston.com/support/downloads/MKP_306_SMART_attribute.pdf */
482 12 : double r = smart_afr_value(SMART_187_R, SMART_187_STEP, smart[187] & mask16);
483 12 : if (afr < r)
484 12 : afr = r;
485 : }
486 :
487 13 : if (smart[188] != SMART_UNASSIGNED) {
488 : /* with Seagate disks, there are three different 16 bits value reported */
489 : /* the lowest one is the most significative */
490 12 : double r = smart_afr_value(SMART_188_R, SMART_188_STEP, smart[188] & mask16);
491 12 : if (afr < r)
492 0 : afr = r;
493 : }
494 :
495 13 : if (smart[193] != SMART_UNASSIGNED) {
496 12 : double r = smart_afr_value(SMART_193_R, SMART_193_STEP, smart[193] & mask32);
497 12 : if (afr < r)
498 0 : afr = r;
499 : }
500 :
501 13 : if (smart[197] != SMART_UNASSIGNED) {
502 12 : double r = smart_afr_value(SMART_197_R, SMART_197_STEP, smart[197] & mask32);
503 12 : if (afr < r)
504 0 : afr = r;
505 : }
506 :
507 13 : if (smart[198] != SMART_UNASSIGNED) {
508 12 : double r = smart_afr_value(SMART_198_R, SMART_198_STEP, smart[198] & mask32);
509 12 : if (afr < r)
510 0 : afr = r;
511 : }
512 :
513 13 : return afr;
514 : }
515 :
516 : /**
517 : * Factorial.
518 : */
519 31 : static double fact(unsigned n)
520 : {
521 31 : double v = 1;
522 :
523 62 : while (n > 1)
524 0 : v *= n--;
525 :
526 31 : return v;
527 : }
528 :
529 : /**
530 : * Probability of having exactly ::n events in a Poisson
531 : * distribution with rate ::rate in a time unit.
532 : */
533 31 : static double poisson_prob_n_failures(double rate, unsigned n)
534 : {
535 31 : return pow(rate, n) * exp(-rate) / fact(n);
536 : }
537 :
538 : /**
539 : * Probability of having ::n or more events in a Poisson
540 : * distribution with rate ::rate in a time unit.
541 : */
542 31 : static double poisson_prob_n_or_more_failures(double rate, unsigned n)
543 : {
544 31 : double p_neg = 0;
545 : unsigned i;
546 :
547 62 : for (i = 0; i < n; ++i)
548 31 : p_neg += poisson_prob_n_failures(rate, n - 1 - i);
549 :
550 31 : return 1 - p_neg;
551 : }
552 :
553 : /**
554 : * Probability of having data loss in a RAID system with the specified ::redundancy
555 : * supposing the specified ::array_failure_rate, and ::replace_rate.
556 : */
557 18 : static double raid_prob_of_one_or_more_failures(double array_failure_rate, double replace_rate, unsigned n, unsigned redundancy)
558 : {
559 : unsigned i;
560 : double MTBF;
561 : double MTTR;
562 : double MTTDL;
563 : double raid_failure_rate;
564 :
565 : /*
566 : * Use the MTTDL model (Mean Time To Data Loss) to estimate the
567 : * failure rate of the array.
568 : *
569 : * See:
570 : * Garth Alan Gibson, "Redundant Disk Arrays: Reliable, Parallel Secondary Storage", 1990
571 : */
572 :
573 : /* get the Mean Time Between Failure of a single disk */
574 : /* from the array failure rate */
575 18 : MTBF = n / array_failure_rate;
576 :
577 : /* get the Mean Time Between Repair (the time that a failed disk is replaced) */
578 : /* from the repair rate */
579 18 : MTTR = 1.0 / replace_rate;
580 :
581 : /* use the approximated MTTDL equation */
582 18 : MTTDL = pow(MTBF, redundancy + 1) / pow(MTTR, redundancy);
583 99 : for (i = 0; i < redundancy + 1; ++i)
584 81 : MTTDL /= n - i;
585 :
586 : /* the raid failure rate is just the inverse of the MTTDL */
587 18 : raid_failure_rate = 1.0 / MTTDL;
588 :
589 : /* probability of at least one RAID failure */
590 : /* note that is almost equal at the probabilty of */
591 : /* the first failure. */
592 18 : return poisson_prob_n_or_more_failures(raid_failure_rate, 1);
593 : }
594 :
595 : /**
596 : * Print a string with space padding.
597 : */
598 52 : static void printl(const char* str, size_t pad)
599 : {
600 : size_t len;
601 :
602 52 : printf("%s", str);
603 :
604 52 : len = strlen(str);
605 :
606 245 : while (len < pad) {
607 141 : printf(" ");
608 141 : ++len;
609 : }
610 52 : }
611 :
612 : /**
613 : * Print a probability with space padding.
614 : */
615 18 : static void printp(double v, size_t pad)
616 : {
617 : char buf[64];
618 18 : const char* s = "%";
619 :
620 18 : if (v > 0.1)
621 4 : snprintf(buf, sizeof(buf), "%5.2f%s", v, s);
622 14 : else if (v > 0.01)
623 2 : snprintf(buf, sizeof(buf), "%6.3f%s", v, s);
624 12 : else if (v > 0.001)
625 3 : snprintf(buf, sizeof(buf), "%7.4f%s", v, s);
626 9 : else if (v > 0.0001)
627 2 : snprintf(buf, sizeof(buf), "%8.5f%s", v, s);
628 7 : else if (v > 0.00001)
629 2 : snprintf(buf, sizeof(buf), "%9.6f%s", v, s);
630 5 : else if (v > 0.000001)
631 1 : snprintf(buf, sizeof(buf), "%10.7f%s", v, s);
632 4 : else if (v > 0.0000001)
633 1 : snprintf(buf, sizeof(buf), "%11.8f%s", v, s);
634 3 : else if (v > 0.00000001)
635 1 : snprintf(buf, sizeof(buf), "%12.9f%s", v, s);
636 2 : else if (v > 0.000000001)
637 1 : snprintf(buf, sizeof(buf), "%13.10f%s", v, s);
638 1 : else if (v > 0.0000000001)
639 0 : snprintf(buf, sizeof(buf), "%14.11f%s", v, s);
640 1 : else if (v > 0.00000000001)
641 1 : snprintf(buf, sizeof(buf), "%15.12f%s", v, s);
642 0 : else if (v > 0.000000000001)
643 0 : snprintf(buf, sizeof(buf), "%16.13f%s", v, s);
644 : else
645 0 : snprintf(buf, sizeof(buf), "%17.14f%s", v, s);
646 18 : printl(buf, pad);
647 18 : }
648 :
649 1 : static void state_smart(unsigned n, tommy_list* low)
650 : {
651 : tommy_node* i;
652 : unsigned j;
653 : size_t device_pad;
654 : size_t serial_pad;
655 : int have_parent;
656 : double array_failure_rate;
657 : double p_at_least_one_failure;
658 1 : int make_it_fail = 0;
659 1 : uint64_t mask32 = 0xffffffffU;
660 1 : uint64_t mask16 = 0xffffU;
661 :
662 : /* compute lengths for padding */
663 1 : device_pad = 0;
664 1 : serial_pad = 0;
665 1 : have_parent = 0;
666 17 : for (i = tommy_list_head(low); i != 0; i = i->next) {
667 : size_t len;
668 16 : devinfo_t* devinfo = i->data;
669 :
670 16 : len = strlen(devinfo->file);
671 16 : if (len > device_pad)
672 1 : device_pad = len;
673 :
674 16 : len = strlen(devinfo->smart_serial);
675 16 : if (len > serial_pad)
676 2 : serial_pad = len;
677 :
678 16 : if (devinfo->parent != 0)
679 0 : have_parent = 1;
680 : }
681 :
682 1 : printf("SnapRAID SMART report:\n");
683 1 : printf("\n");
684 1 : printf(" Temp");
685 1 : printf(" Power");
686 1 : printf(" Error");
687 1 : printf(" FP");
688 1 : printf(" Size");
689 1 : printf("\n");
690 1 : printf(" C");
691 1 : printf(" OnDays");
692 1 : printf(" Count");
693 1 : printf(" ");
694 1 : printf(" TB");
695 1 : printf(" "); printl("Serial", serial_pad);
696 1 : printf(" "); printl("Device", device_pad);
697 1 : printf(" Disk");
698 1 : printf("\n");
699 : /* |<##################################################################72>|####80>| */
700 1 : printf(" -----------------------------------------------------------------------\n");
701 :
702 1 : array_failure_rate = 0;
703 17 : for (i = tommy_list_head(low); i != 0; i = i->next) {
704 16 : devinfo_t* devinfo = i->data;
705 : double afr;
706 : uint64_t flag;
707 :
708 16 : if (devinfo->smart[194] != SMART_UNASSIGNED)
709 15 : printf("%7" PRIu64, devinfo->smart[194] & mask16);
710 1 : else if (devinfo->smart[190] != SMART_UNASSIGNED)
711 0 : printf("%7" PRIu64, devinfo->smart[190] & mask16);
712 : else
713 1 : printf(" -");
714 :
715 16 : if (devinfo->smart[9] != SMART_UNASSIGNED)
716 15 : printf("%7" PRIu64, (devinfo->smart[9] & mask32) / 24);
717 : else
718 1 : printf(" -");
719 :
720 16 : if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED)
721 8 : flag = devinfo->smart[SMART_FLAGS];
722 : else
723 8 : flag = 0;
724 16 : if (flag & SMARTCTL_FLAG_FAIL)
725 1 : printf(" FAIL");
726 15 : else if (flag & SMARTCTL_FLAG_PREFAIL)
727 1 : printf(" PREFAIL");
728 14 : else if (flag & SMARTCTL_FLAG_PREFAIL_LOGGED)
729 1 : printf(" logfail");
730 13 : else if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED
731 13 : && devinfo->smart[SMART_ERROR] != 0)
732 1 : printf("%8" PRIu64, devinfo->smart[SMART_ERROR]);
733 12 : else if (flag & SMARTCTL_FLAG_ERROR)
734 1 : printf(" logerr");
735 11 : else if (flag & SMARTCTL_FLAG_ERROR_LOGGED)
736 1 : printf(" selferr");
737 10 : else if (devinfo->smart[SMART_ERROR] == 0)
738 10 : printf(" 0");
739 : else
740 0 : printf(" -");
741 :
742 : /* if some fail/prefail attribute, make the command to fail */
743 16 : if (flag & (SMARTCTL_FLAG_FAIL | SMARTCTL_FLAG_PREFAIL))
744 2 : make_it_fail = 1;
745 :
746 : /* note that in older smartmontools, like 5.x, rotation rate is not present */
747 : /* and then it could remain unassigned */
748 :
749 16 : if (flag & (SMARTCTL_FLAG_UNSUPPORTED | SMARTCTL_FLAG_OPEN)) {
750 : /* if error running smartctl, skip AFR estimation */
751 2 : afr = 0;
752 2 : printf(" n/a");
753 14 : } else if (devinfo->smart[SMART_ROTATION_RATE] == 0) {
754 : /* if SSD, skip AFR estimation as data is from not SSD disks */
755 1 : afr = 0;
756 1 : printf(" SSD");
757 : } else {
758 13 : afr = smart_afr(devinfo->smart);
759 :
760 13 : if (afr == 0) {
761 : /* this happens only if no data */
762 1 : printf(" -");
763 : } else {
764 : /* use only the disks in the array */
765 12 : if (devinfo->parent != 0 || !have_parent)
766 12 : array_failure_rate += afr;
767 :
768 12 : printf("%4.0f%%", poisson_prob_n_or_more_failures(afr, 1) * 100);
769 : }
770 : }
771 :
772 16 : if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED)
773 15 : printf(" %4.1f", devinfo->smart[SMART_SIZE] / 1E12);
774 : else
775 1 : printf(" -");
776 :
777 16 : printf(" ");
778 16 : if (*devinfo->smart_serial)
779 15 : printl(devinfo->smart_serial, serial_pad);
780 : else
781 1 : printl("-", serial_pad);
782 :
783 16 : printf(" ");
784 16 : if (*devinfo->file)
785 15 : printl(devinfo->file, device_pad);
786 : else
787 1 : printl("-", device_pad);
788 :
789 16 : printf(" ");
790 16 : if (*devinfo->name)
791 15 : printf("%s", devinfo->name);
792 : else
793 1 : printf("-");
794 :
795 16 : printf("\n");
796 :
797 16 : log_tag("smart:%s:%s\n", devinfo->file, devinfo->name);
798 16 : if (devinfo->smart_serial[0])
799 15 : log_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc(devinfo->smart_serial));
800 16 : if (afr != 0)
801 12 : log_tag("attr:%s:%s:afr:%g\n", devinfo->file, devinfo->name, afr);
802 16 : if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED)
803 15 : log_tag("attr:%s:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_SIZE]);
804 16 : if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED)
805 16 : log_tag("attr:%s:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ERROR]);
806 16 : if (devinfo->smart[SMART_ROTATION_RATE] != SMART_UNASSIGNED)
807 16 : log_tag("attr:%s:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ROTATION_RATE]);
808 16 : if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED)
809 8 : log_tag("attr:%s:%s:flags:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_FLAGS], devinfo->smart[SMART_FLAGS]);
810 4112 : for (j = 0; j < 256; ++j)
811 4096 : if (devinfo->smart[j] != SMART_UNASSIGNED)
812 3840 : log_tag("attr:%s:%s:%u:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, j, devinfo->smart[j], devinfo->smart[j]);
813 : }
814 :
815 1 : printf("\n");
816 :
817 : /* |<##################################################################72>|####80>| */
818 1 : printf("The FP column is the estimated probability (in percentage) that the disk\n");
819 1 : printf("is going to fail in the next year.\n");
820 1 : printf("\n");
821 :
822 : /*
823 : * The probability of one and of at least one failure is computed assuming
824 : * a Poisson distribution with the estimated array failure rate.
825 : */
826 1 : p_at_least_one_failure = poisson_prob_n_or_more_failures(array_failure_rate, 1);
827 :
828 1 : printf("Probability that at least one disk is going to fail in the next year is %.0f%%.\n", p_at_least_one_failure * 100);
829 1 : log_tag("summary:array_failure:%g:%g\n", array_failure_rate, p_at_least_one_failure);
830 :
831 : /* print extra stats only in verbose mode */
832 1 : if (msg_level < MSG_VERBOSE)
833 0 : goto bail;
834 :
835 : /* |<##################################################################72>|####80>| */
836 1 : printf("\n");
837 1 : printf("Probability of data loss in the next year for different parity and\n");
838 1 : printf("combined scrub and repair time:\n");
839 1 : printf("\n");
840 1 : printf(" Parity 1 Week 1 Month 3 Months\n");
841 1 : printf(" -----------------------------------------------------------------------\n");
842 7 : for (j = 0; j < RAID_PARITY_MAX; ++j) {
843 6 : printf("%6u", j + 1);
844 6 : printf(" ");
845 6 : printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 7, n, j + 1) * 100, 19);
846 6 : printf(" ");
847 6 : printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 30, n, j + 1) * 100, 17);
848 6 : printf(" ");
849 6 : printp(raid_prob_of_one_or_more_failures(array_failure_rate, 365.0 / 90, n, j + 1) * 100, 13);
850 6 : printf("\n");
851 : }
852 :
853 1 : printf("\n");
854 :
855 : /* |<##################################################################72>|####80>| */
856 1 : printf("These values are the probabilities that in the next year you'll have a\n");
857 1 : printf("sequence of failures that the parity WONT be able to recover, assuming\n");
858 1 : printf("that you regularly scrub, and in case repair, the array in the specified\n");
859 1 : printf("time.\n");
860 :
861 : bail:
862 1 : if (make_it_fail) {
863 1 : printf("\n");
864 1 : printf("DANGER! SMART is reporting that one or more disks are FAILING!\n");
865 1 : printf("Please take immediate action!\n");
866 1 : exit(EXIT_FAILURE);
867 : }
868 0 : }
869 :
870 : /**
871 : * Fill with fake data the device list.
872 : */
873 1 : static int devtest(tommy_list* low, int operation)
874 : {
875 : unsigned c;
876 :
877 1 : if (operation != DEVICE_SMART)
878 0 : return -1;
879 :
880 : /* add some fake data */
881 17 : for (c = 0; c < 16; ++c) {
882 : devinfo_t* entry;
883 : int j;
884 :
885 16 : entry = calloc_nofail(1, sizeof(devinfo_t));
886 :
887 16 : entry->device = c;
888 :
889 16 : tommy_list_insert_tail(low, &entry->node, entry);
890 :
891 4112 : for (j = 0; j < 256; ++j) {
892 4096 : switch (c) {
893 256 : case 0 : entry->smart[j] = 0; break;
894 256 : case 1 : entry->smart[j] = SMART_UNASSIGNED; break;
895 : default:
896 3584 : if (j == 193)
897 14 : entry->smart[j] = c - 2;
898 : else
899 3570 : entry->smart[j] = 0;
900 3584 : break;
901 : }
902 : }
903 :
904 16 : if (c == 0) {
905 1 : entry->smart_serial[0] = 0;
906 1 : entry->file[0] = 0;
907 1 : entry->name[0] = 0;
908 1 : entry->smart[SMART_SIZE] = SMART_UNASSIGNED;
909 1 : entry->smart[SMART_ROTATION_RATE] = 0;
910 : } else {
911 15 : snprintf(entry->smart_serial, sizeof(entry->smart_serial), "%u", c);
912 15 : pathcpy(entry->file, sizeof(entry->name), "file");
913 15 : pathcpy(entry->name, sizeof(entry->name), "name");
914 15 : entry->smart[SMART_SIZE] = c * TERA;
915 15 : entry->smart[SMART_ROTATION_RATE] = 7200;
916 : }
917 :
918 16 : entry->smart[SMART_ERROR] = 0;
919 16 : entry->smart[SMART_FLAGS] = SMART_UNASSIGNED;
920 :
921 16 : switch (c) {
922 1 : case 3 : entry->smart[SMART_ERROR] = 1; break;
923 1 : case 4 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_UNSUPPORTED; break;
924 1 : case 5 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_COMMAND; break;
925 1 : case 6 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_OPEN; break;
926 1 : case 7 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_FAIL; break;
927 1 : case 8 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_PREFAIL; break;
928 1 : case 9 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_PREFAIL_LOGGED; break;
929 1 : case 10 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_ERROR; break;
930 1 : case 11 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_ERROR_LOGGED; break;
931 : }
932 : }
933 :
934 1 : return 0;
935 : }
936 :
937 5 : void state_device(struct snapraid_state* state, int operation)
938 : {
939 : tommy_node* i;
940 : unsigned j;
941 : tommy_list high;
942 : tommy_list low;
943 : int ret;
944 :
945 5 : switch (operation) {
946 1 : case DEVICE_UP : msg_progress("Spinup...\n"); break;
947 1 : case DEVICE_DOWN : msg_progress("Spindown...\n"); break;
948 : }
949 :
950 5 : tommy_list_init(&high);
951 5 : tommy_list_init(&low);
952 :
953 : /* for all disks */
954 35 : for (i = state->disklist; i != 0; i = i->next) {
955 30 : struct snapraid_disk* disk = i->data;
956 : devinfo_t* entry;
957 :
958 30 : entry = calloc_nofail(1, sizeof(devinfo_t));
959 :
960 30 : entry->device = disk->device;
961 30 : pathcpy(entry->name, sizeof(entry->name), disk->name);
962 30 : pathcpy(entry->mount, sizeof(entry->mount), disk->dir);
963 30 : pathcpy(entry->smartctl, sizeof(entry->smartctl), disk->smartctl);
964 :
965 30 : tommy_list_insert_tail(&high, &entry->node, entry);
966 : }
967 :
968 : /* for all parities */
969 35 : for (j = 0; j < state->level; ++j) {
970 : devinfo_t* entry;
971 :
972 30 : entry = calloc_nofail(1, sizeof(devinfo_t));
973 :
974 30 : entry->device = state->parity[j].device;
975 30 : pathcpy(entry->name, sizeof(entry->name), lev_config_name(j));
976 30 : pathcpy(entry->mount, sizeof(entry->mount), state->parity[j].path);
977 30 : pathcpy(entry->smartctl, sizeof(entry->smartctl), state->parity[j].smartctl);
978 30 : pathcut(entry->mount); /* remove the parity file */
979 :
980 30 : tommy_list_insert_tail(&high, &entry->node, entry);
981 : }
982 :
983 5 : if (state->opt.fake_device)
984 1 : ret = devtest(&low, operation);
985 : else
986 4 : ret = devquery(&high, &low, operation);
987 :
988 5 : if (ret != 0) {
989 2 : const char* ope = 0;
990 2 : switch (operation) {
991 0 : case DEVICE_UP : ope = "Spinup"; break;
992 1 : case DEVICE_DOWN : ope = "Spindown"; break;
993 0 : case DEVICE_LIST : ope = "List"; break;
994 1 : case DEVICE_SMART : ope = "SMART"; break;
995 : }
996 2 : log_fatal("%s unsupported in this platform.\n", ope);
997 : } else {
998 3 : if (operation == DEVICE_LIST) {
999 13 : for (i = tommy_list_head(&low); i != 0; i = i->next) {
1000 12 : devinfo_t* devinfo = i->data;
1001 12 : devinfo_t* parent = devinfo->parent;
1002 : #ifdef _WIN32
1003 : printf("%" PRIu64 "\t%s\t%08" PRIx64 "\t%s\t%s\n", devinfo->device, devinfo->wfile, parent->device, parent->wfile, parent->name);
1004 : #else
1005 12 : printf("%u:%u\t%s\t%u:%u\t%s\t%s\n", major(devinfo->device), minor(devinfo->device), devinfo->file, major(parent->device), minor(parent->device), parent->file, parent->name);
1006 : #endif
1007 : }
1008 : }
1009 :
1010 3 : if (operation == DEVICE_SMART)
1011 1 : state_smart(state->level + tommy_list_count(&state->disklist), &low);
1012 : }
1013 :
1014 4 : tommy_list_foreach(&high, free);
1015 4 : tommy_list_foreach(&low, free);
1016 4 : }
1017 :
|