diff --git a/blockdevice/stats_test.go b/blockdevice/stats_test.go index 018671fe..a17df8ee 100644 --- a/blockdevice/stats_test.go +++ b/blockdevice/stats_test.go @@ -75,7 +75,7 @@ func TestBlockDevice(t *testing.T) { if err != nil { t.Fatal(err) } - expectedNumOfDevices := 8 + expectedNumOfDevices := 9 if len(devices) != expectedNumOfDevices { t.Fatalf(failMsgFormat, "Incorrect number of devices", expectedNumOfDevices, len(devices)) } @@ -95,18 +95,18 @@ func TestBlockDevice(t *testing.T) { if device0stats.WeightedIOTicks != 6088971 { t.Errorf(failMsgFormat, "Incorrect time in queue", 6088971, device0stats.WeightedIOTicks) } - device7stats, count, err := blockdevice.SysBlockDeviceStat(devices[7]) + device8stats, count, err := blockdevice.SysBlockDeviceStat(devices[8]) if count != 15 { t.Errorf(failMsgFormat, "Incorrect number of stats read", 15, count) } if err != nil { t.Fatal(err) } - if device7stats.WriteSectors != 286915323 { - t.Errorf(failMsgFormat, "Incorrect write merges", 286915323, device7stats.WriteSectors) + if device8stats.WriteSectors != 286915323 { + t.Errorf(failMsgFormat, "Incorrect write merges", 286915323, device8stats.WriteSectors) } - if device7stats.DiscardTicks != 12 { - t.Errorf(failMsgFormat, "Incorrect discard ticks", 12, device7stats.DiscardTicks) + if device8stats.DiscardTicks != 12 { + t.Errorf(failMsgFormat, "Incorrect discard ticks", 12, device8stats.DiscardTicks) } blockQueueStatExpected := BlockQueueStats{ AddRandom: 1, @@ -147,7 +147,7 @@ func TestBlockDevice(t *testing.T) { WriteZeroesMaxBytes: 0, } - blockQueueStat, err := blockdevice.SysBlockDeviceQueueStats(devices[7]) + blockQueueStat, err := blockdevice.SysBlockDeviceQueueStats(devices[8]) if err != nil { t.Fatal(err) } @@ -232,12 +232,12 @@ func TestSysBlockDeviceSize(t *testing.T) { if err != nil { t.Fatal(err) } - size7, err := blockdevice.SysBlockDeviceSize(devices[7]) + size8, err := blockdevice.SysBlockDeviceSize(devices[8]) if err != nil { t.Fatal(err) } - size7Expected := uint64(1920383410176) - if size7 != size7Expected { - t.Errorf("Incorrect BlockDeviceSize, expected: \n%+v, got: \n%+v", size7Expected, size7) + size8Expected := uint64(1920383410176) + if size8 != size8Expected { + t.Errorf("Incorrect BlockDeviceSize, expected: \n%+v, got: \n%+v", size8Expected, size8) } } diff --git a/sysfs/mdraid.go b/sysfs/mdraid.go index 139c7ebe..bd286eb9 100644 --- a/sysfs/mdraid.go +++ b/sysfs/mdraid.go @@ -81,10 +81,16 @@ func (fs FS) Mdraids() ([]Mdraid, error) { return mdraids, err } - if val, err := util.ReadUintFromFile(filepath.Join(path, "raid_disks")); err == nil { - md.Disks = val - } else { - return mdraids, err + // RAID level is set to 'container', 'imsm' or 'ddf', no physical disks are assigned. + switch md.Level { + case "container", "imsm", "ddf": + md.Disks = 0 + default: + if val, err := util.ReadUintFromFile(filepath.Join(path, "raid_disks")); err == nil { + md.Disks = val + } else { + return mdraids, err + } } if val, err := util.SysReadFile(filepath.Join(path, "uuid")); err == nil { diff --git a/sysfs/mdraid_test.go b/sysfs/mdraid_test.go index cef9a342..5065c5bd 100644 --- a/sysfs/mdraid_test.go +++ b/sysfs/mdraid_test.go @@ -125,6 +125,14 @@ func TestMdraidStats(t *testing.T) { SyncAction: "recover", SyncCompleted: 0.7500458659491194, }, + { + Device: "md7", + Level: "container", + ArrayState: "inactive", + MetadataVersion: "1.2", + Disks: 0, + UUID: "0e51f6d1-b357-2712-8eaa-31f6f597be6b", + }, } if diff := cmp.Diff(want, got); diff != "" { diff --git a/testdata/fixtures.ttar b/testdata/fixtures.ttar index 333850c3..3e0b44d0 100644 --- a/testdata/fixtures.ttar +++ b/testdata/fixtures.ttar @@ -4478,6 +4478,37 @@ Lines: 1 5f529b25-6efd-46e4-99a2-31f6f597be6b Mode: 444 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: fixtures/sys/block/md7 +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: fixtures/sys/block/md7/md +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/block/md7/md/array_state +Lines: 1 +inactive +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/block/md7/md/level +Lines: 1 +container +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/block/md7/md/metadata_version +Lines: 1 +1.2 +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/block/md7/md/raid_disks +Lines: 1 + +Mode: 644 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Path: fixtures/sys/block/md7/md/uuid +Lines: 1 +0e51f6d1-b357-2712-8eaa-31f6f597be6b +Mode: 444 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: fixtures/sys/block/sda Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -