@@ -97,11 +97,14 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
9797 mdName := deviceFields [0 ] // mdx
9898 state := deviceFields [2 ] // active or inactive
9999
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+ }
105108 }
106109
107110 if len (lines ) <= i + 3 {
@@ -175,8 +178,11 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
175178 return mdStats , nil
176179}
177180
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]
178184func isRaidType (mdType string ) bool {
179- return strings .HasPrefix (mdType , "raid" ) || mdType == "linear"
185+ return ! strings .ContainsAny (mdType , "([" )
180186}
181187
182188func evalStatusLine (deviceLine , statusLine string ) (active , total , down , size int64 , err error ) {
0 commit comments