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.0034, 0.0738, 0.0883, 0.0960, 0.1016,
63 : 0.1062, 0.1106, 0.1142, 0.1189, 0.1259,
64 : 0.1307, 0.1337, 0.1368, 0.1400, 0.1419,
65 : 0.1448, 0.1463, 0.1497, 0.1512, 0.1532,
66 : 0.1546, 0.1563, 0.1582, 0.1606, 0.1624,
67 : 0.1645, 0.1658, 0.1670, 0.1687, 0.1702,
68 : 0.1717, 0.1730, 0.1749, 0.1774, 0.1791,
69 : 0.1804, 0.1819, 0.1826, 0.1840, 0.1858,
70 : 0.1869, 0.1899, 0.1906, 0.1914, 0.1932,
71 : 0.1942, 0.1954, 0.1962, 0.1985, 0.2007,
72 : 0.2017, 0.2030, 0.2041, 0.2049, 0.2061,
73 : 0.2072, 0.2080, 0.2096, 0.2100, 0.2107,
74 : 0.2113, 0.2124, 0.2132, 0.2138, 0.2145,
75 : 0.2159, 0.2168, 0.2180, 0.2198, 0.2204,
76 : 0.2208, 0.2212, 0.2225, 0.2242, 0.2248,
77 : 0.2254, 0.2261, 0.2265, 0.2269, 0.2278,
78 : 0.2293, 0.2313, 0.2321, 0.2326, 0.2334,
79 : 0.2346, 0.2362, 0.2366, 0.2375, 0.2393,
80 : 0.2397, 0.2402, 0.2410, 0.2415, 0.2423,
81 : 0.2436, 0.2447, 0.2458, 0.2463, 0.2470,
82 : 0.2481, 0.2488, 0.2492, 0.2498, 0.2510,
83 : 0.2528, 0.2536, 0.2540, 0.2548, 0.2557,
84 : 0.2563, 0.2568, 0.2574, 0.2591, 0.2593,
85 : 0.2596, 0.2603, 0.2608, 0.2613, 0.2616,
86 : 0.2622, 0.2635, 0.2648, 0.2651, 0.2658,
87 : 0.2661, 0.2664, 0.2667, 0.2677, 0.2689,
88 : 0.2697, 0.2699, 0.2701, 0.2711, 0.2717,
89 : 0.2719, 0.2733, 0.2745, 0.2759, 0.2761,
90 : 0.2769, 0.2771, 0.2772, 0.2774, 0.2780,
91 : 0.2796, 0.2798, 0.2803, 0.2808, 0.2811,
92 : 0.2814, 0.2821, 0.2829, 0.2841, 0.2846,
93 : 0.2848, 0.2851, 0.2856, 0.2866, 0.2869,
94 : 0.2873, 0.2895, 0.2897, 0.2903, 0.2906,
95 : 0.2910, 0.2914, 0.2916, 0.2923, 0.2940,
96 : 0.2945, 0.2954, 0.2959, 0.2962, 0.2966,
97 : 0.2974, 0.2991, 0.3004, 0.3004, 0.3007,
98 : 0.3011, 0.3015, 0.3017, 0.3019, 0.3025,
99 : 0.3037, 0.3038, 0.3040, 0.3043, 0.3046,
100 : 0.3050, 0.3055, 0.3061, 0.3079, 0.3084,
101 : 0.3088, 0.3092, 0.3095, 0.3101, 0.3109,
102 : 0.3119, 0.3142, 0.3146, 0.3149, 0.3151,
103 : 0.3153, 0.3154, 0.3157, 0.3164, 0.3177,
104 : 0.3178, 0.3186, 0.3188, 0.3201, 0.3208,
105 : 0.3212, 0.3218, 0.3233, 0.3234, 0.3239,
106 : 0.3243, 0.3246, 0.3256, 0.3258, 0.3264,
107 : 0.3280, 0.3285, 0.3288, 0.3297, 0.3299,
108 : 0.3302, 0.3304, 0.3310, 0.3323, 0.3324,
109 : 0.3326, 0.3327, 0.3328, 0.3337, 0.3338,
110 : 0.3349, 0.3367, 0.3374, 0.3378, 0.3381,
111 : 0.3385, 0.3387, 0.3389, 0.3394, 0.3404,
112 : 0.3408, 0.3410, 0.3412, 0.3413, 0.3416,
113 : 0.3421,
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.0048, 0.0957, 0.1157, 0.1306, 0.1415,
127 : 0.1501, 0.1695, 0.2444, 0.2714, 0.2925,
128 : 0.3113, 0.3284, 0.3515, 0.4054, 0.4331,
129 : 0.4578, 0.4817, 0.5010, 0.5171, 0.5610,
130 : 0.5893, 0.6120, 0.6362, 0.6608, 0.6803,
131 : 0.7261, 0.7490, 0.7818, 0.8109, 0.8364,
132 : 0.8599, 0.9086, 0.9303, 0.9580, 0.9820,
133 : 1.0057, 1.0388, 1.0803, 1.1067, 1.1327,
134 : 1.1589, 1.1788, 1.1963, 1.2136, 1.2367,
135 : 1.2617, 1.2789, 1.2940, 1.3134, 1.3376,
136 : 1.3562, 1.3673, 1.3799, 1.4099, 1.4260,
137 : 1.4321, 1.4495, 1.4548, 1.4696, 1.4816,
138 : 1.5054, 1.5204, 1.5296, 1.5627, 1.5820,
139 : 1.5969, 1.6076, 1.6125, 1.6205, 1.6333,
140 : 1.6582, 1.6674, 1.6843, 1.7144, 1.7269,
141 : 1.7494, 1.7590, 1.7747, 1.7962, 1.8383,
142 : 1.8480, 1.8532, 1.8641, 1.8793, 1.8850,
143 : 1.8920, 1.8978, 1.9033, 1.9081, 1.9237,
144 : 1.9609, 1.9805, 2.0055, 2.0095, 2.0127,
145 : 2.0277, 2.0493, 2.0873, 2.1064, 2.1130,
146 : 2.1190, 2.1240, 2.1477, 2.1850, 2.1979,
147 : 2.2168, 2.2279, 2.2701, 2.2794, 2.2855,
148 : 2.3012, 2.3138, 2.3167, 2.3764, 2.3832,
149 : 2.3860, 2.3906, 2.4012, 2.4261, 2.4314,
150 : 2.4539, 2.4556, 2.4630, 2.4764, 2.4821,
151 : 2.4851, 2.4894, 2.4922, 2.4992, 2.5123,
152 : 2.5202, 2.5232, 2.5264, 2.5322, 2.5407,
153 : 2.5429, 2.5485, 2.5642, 2.5669, 2.5743,
154 : 2.5887, 2.5890, 2.6177, 2.7026, 2.7028,
155 : 2.7080, 2.7110, 2.7159, 2.7192, 2.7217,
156 : 2.7227, 2.7263, 2.7313, 2.7344, 2.7348,
157 : 2.7450, 2.7501, 2.7641, 2.7670, 2.7711,
158 : 2.7724, 2.7753, 2.7757, 2.7853, 2.7870,
159 : 2.7919, 2.7947, 2.7974, 2.8002, 2.8132,
160 : 2.8157, 2.8195, 2.8204, 2.8220, 2.8254,
161 : 2.8270, 2.8329, 2.8479, 2.8490, 2.8532,
162 : 2.8578, 2.8662, 2.8710, 2.8737, 2.8742,
163 : 2.8750, 2.9768, 2.9810, 2.9825, 2.9873,
164 : 2.9884, 3.0040, 3.0055, 3.0066, 3.0119,
165 : 3.0189, 3.0239, 3.0277, 3.0335, 3.0345,
166 : 3.0388, 3.0521, 3.0673, 3.0717, 3.0734,
167 : 3.0753, 3.0770, 3.0961, 3.0975, 3.0988,
168 : 3.1004, 3.1018, 3.1018, 3.1041, 3.1058,
169 : 3.1067, 3.1126, 3.1144, 3.1178, 3.1185,
170 : 3.1226, 3.1264, 3.1303, 3.1308, 3.1314,
171 : 3.1339, 3.1346, 3.1364, 3.1384, 3.1389,
172 : 3.1390, 3.1399, 3.1405, 3.1406, 3.1412,
173 : 3.1412, 3.1424, 3.1467, 3.1556, 3.1650,
174 : 3.1662, 3.1834, 3.1839, 3.1853, 3.1855,
175 : 3.1864, 3.1889, 3.1912, 3.1913, 3.1918,
176 : 3.1924, 3.1934, 3.1951, 3.2129, 3.2138,
177 : 3.2176,
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.0022, 0.0087, 0.0113, 0.0131, 0.0143,
191 : 0.0157, 0.0176, 0.0203, 0.0233, 0.0271,
192 : 0.0317, 0.0377, 0.0449, 0.0542, 0.0658,
193 : 0.0798, 0.0934, 0.1100, 0.1268, 0.1451,
194 : 0.1626, 0.1820, 0.1975, 0.2138, 0.2270,
195 : 0.2397, 0.2515, 0.2606, 0.2692, 0.2792,
196 : 0.2861, 0.2954, 0.3050, 0.3165, 0.3252,
197 : 0.3369, 0.3430, 0.3512, 0.3588, 0.3731,
198 : 0.3777, 0.3894, 0.3981, 0.4148, 0.4206,
199 : 0.4325, 0.4354, 0.4449, 0.4503, 0.4635,
200 : 0.4695, 0.4806, 0.4871, 0.4988, 0.5007,
201 : 0.5099, 0.5144, 0.5270, 0.5313, 0.5393,
202 : 0.5456, 0.5529, 0.5542, 0.5633, 0.5657,
203 : 0.5729, 0.5748, 0.5814, 0.5906, 0.5977,
204 : 0.6045, 0.6096, 0.6208, 0.6259, 0.6293,
205 : 0.6347, 0.6354, 0.6389, 0.6449, 0.6481,
206 : 0.6549, 0.6581, 0.6604, 0.6703, 0.6759,
207 : 0.6830, 0.6882, 0.6900, 0.6931, 0.7027,
208 : 0.7070, 0.7125, 0.7202, 0.7302, 0.7405,
209 : 0.7467, 0.7520, 0.7573, 0.7616, 0.7688,
210 : 0.7732, 0.7773, 0.7825, 0.7890, 0.7940,
211 : 0.8113, 0.8213, 0.8344, 0.8364, 0.8403,
212 : 0.8449, 0.8488, 0.8567, 0.8621, 0.8668,
213 : 0.8729, 0.8737, 0.8750, 0.8782, 0.8807,
214 : 0.8821, 0.8920, 0.8987, 0.8990, 0.9099,
215 : 0.9141, 0.9165, 0.9195, 0.9198, 0.9235,
216 : 0.9247, 0.9315, 0.9359, 0.9372, 0.9394,
217 : 0.9451, 0.9454, 0.9493, 0.9520, 0.9534,
218 : 0.9556, 0.9564, 0.9605, 0.9628, 0.9648,
219 : 0.9709, 0.9717, 0.9761, 0.9784, 0.9788,
220 : 0.9824, 0.9884, 0.9938, 0.9944, 1.0056,
221 : 1.0061, 1.0111, 1.0314, 1.0375, 1.0393,
222 : 1.0396, 1.0397, 1.0414, 1.0418, 1.0466,
223 : 1.0467, 1.0474, 1.0475, 1.0523, 1.0523,
224 : 1.0524, 1.0525, 1.0557, 1.0597, 1.0597,
225 : 1.0598, 1.0599, 1.0599, 1.0602, 1.0603,
226 : 1.0603, 1.0605, 1.0605, 1.0610, 1.0611,
227 : 1.0613, 1.0615, 1.0628, 1.0666, 1.0732,
228 : 1.0792, 1.0796, 1.0797, 1.0864, 1.0935,
229 : 1.0936, 1.1013, 1.1066, 1.1088, 1.1088,
230 : 1.1093, 1.1119, 1.1136, 1.1146, 1.1245,
231 : 1.1274, 1.1275, 1.1276, 1.1280, 1.1280,
232 : 1.1347, 1.1348, 1.1348, 1.1348, 1.1350,
233 : 1.1408, 1.1476, 1.1477, 1.1477, 1.1478,
234 : 1.1479, 1.1479, 1.1479, 1.1480, 1.1480,
235 : 1.1564, 1.1714, 1.1732, 1.1747, 1.1816,
236 : 1.1819, 1.1887, 1.1906, 1.2126, 1.2167,
237 : 1.2168, 1.2168, 1.2168, 1.2171, 1.2171,
238 : 1.2268, 1.2396, 1.2397, 1.2418, 1.2478,
239 : 1.2588, 1.2610, 1.2615, 1.2651, 1.2668,
240 : 1.2682, 1.2732, 1.2738, 1.2747, 1.2764,
241 : 1.2765,
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.0014, 0.0027, 0.0030, 0.0031,
255 : 0.0033, 0.0036, 0.0038, 0.0041, 0.0043,
256 : 0.0046, 0.0048, 0.0050, 0.0053, 0.0056,
257 : 0.0058, 0.0060, 0.0064, 0.0067, 0.0069,
258 : 0.0073, 0.0076, 0.0079, 0.0082, 0.0085,
259 : 0.0088, 0.0091, 0.0094, 0.0097, 0.0100,
260 : 0.0104, 0.0107, 0.0110, 0.0113, 0.0115,
261 : 0.0117, 0.0120, 0.0123, 0.0126, 0.0129,
262 : 0.0131, 0.0134, 0.0138, 0.0141, 0.0144,
263 : 0.0149, 0.0153, 0.0156, 0.0159, 0.0162,
264 : 0.0166, 0.0168, 0.0171, 0.0173, 0.0176,
265 : 0.0179, 0.0183, 0.0186, 0.0191, 0.0196,
266 : 0.0202, 0.0207, 0.0213, 0.0217, 0.0221,
267 : 0.0225, 0.0233, 0.0238, 0.0243, 0.0247,
268 : 0.0252, 0.0257, 0.0261, 0.0265, 0.0271,
269 : 0.0278, 0.0284, 0.0290, 0.0294, 0.0298,
270 : 0.0304, 0.0310, 0.0316, 0.0321, 0.0325,
271 : 0.0329, 0.0334, 0.0340, 0.0346, 0.0351,
272 : 0.0355, 0.0359, 0.0365, 0.0372, 0.0379,
273 : 0.0387, 0.0395, 0.0405, 0.0413, 0.0419,
274 : 0.0424, 0.0432, 0.0440, 0.0447, 0.0455,
275 : 0.0461, 0.0467, 0.0471, 0.0476, 0.0481,
276 : 0.0486, 0.0490, 0.0495, 0.0500, 0.0505,
277 : 0.0512, 0.0518, 0.0524, 0.0532, 0.0540,
278 : 0.0545, 0.0552, 0.0559, 0.0566, 0.0574,
279 : 0.0582, 0.0592, 0.0601, 0.0607, 0.0616,
280 : 0.0623, 0.0631, 0.0639, 0.0646, 0.0654,
281 : 0.0661, 0.0668, 0.0677, 0.0685, 0.0696,
282 : 0.0707, 0.0717, 0.0727, 0.0737, 0.0749,
283 : 0.0759, 0.0773, 0.0783, 0.0791, 0.0800,
284 : 0.0809, 0.0819, 0.0829, 0.0839, 0.0847,
285 : 0.0858, 0.0867, 0.0876, 0.0884, 0.0895,
286 : 0.0906, 0.0919, 0.0931, 0.0943, 0.0954,
287 : 0.0966, 0.0976, 0.0985, 0.0995, 0.1009,
288 : 0.1021, 0.1038, 0.1051, 0.1065, 0.1076,
289 : 0.1090, 0.1106, 0.1119, 0.1130, 0.1146,
290 : 0.1158, 0.1168, 0.1181, 0.1193, 0.1206,
291 : 0.1216, 0.1227, 0.1241, 0.1257, 0.1268,
292 : 0.1277, 0.1289, 0.1302, 0.1316, 0.1329,
293 : 0.1341, 0.1355, 0.1372, 0.1387, 0.1400,
294 : 0.1415, 0.1427, 0.1438, 0.1447, 0.1458,
295 : 0.1470, 0.1480, 0.1491, 0.1502, 0.1517,
296 : 0.1528, 0.1539, 0.1555, 0.1568, 0.1583,
297 : 0.1594, 0.1606, 0.1618, 0.1635, 0.1649,
298 : 0.1665, 0.1686, 0.1700, 0.1719, 0.1731,
299 : 0.1743, 0.1755, 0.1777, 0.1788, 0.1802,
300 : 0.1812, 0.1824, 0.1835, 0.1848, 0.1859,
301 : 0.1869, 0.1880, 0.1890, 0.1901, 0.1913,
302 : 0.1926, 0.1935, 0.1948, 0.1960, 0.1977,
303 : 0.1989, 0.2001, 0.2013, 0.2024, 0.2036,
304 : 0.2049, 0.2062, 0.2074, 0.2087, 0.2099,
305 : 0.2111,
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.0036, 0.2430, 0.3027, 0.3349, 0.3533,
319 : 0.3632, 0.3722, 0.3790, 0.4199, 0.6417,
320 : 0.6517, 0.6583, 0.6647, 0.6680, 0.6737,
321 : 0.6787, 0.7076, 0.9073, 0.9113, 0.9194,
322 : 0.9238, 0.9326, 0.9394, 0.9446, 0.9697,
323 : 1.1417, 1.1466, 1.1485, 1.1522, 1.1775,
324 : 1.1817, 1.1864, 1.2105, 1.3939, 1.3991,
325 : 1.4013, 1.4125, 1.4135, 1.4210, 1.4217,
326 : 1.4335, 1.6024, 1.6040, 1.6132, 1.6174,
327 : 1.6187, 1.6203, 1.6211, 1.6354, 1.7839,
328 : 1.7858, 1.7869, 1.7889, 1.7911, 1.7932,
329 : 1.7962, 1.8091, 1.9381, 1.9405, 1.9410,
330 : 1.9415, 1.9420, 1.9424, 1.9434, 1.9518,
331 : 2.0516, 2.0518, 2.0521, 2.0524, 2.0532,
332 : 2.0538, 2.0550, 2.0624, 2.1508, 2.1514,
333 : 2.1519, 2.1519, 2.1520, 2.1533, 2.1534,
334 : 2.1603, 2.2730, 2.2730, 2.2730, 2.2757,
335 : 2.2768, 2.2774, 2.2778, 2.2844, 2.3740,
336 : 2.3753, 2.3769, 2.3779, 2.3790, 2.3796,
337 : 2.3806, 2.3891, 2.5538, 2.5550, 2.5563,
338 : 2.5588, 2.5594, 2.5600, 2.5605, 2.5665,
339 : 2.7510, 2.7526, 2.7539, 2.7544, 2.7549,
340 : 2.7552, 2.7555, 2.7590, 2.8782, 2.8788,
341 : 2.8812, 2.8821, 2.8824, 2.8836, 2.8836,
342 : 2.8864, 2.9536, 2.9539, 2.9543, 2.9559,
343 : 2.9565, 2.9572, 2.9572, 2.9601, 3.0230,
344 : 3.0230, 3.0230, 3.0230, 3.0230, 3.0231,
345 : 3.0231, 3.0266, 3.0846, 3.0846, 3.0846,
346 : 3.0846, 3.0846, 3.0847, 3.0851, 3.0874,
347 : 3.1242, 3.1242, 3.1242, 3.1242, 3.1246,
348 : 3.1246, 3.1246, 3.1273, 3.1806, 3.1806,
349 : 3.1806, 3.1806, 3.1806, 3.1810, 3.1814,
350 : 3.1829, 3.2173, 3.2174, 3.2174, 3.2174,
351 : 3.2174, 3.2174, 3.2174, 3.2197, 3.2643,
352 : 3.2643, 3.2643, 3.2661, 3.2661, 3.2666,
353 : 3.2666, 3.2677, 3.2962, 3.2962, 3.2963,
354 : 3.3673, 3.3713, 3.3813, 3.3813, 3.3835,
355 : 3.4059, 3.4059, 3.4065, 3.4091, 3.4096,
356 : 3.4103, 3.4104, 3.4123, 3.4316, 3.4360,
357 : 3.4387, 3.4393, 3.4393, 3.4404, 3.4409,
358 : 3.4440, 3.5547, 3.5547, 3.5547, 3.5547,
359 : 3.5547, 3.5547, 3.5548, 3.5558, 3.5801,
360 : 3.5801, 3.5801, 3.5801, 3.5802, 3.5802,
361 : 3.5802, 3.5820, 3.6178, 3.6178, 3.6178,
362 : 3.6178, 3.6178, 3.6242, 3.6242, 3.6260,
363 : 3.6567, 3.6567, 3.6568, 3.6568, 3.6568,
364 : 3.6568, 3.6831, 3.6841, 3.7260, 3.7268,
365 : 3.7269, 3.7269, 3.7269, 3.7269, 3.7269,
366 : 3.7279, 3.7387, 3.7387, 3.7394, 3.7394,
367 : 3.7394, 3.7394, 3.7394, 3.7402, 3.7622,
368 : 3.7622, 3.7629, 3.7734, 3.7734, 3.7734,
369 : 3.7734,
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.0038, 0.3963, 0.4189, 0.4297, 0.4364,
383 : 0.4393, 0.4433, 0.4490, 0.4909, 0.7634,
384 : 0.7649, 0.7683, 0.7689, 0.7703, 0.7717,
385 : 0.7737, 0.8009, 1.0435, 1.0438, 1.0445,
386 : 1.0446, 1.0456, 1.0496, 1.0501, 1.0695,
387 : 1.2652, 1.2662, 1.2667, 1.2707, 1.2722,
388 : 1.2734, 1.2750, 1.2974, 1.5036, 1.5038,
389 : 1.5050, 1.5156, 1.5156, 1.5231, 1.5239,
390 : 1.5347, 1.7251, 1.7258, 1.7271, 1.7271,
391 : 1.7271, 1.7271, 1.7271, 1.7423, 1.9132,
392 : 1.9134, 1.9134, 1.9134, 1.9134, 1.9135,
393 : 1.9135, 1.9221, 2.0645, 2.0645, 2.0645,
394 : 2.0645, 2.0645, 2.0645, 2.0645, 2.0716,
395 : 2.1838, 2.1838, 2.1838, 2.1838, 2.1838,
396 : 2.1838, 2.1838, 2.1910, 2.2936, 2.2937,
397 : 2.2937, 2.2937, 2.2937, 2.2937, 2.2937,
398 : 2.3007, 2.4350, 2.4350, 2.4350, 2.4352,
399 : 2.4352, 2.4352, 2.4352, 2.4407, 2.5482,
400 : 2.5482, 2.5482, 2.5482, 2.5482, 2.5482,
401 : 2.5482, 2.5539, 2.7538, 2.7538, 2.7538,
402 : 2.7538, 2.7538, 2.7538, 2.7539, 2.7585,
403 : 2.9231, 2.9231, 2.9231, 2.9231, 2.9231,
404 : 2.9232, 2.9232, 2.9264, 3.0707, 3.0707,
405 : 3.0707, 3.0707, 3.0707, 3.0707, 3.0707,
406 : 3.0734, 3.1562, 3.1562, 3.1562, 3.1562,
407 : 3.1562, 3.1562, 3.1562, 3.1584, 3.2363,
408 : 3.2363, 3.2363, 3.2363, 3.2363, 3.2363,
409 : 3.2363, 3.2397, 3.3121, 3.3121, 3.3121,
410 : 3.3121, 3.3121, 3.3122, 3.3122, 3.3142,
411 : 3.3612, 3.3612, 3.3612, 3.3612, 3.3612,
412 : 3.3612, 3.3612, 3.3636, 3.4314, 3.4314,
413 : 3.4314, 3.4314, 3.4314, 3.4314, 3.4314,
414 : 3.4325, 3.4769, 3.4769, 3.4769, 3.4769,
415 : 3.4769, 3.4769, 3.4769, 3.4788, 3.5366,
416 : 3.5366, 3.5366, 3.5366, 3.5366, 3.5366,
417 : 3.5366, 3.5377, 3.5756, 3.5756, 3.5756,
418 : 3.5756, 3.5756, 3.5756, 3.5756, 3.5775,
419 : 3.6049, 3.6049, 3.6049, 3.6049, 3.6049,
420 : 3.6049, 3.6049, 3.6061, 3.6279, 3.6279,
421 : 3.6279, 3.6279, 3.6279, 3.6279, 3.6279,
422 : 3.6309, 3.7670, 3.7670, 3.7670, 3.7670,
423 : 3.7670, 3.7670, 3.7670, 3.7679, 3.7983,
424 : 3.7983, 3.7983, 3.7983, 3.7983, 3.7983,
425 : 3.7983, 3.8000, 3.8449, 3.8449, 3.8449,
426 : 3.8449, 3.8449, 3.8449, 3.8449, 3.8467,
427 : 3.8854, 3.9337, 3.9337, 3.9337, 3.9337,
428 : 3.9337, 3.9337, 3.9346, 3.9892, 3.9892,
429 : 3.9892, 3.9892, 3.9892, 3.9892, 3.9892,
430 : 3.9901, 4.0043, 4.0043, 4.0043, 4.0043,
431 : 4.0043, 4.0043, 4.0043, 4.0050, 4.0340,
432 : 4.0340, 4.0340, 4.0340, 4.0340, 4.0340,
433 : 4.0340,
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 12 : 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 12 : 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 : * Prints 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 285 : while (len < pad) {
607 181 : printf(" ");
608 181 : ++len;
609 : }
610 52 : }
611 :
612 : /**
613 : * Prints 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 18 : snprintf(buf, sizeof(buf), "%5.2f%s", v, s);
622 0 : else if (v > 0.01)
623 0 : snprintf(buf, sizeof(buf), "%6.3f%s", v, s);
624 0 : else if (v > 0.001)
625 0 : snprintf(buf, sizeof(buf), "%7.4f%s", v, s);
626 0 : else if (v > 0.0001)
627 0 : snprintf(buf, sizeof(buf), "%8.5f%s", v, s);
628 0 : else if (v > 0.00001)
629 0 : snprintf(buf, sizeof(buf), "%9.6f%s", v, s);
630 0 : else if (v > 0.000001)
631 0 : snprintf(buf, sizeof(buf), "%10.7f%s", v, s);
632 0 : else if (v > 0.0000001)
633 0 : snprintf(buf, sizeof(buf), "%11.8f%s", v, s);
634 0 : else if (v > 0.00000001)
635 0 : snprintf(buf, sizeof(buf), "%12.9f%s", v, s);
636 0 : else if (v > 0.000000001)
637 0 : snprintf(buf, sizeof(buf), "%13.10f%s", v, s);
638 0 : else if (v > 0.0000000001)
639 0 : snprintf(buf, sizeof(buf), "%14.11f%s", v, s);
640 0 : else if (v > 0.00000000001)
641 0 : 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 : /* prints 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 3584 : default : entry->smart[j] = c; break;
896 : }
897 : }
898 :
899 16 : if (c == 0) {
900 1 : entry->smart_serial[0] = 0;
901 1 : entry->file[0] = 0;
902 1 : entry->name[0] = 0;
903 1 : entry->smart[SMART_SIZE] = SMART_UNASSIGNED;
904 1 : entry->smart[SMART_ROTATION_RATE] = 0;
905 : } else {
906 15 : snprintf(entry->smart_serial, sizeof(entry->smart_serial), "%u", c);
907 15 : pathcpy(entry->file, sizeof(entry->name), "file");
908 15 : pathcpy(entry->name, sizeof(entry->name), "name");
909 15 : entry->smart[SMART_SIZE] = c * TERA;
910 15 : entry->smart[SMART_ROTATION_RATE] = 7200;
911 : }
912 :
913 16 : entry->smart[SMART_ERROR] = 0;
914 16 : entry->smart[SMART_FLAGS] = SMART_UNASSIGNED;
915 :
916 16 : switch (c) {
917 1 : case 3 : entry->smart[SMART_ERROR] = 1; break;
918 1 : case 4 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_UNSUPPORTED; break;
919 1 : case 5 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_COMMAND; break;
920 1 : case 6 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_OPEN; break;
921 1 : case 7 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_FAIL; break;
922 1 : case 8 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_PREFAIL; break;
923 1 : case 9 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_PREFAIL_LOGGED; break;
924 1 : case 10 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_ERROR; break;
925 1 : case 11 : entry->smart[SMART_FLAGS] = SMARTCTL_FLAG_ERROR_LOGGED; break;
926 : }
927 : }
928 :
929 1 : return 0;
930 : }
931 :
932 5 : void state_device(struct snapraid_state* state, int operation)
933 : {
934 : tommy_node* i;
935 : unsigned j;
936 : tommy_list high;
937 : tommy_list low;
938 : int ret;
939 :
940 5 : switch (operation) {
941 1 : case DEVICE_UP : msg_progress("Spinup...\n"); break;
942 1 : case DEVICE_DOWN : msg_progress("Spindown...\n"); break;
943 : }
944 :
945 5 : tommy_list_init(&high);
946 5 : tommy_list_init(&low);
947 :
948 : /* for all disks */
949 35 : for (i = state->disklist; i != 0; i = i->next) {
950 30 : struct snapraid_disk* disk = i->data;
951 : devinfo_t* entry;
952 :
953 30 : entry = calloc_nofail(1, sizeof(devinfo_t));
954 :
955 30 : entry->device = disk->device;
956 30 : pathcpy(entry->name, sizeof(entry->name), disk->name);
957 30 : pathcpy(entry->mount, sizeof(entry->mount), disk->dir);
958 30 : pathcpy(entry->smartctl, sizeof(entry->smartctl), disk->smartctl);
959 :
960 30 : tommy_list_insert_tail(&high, &entry->node, entry);
961 : }
962 :
963 : /* for all parities */
964 35 : for (j = 0; j < state->level; ++j) {
965 : devinfo_t* entry;
966 :
967 30 : entry = calloc_nofail(1, sizeof(devinfo_t));
968 :
969 30 : entry->device = state->parity[j].device;
970 30 : pathcpy(entry->name, sizeof(entry->name), lev_config_name(j));
971 30 : pathcpy(entry->mount, sizeof(entry->mount), state->parity[j].path);
972 30 : pathcpy(entry->smartctl, sizeof(entry->smartctl), state->parity[j].smartctl);
973 30 : pathcut(entry->mount); /* remove the parity file */
974 :
975 30 : tommy_list_insert_tail(&high, &entry->node, entry);
976 : }
977 :
978 5 : if (state->opt.fake_device)
979 1 : ret = devtest(&low, operation);
980 : else
981 4 : ret = devquery(&high, &low, operation);
982 :
983 5 : if (ret != 0) {
984 2 : const char* ope = 0;
985 2 : switch (operation) {
986 0 : case DEVICE_UP : ope = "Spinup"; break;
987 1 : case DEVICE_DOWN : ope = "Spindown"; break;
988 0 : case DEVICE_LIST : ope = "List"; break;
989 1 : case DEVICE_SMART : ope = "SMART"; break;
990 : }
991 2 : log_fatal("%s unsupported in this platform.\n", ope);
992 : } else {
993 3 : if (operation == DEVICE_LIST) {
994 13 : for (i = tommy_list_head(&low); i != 0; i = i->next) {
995 12 : devinfo_t* devinfo = i->data;
996 12 : devinfo_t* parent = devinfo->parent;
997 : #ifdef _WIN32
998 : printf("%" PRIu64 "\t%s\t%08" PRIx64 "\t%s\t%s\n", devinfo->device, devinfo->wfile, parent->device, parent->wfile, parent->name);
999 : #else
1000 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);
1001 : #endif
1002 : }
1003 : }
1004 :
1005 3 : if (operation == DEVICE_SMART)
1006 1 : state_smart(state->level + tommy_list_count(&state->disklist), &low);
1007 : }
1008 :
1009 4 : tommy_list_foreach(&high, free);
1010 4 : tommy_list_foreach(&low, free);
1011 4 : }
1012 :
|