@@ -26,6 +26,11 @@ func TestFS_MDStat(t *testing.T) {
26
26
if err != nil {
27
27
t .Fatalf ("parsing of reference-file failed entirely: %s" , err )
28
28
}
29
+ // TODO: Test cases to capture in future:
30
+ // WriteMostly devices
31
+ // Journal devices
32
+ // Replacement devices
33
+ // Global hotspares
29
34
30
35
refs := map [string ]MDStat {
31
36
"md127" : {
@@ -43,7 +48,7 @@ func TestFS_MDStat(t *testing.T) {
43
48
BlocksSyncedPct : 0 ,
44
49
BlocksSyncedFinishTime : 0 ,
45
50
BlocksSyncedSpeed : 0 ,
46
- Devices : []string { "sdi2" , "sdj2" }},
51
+ Devices : []MDStatComponent {{ Name : "sdi2" , DescriptorIndex : 0 }, { Name : "sdj2" , DescriptorIndex : 1 } }},
47
52
"md0" : {
48
53
Name : "md0" ,
49
54
Type : "raid1" ,
@@ -59,7 +64,7 @@ func TestFS_MDStat(t *testing.T) {
59
64
BlocksSyncedPct : 0 ,
60
65
BlocksSyncedFinishTime : 0 ,
61
66
BlocksSyncedSpeed : 0 ,
62
- Devices : []string { "sdi1" , "sdj1" }},
67
+ Devices : []MDStatComponent {{ Name : "sdi1" , DescriptorIndex : 0 }, { Name : "sdj1" , DescriptorIndex : 1 } }},
63
68
"md4" : {
64
69
Name : "md4" ,
65
70
Type : "raid1" ,
@@ -75,7 +80,7 @@ func TestFS_MDStat(t *testing.T) {
75
80
BlocksSyncedPct : 0 ,
76
81
BlocksSyncedFinishTime : 0 ,
77
82
BlocksSyncedSpeed : 0 ,
78
- Devices : []string { "sda3" , "sdb3" }},
83
+ Devices : []MDStatComponent {{ Name : "sda3" , Faulty : true , DescriptorIndex : 0 }, { Name : "sdb3" , Spare : true , DescriptorIndex : 1 } }},
79
84
"md6" : {
80
85
Name : "md6" ,
81
86
Type : "raid1" ,
@@ -91,7 +96,7 @@ func TestFS_MDStat(t *testing.T) {
91
96
BlocksSyncedPct : 8.5 ,
92
97
BlocksSyncedFinishTime : 17 ,
93
98
BlocksSyncedSpeed : 259783 ,
94
- Devices : []string { "sdb2" , "sdc" , "sda2" }},
99
+ Devices : []MDStatComponent {{ Name : "sdb2" , DescriptorIndex : 2 , Faulty : true }, { Name : "sdc" , DescriptorIndex : 1 , Spare : true }, { Name : "sda2" , DescriptorIndex : 0 } }},
95
100
"md3" : {
96
101
Name : "md3" ,
97
102
Type : "raid6" ,
@@ -107,7 +112,7 @@ func TestFS_MDStat(t *testing.T) {
107
112
BlocksSyncedPct : 0 ,
108
113
BlocksSyncedFinishTime : 0 ,
109
114
BlocksSyncedSpeed : 0 ,
110
- Devices : []string { "sda1" , "sdh1" , "sdg1" , "sdf1" , "sde1" , "sdd1" , "sdc1" , "sdb1" , "sdd1" , "sdd2" }},
115
+ Devices : []MDStatComponent {{ Name : "sda1" , DescriptorIndex : 8 }, { Name : "sdh1" , DescriptorIndex : 7 }, { Name : "sdg1" , DescriptorIndex : 6 }, { Name : "sdf1" , DescriptorIndex : 5 }, { Name : "sde1" , DescriptorIndex : 11 }, { Name : "sdd1" , DescriptorIndex : 3 }, { Name : "sdc1" , DescriptorIndex : 10 }, { Name : "sdb1" , DescriptorIndex : 9 }, { Name : "sdd1" , DescriptorIndex : 10 , Spare : true }, { Name : "sdd2" , DescriptorIndex : 11 , Spare : true } }},
111
116
"md8" : {
112
117
Name : "md8" ,
113
118
Type : "raid1" ,
@@ -123,7 +128,7 @@ func TestFS_MDStat(t *testing.T) {
123
128
BlocksSyncedPct : 8.5 ,
124
129
BlocksSyncedFinishTime : 17 ,
125
130
BlocksSyncedSpeed : 259783 ,
126
- Devices : []string { "sdb1" , "sda1" , "sdc" , "sde" }},
131
+ Devices : []MDStatComponent {{ Name : "sdb1" , DescriptorIndex : 1 }, { Name : "sda1" , DescriptorIndex : 0 }, { Name : "sdc" , DescriptorIndex : 2 , Spare : true }, { Name : "sde" , DescriptorIndex : 3 , Spare : true } }},
127
132
"md7" : {
128
133
Name : "md7" ,
129
134
Type : "raid6" ,
@@ -139,7 +144,7 @@ func TestFS_MDStat(t *testing.T) {
139
144
BlocksSyncedPct : 0 ,
140
145
BlocksSyncedFinishTime : 0 ,
141
146
BlocksSyncedSpeed : 0 ,
142
- Devices : []string { "sdb1" , "sde1" , "sdd1" , "sdc1" }},
147
+ Devices : []MDStatComponent {{ Name : "sdb1" , DescriptorIndex : 0 }, { Name : "sde1" , DescriptorIndex : 3 }, { Name : "sdd1" , DescriptorIndex : 2 }, { Name : "sdc1" , DescriptorIndex : 1 , Faulty : true } }},
143
148
"md9" : {
144
149
Name : "md9" ,
145
150
Type : "raid1" ,
@@ -155,7 +160,7 @@ func TestFS_MDStat(t *testing.T) {
155
160
BlocksSyncedPct : 0 ,
156
161
BlocksSyncedFinishTime : 0 ,
157
162
BlocksSyncedSpeed : 0 ,
158
- Devices : []string { "sdc2" , "sdd2" , "sdb2" , "sda2" , "sde" , "sdf" , "sdg" }},
163
+ Devices : []MDStatComponent {{ Name : "sdc2" , DescriptorIndex : 2 }, { Name : "sdd2" , DescriptorIndex : 3 }, { Name : "sdb2" , DescriptorIndex : 1 }, { Name : "sda2" , DescriptorIndex : 0 }, { Name : "sde" , DescriptorIndex : 4 , Faulty : true }, { Name : "sdf" , DescriptorIndex : 5 , Faulty : true }, { Name : "sdg" , DescriptorIndex : 6 , Spare : true } }},
159
164
"md10" : {
160
165
Name : "md10" ,
161
166
Type : "raid0" ,
@@ -171,7 +176,7 @@ func TestFS_MDStat(t *testing.T) {
171
176
BlocksSyncedPct : 0 ,
172
177
BlocksSyncedFinishTime : 0 ,
173
178
BlocksSyncedSpeed : 0 ,
174
- Devices : []string { "sda1" , "sdb1" }},
179
+ Devices : []MDStatComponent {{ Name : "sda1" , DescriptorIndex : 0 }, { Name : "sdb1" , DescriptorIndex : 1 } }},
175
180
"md11" : {
176
181
Name : "md11" ,
177
182
Type : "raid1" ,
@@ -187,7 +192,7 @@ func TestFS_MDStat(t *testing.T) {
187
192
BlocksSyncedPct : 0 ,
188
193
BlocksSyncedFinishTime : 0 ,
189
194
BlocksSyncedSpeed : 0 ,
190
- Devices : []string { "sdb2" , "sdc2" , "sdc3" , "hda" , "ssdc2" }},
195
+ Devices : []MDStatComponent {{ Name : "sdb2" , DescriptorIndex : 0 }, { Name : "sdc2" , DescriptorIndex : 1 }, { Name : "sdc3" , DescriptorIndex : 2 , Faulty : true }, { Name : "hda" , DescriptorIndex : 4 , Spare : true }, { Name : "ssdc2" , DescriptorIndex : 3 , Spare : true } }},
191
196
"md12" : {
192
197
Name : "md12" ,
193
198
Type : "raid0" ,
@@ -203,7 +208,7 @@ func TestFS_MDStat(t *testing.T) {
203
208
BlocksSyncedPct : 0 ,
204
209
BlocksSyncedFinishTime : 0 ,
205
210
BlocksSyncedSpeed : 0 ,
206
- Devices : []string { "sdc2" , "sdd2" }},
211
+ Devices : []MDStatComponent {{ Name : "sdc2" , DescriptorIndex : 0 }, { Name : "sdd2" , DescriptorIndex : 1 } }},
207
212
"md120" : {
208
213
Name : "md120" ,
209
214
Type : "linear" ,
@@ -219,7 +224,7 @@ func TestFS_MDStat(t *testing.T) {
219
224
BlocksSyncedPct : 0 ,
220
225
BlocksSyncedFinishTime : 0 ,
221
226
BlocksSyncedSpeed : 0 ,
222
- Devices : []string { "sda1" , "sdb1" }},
227
+ Devices : []MDStatComponent {{ Name : "sda1" , DescriptorIndex : 1 }, { Name : "sdb1" , DescriptorIndex : 0 } }},
223
228
"md126" : {
224
229
Name : "md126" ,
225
230
Type : "raid0" ,
@@ -235,7 +240,7 @@ func TestFS_MDStat(t *testing.T) {
235
240
BlocksSyncedPct : 0 ,
236
241
BlocksSyncedFinishTime : 0 ,
237
242
BlocksSyncedSpeed : 0 ,
238
- Devices : []string { "sdb" , "sdc" }},
243
+ Devices : []MDStatComponent {{ Name : "sdb" , DescriptorIndex : 1 }, { Name : "sdc" , DescriptorIndex : 0 } }},
239
244
"md219" : {
240
245
Name : "md219" ,
241
246
Type : "unknown" ,
@@ -251,7 +256,7 @@ func TestFS_MDStat(t *testing.T) {
251
256
BlocksSyncedPct : 0 ,
252
257
BlocksSyncedFinishTime : 0 ,
253
258
BlocksSyncedSpeed : 0 ,
254
- Devices : []string { " sdc" , "sda" }},
259
+ Devices : []MDStatComponent {{ Name : "sdb" , DescriptorIndex : 2 , Spare : true }, { Name : " sdc" , DescriptorIndex : 1 , Spare : true }, { Name : "sda" , DescriptorIndex : 0 , Spare : true } }},
255
260
"md00" : {
256
261
Name : "md00" ,
257
262
Type : "raid0" ,
@@ -267,7 +272,7 @@ func TestFS_MDStat(t *testing.T) {
267
272
BlocksSyncedPct : 0 ,
268
273
BlocksSyncedFinishTime : 0 ,
269
274
BlocksSyncedSpeed : 0 ,
270
- Devices : []string { "xvdb" }},
275
+ Devices : []MDStatComponent {{ Name : "xvdb" , DescriptorIndex : 0 } }},
271
276
"md101" : {
272
277
Name : "md101" ,
273
278
Type : "raid0" ,
@@ -283,7 +288,7 @@ func TestFS_MDStat(t *testing.T) {
283
288
BlocksSyncedPct : 0 ,
284
289
BlocksSyncedFinishTime : 0 ,
285
290
BlocksSyncedSpeed : 0 ,
286
- Devices : []string { "sdb" , "sdd" , "sdc" }},
291
+ Devices : []MDStatComponent {{ Name : "sdb" , DescriptorIndex : 2 }, { Name : "sdd" , DescriptorIndex : 1 }, { Name : "sdc" , DescriptorIndex : 0 } }},
287
292
"md201" : {
288
293
Name : "md201" ,
289
294
Type : "raid1" ,
@@ -299,7 +304,7 @@ func TestFS_MDStat(t *testing.T) {
299
304
BlocksSyncedPct : 5.7 ,
300
305
BlocksSyncedFinishTime : 0.2 ,
301
306
BlocksSyncedSpeed : 114176 ,
302
- Devices : []string { "sda3" , "sdb3" }},
307
+ Devices : []MDStatComponent {{ Name : "sda3" , DescriptorIndex : 0 }, { Name : "sdb3" , DescriptorIndex : 1 } }},
303
308
"md42" : {
304
309
Name : "md42" ,
305
310
ActivityState : "reshaping" ,
@@ -314,7 +319,7 @@ func TestFS_MDStat(t *testing.T) {
314
319
BlocksSyncedPct : 56.1 ,
315
320
BlocksSyncedFinishTime : 1868.1 ,
316
321
BlocksSyncedSpeed : 7640 ,
317
- Devices : []string { "sda1" , "sdd1" , "sde1" }},
322
+ Devices : []MDStatComponent {{ Name : "sda1" , DescriptorIndex : 3 , Spare : true }, { Name : "sdd1" , DescriptorIndex : 0 }, { Name : "sde1" , DescriptorIndex : 1 } }},
318
323
}
319
324
320
325
if want , have := len (refs ), len (mdStats ); want != have {
@@ -329,18 +334,32 @@ func TestFS_MDStat(t *testing.T) {
329
334
}
330
335
331
336
func TestInvalidMdstat (t * testing.T ) {
332
- invalidMount := [][]byte {[]byte (`
337
+ invalidMount := [][]byte {
338
+ // Test invalid Personality and format
339
+ []byte (`
333
340
Personalities : [invalid]
334
341
md3 : invalid
335
342
314159265 blocks 64k chunks
336
343
337
344
unused devices: <none>
338
345
` ),
346
+ // Test extra blank line
339
347
[]byte (`
340
348
md12 : active raid0 sdc2[0] sdd2[1]
341
349
342
350
3886394368 blocks super 1.2 512k chunks
343
- ` )}
351
+ ` ),
352
+ // test for impossible component state
353
+ []byte (`
354
+ md127 : active raid1 sdi2[0] sdj2[1](Z)
355
+ 312319552 blocks [2/2] [UU]
356
+ ` ),
357
+ // test for malformed component state
358
+ []byte (`
359
+ md127 : active raid1 sdi2[0] sdj2[X]
360
+ 312319552 blocks [2/2] [UU]
361
+ ` ),
362
+ }
344
363
345
364
for _ , invalid := range invalidMount {
346
365
_ , err := parseMDStat (invalid )
0 commit comments