@@ -97,11 +97,14 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
97
97
mdName := deviceFields [0 ] // mdx
98
98
state := deviceFields [2 ] // active or inactive
99
99
100
- mdType := "unknown"
101
- if len (deviceFields ) > 3 && isRaidType (deviceFields [3 ]) {
102
- mdType = deviceFields [3 ] // raid1, raid5, etc.
103
- } else if len (deviceFields ) > 4 && isRaidType (deviceFields [4 ]) {
104
- mdType = deviceFields [4 ]
100
+ mdType := "unknown" // raid1, raid5, etc.
101
+ if len (deviceFields ) > 3 { // mdType may be in the 3rd or 4th field
102
+ if isRaidType (deviceFields [3 ]) {
103
+ mdType = deviceFields [3 ]
104
+ } else if len (deviceFields ) > 4 && isRaidType (deviceFields [4 ]) {
105
+ // if the 3rd field is (...), the 4th field is the mdType
106
+ mdType = deviceFields [4 ]
107
+ }
105
108
}
106
109
107
110
if len (lines ) <= i + 3 {
@@ -175,8 +178,11 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
175
178
return mdStats , nil
176
179
}
177
180
181
+ // check if a string's format is like the mdType
182
+ // Rule 1: mdType should not be like (...)
183
+ // Rule 2: mdType should not be like sda[0]
178
184
func isRaidType (mdType string ) bool {
179
- return strings .HasPrefix (mdType , "raid" ) || mdType == "linear"
185
+ return ! strings .ContainsAny (mdType , "([" )
180
186
}
181
187
182
188
func evalStatusLine (deviceLine , statusLine string ) (active , total , down , size int64 , err error ) {
0 commit comments