diff --git a/mdstat.go b/mdstat.go index 85431b65..80c28e8d 100644 --- a/mdstat.go +++ b/mdstat.go @@ -98,9 +98,9 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { state := deviceFields[2] // active or inactive mdType := "" - if len(deviceFields) > 3 && strings.HasPrefix(deviceFields[3], "raid") { + if len(deviceFields) > 3 && isRaidType(deviceFields[3]) { mdType = deviceFields[3] // raid1, raid5, etc. - } else if len(deviceFields) > 4 && strings.HasPrefix(deviceFields[4], "raid") { + } else if len(deviceFields) > 4 && isRaidType(deviceFields[4]) { mdType = deviceFields[4] } @@ -175,6 +175,10 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { return mdStats, nil } +func isRaidType(mdType string) bool { + return strings.HasPrefix(mdType, "raid") || mdType == "linear" +} + func evalStatusLine(deviceLine, statusLine string) (active, total, down, size int64, err error) { statusFields := strings.Fields(statusLine) if len(statusFields) < 1 { diff --git a/mdstat_test.go b/mdstat_test.go index 0d43ece7..c7f6c0ec 100644 --- a/mdstat_test.go +++ b/mdstat_test.go @@ -36,7 +36,7 @@ func TestFS_MDStat(t *testing.T) { "md10": {Name: "md10", Type: "raid0", ActivityState: "active", DisksActive: 2, DisksTotal: 2, DisksFailed: 0, DisksDown: 0, DisksSpare: 0, BlocksTotal: 314159265, BlocksSynced: 314159265, BlocksSyncedPct: 0, BlocksSyncedFinishTime: 0, BlocksSyncedSpeed: 0, Devices: []string{"sda1", "sdb1"}}, "md11": {Name: "md11", Type: "raid1", ActivityState: "resyncing", DisksActive: 2, DisksTotal: 2, DisksFailed: 1, DisksDown: 0, DisksSpare: 2, BlocksTotal: 4190208, BlocksSynced: 0, BlocksSyncedPct: 0, BlocksSyncedFinishTime: 0, BlocksSyncedSpeed: 0, Devices: []string{"sdb2", "sdc2", "sdc3", "hda", "ssdc2"}}, "md12": {Name: "md12", Type: "raid0", ActivityState: "active", DisksActive: 2, DisksTotal: 2, DisksSpare: 0, DisksDown: 0, DisksFailed: 0, BlocksTotal: 3886394368, BlocksSynced: 3886394368, BlocksSyncedPct: 0, BlocksSyncedFinishTime: 0, BlocksSyncedSpeed: 0, Devices: []string{"sdc2", "sdd2"}}, - "md120": {Name: "md120", Type: "", ActivityState: "active", DisksActive: 2, DisksTotal: 2, DisksFailed: 0, DisksDown: 0, DisksSpare: 0, BlocksTotal: 2095104, BlocksSynced: 2095104, BlocksSyncedPct: 0, BlocksSyncedFinishTime: 0, BlocksSyncedSpeed: 0, Devices: []string{"sda1", "sdb1"}}, + "md120": {Name: "md120", Type: "linear", ActivityState: "active", DisksActive: 2, DisksTotal: 2, DisksFailed: 0, DisksDown: 0, DisksSpare: 0, BlocksTotal: 2095104, BlocksSynced: 2095104, BlocksSyncedPct: 0, BlocksSyncedFinishTime: 0, BlocksSyncedSpeed: 0, Devices: []string{"sda1", "sdb1"}}, "md126": {Name: "md126", Type: "raid0", ActivityState: "active", DisksActive: 2, DisksTotal: 2, DisksFailed: 0, DisksDown: 0, DisksSpare: 0, BlocksTotal: 1855870976, BlocksSynced: 1855870976, BlocksSyncedPct: 0, BlocksSyncedFinishTime: 0, BlocksSyncedSpeed: 0, Devices: []string{"sdb", "sdc"}}, "md219": {Name: "md219", Type: "", ActivityState: "inactive", DisksTotal: 0, DisksFailed: 0, DisksActive: 0, DisksDown: 0, DisksSpare: 3, BlocksTotal: 7932, BlocksSynced: 7932, BlocksSyncedPct: 0, BlocksSyncedFinishTime: 0, BlocksSyncedSpeed: 0, Devices: []string{"sdc", "sda"}}, "md00": {Name: "md00", Type: "raid0", ActivityState: "active", DisksActive: 1, DisksTotal: 1, DisksFailed: 0, DisksDown: 0, DisksSpare: 0, BlocksTotal: 4186624, BlocksSynced: 4186624, BlocksSyncedPct: 0, BlocksSyncedFinishTime: 0, BlocksSyncedSpeed: 0, Devices: []string{"xvdb"}},