@@ -26,6 +26,11 @@ func TestFS_MDStat(t *testing.T) {
2626 if err != nil {
2727 t .Fatalf ("parsing of reference-file failed entirely: %s" , err )
2828 }
29+ // TODO: Test cases to capture in future:
30+ // WriteMostly devices
31+ // Journal devices
32+ // Replacement devices
33+ // Global hotspares
2934
3035 refs := map [string ]MDStat {
3136 "md127" : {
@@ -43,7 +48,7 @@ func TestFS_MDStat(t *testing.T) {
4348 BlocksSyncedPct : 0 ,
4449 BlocksSyncedFinishTime : 0 ,
4550 BlocksSyncedSpeed : 0 ,
46- Devices : []string { "sdi2" , "sdj2" }},
51+ Devices : []MDStatComponent {{ Name : "sdi2" , DescriptorIndex : 0 }, { Name : "sdj2" , DescriptorIndex : 1 } }},
4752 "md0" : {
4853 Name : "md0" ,
4954 Type : "raid1" ,
@@ -59,7 +64,7 @@ func TestFS_MDStat(t *testing.T) {
5964 BlocksSyncedPct : 0 ,
6065 BlocksSyncedFinishTime : 0 ,
6166 BlocksSyncedSpeed : 0 ,
62- Devices : []string { "sdi1" , "sdj1" }},
67+ Devices : []MDStatComponent {{ Name : "sdi1" , DescriptorIndex : 0 }, { Name : "sdj1" , DescriptorIndex : 1 } }},
6368 "md4" : {
6469 Name : "md4" ,
6570 Type : "raid1" ,
@@ -75,7 +80,7 @@ func TestFS_MDStat(t *testing.T) {
7580 BlocksSyncedPct : 0 ,
7681 BlocksSyncedFinishTime : 0 ,
7782 BlocksSyncedSpeed : 0 ,
78- Devices : []string { "sda3" , "sdb3" }},
83+ Devices : []MDStatComponent {{ Name : "sda3" , Faulty : true , DescriptorIndex : 0 }, { Name : "sdb3" , Spare : true , DescriptorIndex : 1 } }},
7984 "md6" : {
8085 Name : "md6" ,
8186 Type : "raid1" ,
@@ -91,7 +96,7 @@ func TestFS_MDStat(t *testing.T) {
9196 BlocksSyncedPct : 8.5 ,
9297 BlocksSyncedFinishTime : 17 ,
9398 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 } }},
95100 "md3" : {
96101 Name : "md3" ,
97102 Type : "raid6" ,
@@ -107,7 +112,7 @@ func TestFS_MDStat(t *testing.T) {
107112 BlocksSyncedPct : 0 ,
108113 BlocksSyncedFinishTime : 0 ,
109114 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 } }},
111116 "md8" : {
112117 Name : "md8" ,
113118 Type : "raid1" ,
@@ -123,7 +128,7 @@ func TestFS_MDStat(t *testing.T) {
123128 BlocksSyncedPct : 8.5 ,
124129 BlocksSyncedFinishTime : 17 ,
125130 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 } }},
127132 "md7" : {
128133 Name : "md7" ,
129134 Type : "raid6" ,
@@ -139,7 +144,7 @@ func TestFS_MDStat(t *testing.T) {
139144 BlocksSyncedPct : 0 ,
140145 BlocksSyncedFinishTime : 0 ,
141146 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 } }},
143148 "md9" : {
144149 Name : "md9" ,
145150 Type : "raid1" ,
@@ -155,7 +160,7 @@ func TestFS_MDStat(t *testing.T) {
155160 BlocksSyncedPct : 0 ,
156161 BlocksSyncedFinishTime : 0 ,
157162 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 } }},
159164 "md10" : {
160165 Name : "md10" ,
161166 Type : "raid0" ,
@@ -171,7 +176,7 @@ func TestFS_MDStat(t *testing.T) {
171176 BlocksSyncedPct : 0 ,
172177 BlocksSyncedFinishTime : 0 ,
173178 BlocksSyncedSpeed : 0 ,
174- Devices : []string { "sda1" , "sdb1" }},
179+ Devices : []MDStatComponent {{ Name : "sda1" , DescriptorIndex : 0 }, { Name : "sdb1" , DescriptorIndex : 1 } }},
175180 "md11" : {
176181 Name : "md11" ,
177182 Type : "raid1" ,
@@ -187,7 +192,7 @@ func TestFS_MDStat(t *testing.T) {
187192 BlocksSyncedPct : 0 ,
188193 BlocksSyncedFinishTime : 0 ,
189194 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 } }},
191196 "md12" : {
192197 Name : "md12" ,
193198 Type : "raid0" ,
@@ -203,7 +208,7 @@ func TestFS_MDStat(t *testing.T) {
203208 BlocksSyncedPct : 0 ,
204209 BlocksSyncedFinishTime : 0 ,
205210 BlocksSyncedSpeed : 0 ,
206- Devices : []string { "sdc2" , "sdd2" }},
211+ Devices : []MDStatComponent {{ Name : "sdc2" , DescriptorIndex : 0 }, { Name : "sdd2" , DescriptorIndex : 1 } }},
207212 "md120" : {
208213 Name : "md120" ,
209214 Type : "linear" ,
@@ -219,7 +224,7 @@ func TestFS_MDStat(t *testing.T) {
219224 BlocksSyncedPct : 0 ,
220225 BlocksSyncedFinishTime : 0 ,
221226 BlocksSyncedSpeed : 0 ,
222- Devices : []string { "sda1" , "sdb1" }},
227+ Devices : []MDStatComponent {{ Name : "sda1" , DescriptorIndex : 1 }, { Name : "sdb1" , DescriptorIndex : 0 } }},
223228 "md126" : {
224229 Name : "md126" ,
225230 Type : "raid0" ,
@@ -235,7 +240,7 @@ func TestFS_MDStat(t *testing.T) {
235240 BlocksSyncedPct : 0 ,
236241 BlocksSyncedFinishTime : 0 ,
237242 BlocksSyncedSpeed : 0 ,
238- Devices : []string { "sdb" , "sdc" }},
243+ Devices : []MDStatComponent {{ Name : "sdb" , DescriptorIndex : 1 }, { Name : "sdc" , DescriptorIndex : 0 } }},
239244 "md219" : {
240245 Name : "md219" ,
241246 Type : "unknown" ,
@@ -251,7 +256,7 @@ func TestFS_MDStat(t *testing.T) {
251256 BlocksSyncedPct : 0 ,
252257 BlocksSyncedFinishTime : 0 ,
253258 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 } }},
255260 "md00" : {
256261 Name : "md00" ,
257262 Type : "raid0" ,
@@ -267,7 +272,7 @@ func TestFS_MDStat(t *testing.T) {
267272 BlocksSyncedPct : 0 ,
268273 BlocksSyncedFinishTime : 0 ,
269274 BlocksSyncedSpeed : 0 ,
270- Devices : []string { "xvdb" }},
275+ Devices : []MDStatComponent {{ Name : "xvdb" , DescriptorIndex : 0 } }},
271276 "md101" : {
272277 Name : "md101" ,
273278 Type : "raid0" ,
@@ -283,7 +288,7 @@ func TestFS_MDStat(t *testing.T) {
283288 BlocksSyncedPct : 0 ,
284289 BlocksSyncedFinishTime : 0 ,
285290 BlocksSyncedSpeed : 0 ,
286- Devices : []string { "sdb" , "sdd" , "sdc" }},
291+ Devices : []MDStatComponent {{ Name : "sdb" , DescriptorIndex : 2 }, { Name : "sdd" , DescriptorIndex : 1 }, { Name : "sdc" , DescriptorIndex : 0 } }},
287292 "md201" : {
288293 Name : "md201" ,
289294 Type : "raid1" ,
@@ -299,7 +304,7 @@ func TestFS_MDStat(t *testing.T) {
299304 BlocksSyncedPct : 5.7 ,
300305 BlocksSyncedFinishTime : 0.2 ,
301306 BlocksSyncedSpeed : 114176 ,
302- Devices : []string { "sda3" , "sdb3" }},
307+ Devices : []MDStatComponent {{ Name : "sda3" , DescriptorIndex : 0 }, { Name : "sdb3" , DescriptorIndex : 1 } }},
303308 }
304309
305310 if want , have := len (refs ), len (mdStats ); want != have {
@@ -314,18 +319,32 @@ func TestFS_MDStat(t *testing.T) {
314319}
315320
316321func TestInvalidMdstat (t * testing.T ) {
317- invalidMount := [][]byte {[]byte (`
322+ invalidMount := [][]byte {
323+ // Test invalid Personality and format
324+ []byte (`
318325Personalities : [invalid]
319326md3 : invalid
320327 314159265 blocks 64k chunks
321328
322329unused devices: <none>
323330` ),
331+ // Test extra blank line
324332 []byte (`
325333md12 : active raid0 sdc2[0] sdd2[1]
326334
327335 3886394368 blocks super 1.2 512k chunks
328- ` )}
336+ ` ),
337+ // test for impossible component state
338+ []byte (`
339+ md127 : active raid1 sdi2[0] sdj2[1](Z)
340+ 312319552 blocks [2/2] [UU]
341+ ` ),
342+ // test for malformed component state
343+ []byte (`
344+ md127 : active raid1 sdi2[0] sdj2[X]
345+ 312319552 blocks [2/2] [UU]
346+ ` ),
347+ }
329348
330349 for _ , invalid := range invalidMount {
331350 _ , err := parseMDStat (invalid )
0 commit comments