Skip to content

Commit 2e01e40

Browse files
ImSingeerobbat2
authored andcommitted
support linear type in mdstat
Note: rebased on top of master for reformatting Signed-off-by: Singee <[email protected]> Signed-off-by: Robin H. Johnson <[email protected]>
1 parent 06e19a7 commit 2e01e40

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

mdstat.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
100100
state := deviceFields[2] // active or inactive
101101

102102
mdType := ""
103-
if len(deviceFields) > 3 && strings.HasPrefix(deviceFields[3], "raid") {
103+
if len(deviceFields) > 3 && isRaidType(deviceFields[3]) {
104104
mdType = deviceFields[3] // raid1, raid5, etc.
105-
} else if len(deviceFields) > 4 && strings.HasPrefix(deviceFields[4], "raid") {
105+
} else if len(deviceFields) > 4 && isRaidType(deviceFields[4]) {
106106
mdType = deviceFields[4]
107107
}
108108

@@ -182,6 +182,10 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
182182
return mdStats, nil
183183
}
184184

185+
func isRaidType(mdType string) bool {
186+
return strings.HasPrefix(mdType, "raid") || mdType == "linear"
187+
}
188+
185189
func evalStatusLine(deviceLine, statusLine string) (active, total, down, size int64, err error) {
186190
statusFields := strings.Fields(statusLine)
187191
if len(statusFields) < 1 {

mdstat_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func TestFS_MDStat(t *testing.T) {
206206
Devices: []string{"sdc2", "sdd2"}},
207207
"md120": {
208208
Name: "md120",
209-
Type: "",
209+
Type: "linear",
210210
ActivityState: "active",
211211
DisksActive: 2,
212212
DisksTotal: 2,

0 commit comments

Comments
 (0)