Feedback on PR, thanks @tcolgate for the review
This commit is contained in:
parent
1f6b5aee39
commit
13aa37025f
|
@ -28,11 +28,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
statuslineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`)
|
statuslineRE = regexp.MustCompile(`(\d+) blocks .*\[(\d+)/(\d+)\] \[[U_]+\]`)
|
||||||
raid0lineRE = regexp.MustCompile(`(\d+) blocks( super ([0-9\.])*)? \d+k chunks`)
|
raid0lineRE = regexp.MustCompile(`(\d+) blocks( super ([0-9\.])*)? \d+k chunks`)
|
||||||
buildlineRE = regexp.MustCompile(`\((\d+)/\d+\)`)
|
buildlineRE = regexp.MustCompile(`\((\d+)/\d+\)`)
|
||||||
unknownPersonalityLine = regexp.MustCompile(`(\d+) blocks (.*)`)
|
unknownPersonalityLineRE = regexp.MustCompile(`(\d+) blocks (.*)`)
|
||||||
raidPersonalityRE = regexp.MustCompile(`raid[0-9]+`)
|
raidPersonalityRE = regexp.MustCompile(`raid[0-9]+`)
|
||||||
)
|
)
|
||||||
|
|
||||||
type mdStatus struct {
|
type mdStatus struct {
|
||||||
|
@ -94,8 +94,8 @@ func evalRaid0line(statusline string) (size int64, err error) {
|
||||||
return size, nil
|
return size, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func evalUnknownPersonalityline(statusline string) (size int64, err error) {
|
func evalUnknownPersonalitylineRE(statusline string) (size int64, err error) {
|
||||||
matches := unknownPersonalityLine.FindStringSubmatch(statusline)
|
matches := unknownPersonalityLineRE.FindStringSubmatch(statusline)
|
||||||
|
|
||||||
if len(matches) != 2+1 {
|
if len(matches) != 2+1 {
|
||||||
return 0, fmt.Errorf("invalid unknown personality status line: %s", statusline)
|
return 0, fmt.Errorf("invalid unknown personality status line: %s", statusline)
|
||||||
|
@ -176,10 +176,10 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
|
||||||
currentMD = mainLine[0] // The name of the md-device.
|
currentMD = mainLine[0] // The name of the md-device.
|
||||||
isActive := (mainLine[2] == "active") // The activity status of the md-device.
|
isActive := (mainLine[2] == "active") // The activity status of the md-device.
|
||||||
personality = ""
|
personality = ""
|
||||||
for _, possiblePersonality := range mainLine {
|
for _, possiblePersonality := range mainLine[3:] {
|
||||||
if raidPersonalityRE.MatchString(possiblePersonality) {
|
if raidPersonalityRE.MatchString(possiblePersonality) {
|
||||||
personality = possiblePersonality
|
personality = possiblePersonality
|
||||||
// break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
|
||||||
active, total, size, err = evalStatusline(lines[i+1]) // Parse statusline, always present.
|
active, total, size, err = evalStatusline(lines[i+1]) // Parse statusline, always present.
|
||||||
default:
|
default:
|
||||||
log.Infof("Personality unknown: %s\n", mainLine)
|
log.Infof("Personality unknown: %s\n", mainLine)
|
||||||
size, err = evalUnknownPersonalityline(lines[i+1]) // Parse statusline, always present.
|
size, err = evalUnknownPersonalitylineRE(lines[i+1]) // Parse statusline, always present.
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue