From 7558d2ba4a59f697bb294998fada380f67e581b9 Mon Sep 17 00:00:00 2001 From: Singee Date: Thu, 13 Apr 2023 17:05:59 +0800 Subject: [PATCH] support linear type in mdstat --- mdstat.go | 4 ++-- mdstat_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mdstat.go b/mdstat.go index 85431b65..0c719598 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 && !strings.HasPrefix(deviceFields[3], "(") { mdType = deviceFields[3] // raid1, raid5, etc. - } else if len(deviceFields) > 4 && strings.HasPrefix(deviceFields[4], "raid") { + } else if len(deviceFields) > 4 && !strings.HasPrefix(deviceFields[4], "(") { mdType = deviceFields[4] } 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"}},