Skip to content

Commit 13aa370

Browse files
committed
Feedback on PR, thanks @tcolgate for the review
1 parent 1f6b5ae commit 13aa370

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

collector/mdadm_linux.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import (
2828
)
2929

3030
var (
31-
statuslineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`)
32-
raid0lineRE = regexp.MustCompile(`(\d+) blocks( super ([0-9\.])*)? \d+k chunks`)
33-
buildlineRE = regexp.MustCompile(`\((\d+)/\d+\)`)
34-
unknownPersonalityLine = regexp.MustCompile(`(\d+) blocks (.*)`)
35-
raidPersonalityRE = regexp.MustCompile(`raid[0-9]+`)
31+
statuslineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`)
32+
raid0lineRE = regexp.MustCompile(`(\d+) blocks( super ([0-9\.])*)? \d+k chunks`)
33+
buildlineRE = regexp.MustCompile(`\((\d+)/\d+\)`)
34+
unknownPersonalityLineRE = regexp.MustCompile(`(\d+) blocks (.*)`)
35+
raidPersonalityRE = regexp.MustCompile(`raid[0-9]+`)
3636
)
3737

3838
type mdStatus struct {
@@ -94,8 +94,8 @@ func evalRaid0line(statusline string) (size int64, err error) {
9494
return size, nil
9595
}
9696

97-
func evalUnknownPersonalityline(statusline string) (size int64, err error) {
98-
matches := unknownPersonalityLine.FindStringSubmatch(statusline)
97+
func evalUnknownPersonalitylineRE(statusline string) (size int64, err error) {
98+
matches := unknownPersonalityLineRE.FindStringSubmatch(statusline)
9999

100100
if len(matches) != 2+1 {
101101
return 0, fmt.Errorf("invalid unknown personality status line: %s", statusline)
@@ -176,10 +176,10 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
176176
currentMD = mainLine[0] // The name of the md-device.
177177
isActive := (mainLine[2] == "active") // The activity status of the md-device.
178178
personality = ""
179-
for _, possiblePersonality := range mainLine {
179+
for _, possiblePersonality := range mainLine[3:] {
180180
if raidPersonalityRE.MatchString(possiblePersonality) {
181181
personality = possiblePersonality
182-
// break
182+
break
183183
}
184184
}
185185

@@ -196,7 +196,7 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
196196
active, total, size, err = evalStatusline(lines[i+1]) // Parse statusline, always present.
197197
default:
198198
log.Infof("Personality unknown: %s\n", mainLine)
199-
size, err = evalUnknownPersonalityline(lines[i+1]) // Parse statusline, always present.
199+
size, err = evalUnknownPersonalitylineRE(lines[i+1]) // Parse statusline, always present.
200200
}
201201

202202
if err != nil {

0 commit comments

Comments
 (0)