Skip to content

Commit 3efbe8c

Browse files
committed
fix mdraid with Intel VROC
Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
1 parent a6ebb3e commit 3efbe8c

4 files changed

Lines changed: 60 additions & 15 deletions

File tree

blockdevice/stats_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestBlockDevice(t *testing.T) {
7575
if err != nil {
7676
t.Fatal(err)
7777
}
78-
expectedNumOfDevices := 8
78+
expectedNumOfDevices := 9
7979
if len(devices) != expectedNumOfDevices {
8080
t.Fatalf(failMsgFormat, "Incorrect number of devices", expectedNumOfDevices, len(devices))
8181
}
@@ -95,18 +95,18 @@ func TestBlockDevice(t *testing.T) {
9595
if device0stats.WeightedIOTicks != 6088971 {
9696
t.Errorf(failMsgFormat, "Incorrect time in queue", 6088971, device0stats.WeightedIOTicks)
9797
}
98-
device7stats, count, err := blockdevice.SysBlockDeviceStat(devices[7])
98+
device8stats, count, err := blockdevice.SysBlockDeviceStat(devices[8])
9999
if count != 15 {
100100
t.Errorf(failMsgFormat, "Incorrect number of stats read", 15, count)
101101
}
102102
if err != nil {
103103
t.Fatal(err)
104104
}
105-
if device7stats.WriteSectors != 286915323 {
106-
t.Errorf(failMsgFormat, "Incorrect write merges", 286915323, device7stats.WriteSectors)
105+
if device8stats.WriteSectors != 286915323 {
106+
t.Errorf(failMsgFormat, "Incorrect write merges", 286915323, device8stats.WriteSectors)
107107
}
108-
if device7stats.DiscardTicks != 12 {
109-
t.Errorf(failMsgFormat, "Incorrect discard ticks", 12, device7stats.DiscardTicks)
108+
if device8stats.DiscardTicks != 12 {
109+
t.Errorf(failMsgFormat, "Incorrect discard ticks", 12, device8stats.DiscardTicks)
110110
}
111111
blockQueueStatExpected := BlockQueueStats{
112112
AddRandom: 1,
@@ -147,7 +147,7 @@ func TestBlockDevice(t *testing.T) {
147147
WriteZeroesMaxBytes: 0,
148148
}
149149

150-
blockQueueStat, err := blockdevice.SysBlockDeviceQueueStats(devices[7])
150+
blockQueueStat, err := blockdevice.SysBlockDeviceQueueStats(devices[8])
151151
if err != nil {
152152
t.Fatal(err)
153153
}
@@ -232,12 +232,12 @@ func TestSysBlockDeviceSize(t *testing.T) {
232232
if err != nil {
233233
t.Fatal(err)
234234
}
235-
size7, err := blockdevice.SysBlockDeviceSize(devices[7])
235+
size8, err := blockdevice.SysBlockDeviceSize(devices[8])
236236
if err != nil {
237237
t.Fatal(err)
238238
}
239-
size7Expected := uint64(1920383410176)
240-
if size7 != size7Expected {
241-
t.Errorf("Incorrect BlockDeviceSize, expected: \n%+v, got: \n%+v", size7Expected, size7)
239+
size8Expected := uint64(1920383410176)
240+
if size8 != size8Expected {
241+
t.Errorf("Incorrect BlockDeviceSize, expected: \n%+v, got: \n%+v", size8Expected, size8)
242242
}
243243
}

sysfs/mdraid.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,16 @@ func (fs FS) Mdraids() ([]Mdraid, error) {
8181
return mdraids, err
8282
}
8383

84-
if val, err := util.ReadUintFromFile(filepath.Join(path, "raid_disks")); err == nil {
85-
md.Disks = val
86-
} else {
87-
return mdraids, err
84+
// RAID level is set to 'container', 'imsm' or 'ddf', no physical disks are assigned.
85+
switch md.Level {
86+
case "container", "imsm", "ddf":
87+
md.Disks = 0
88+
default:
89+
if val, err := util.ReadUintFromFile(filepath.Join(path, "raid_disks")); err == nil {
90+
md.Disks = val
91+
} else {
92+
return mdraids, err
93+
}
8894
}
8995

9096
if val, err := util.SysReadFile(filepath.Join(path, "uuid")); err == nil {

sysfs/mdraid_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ func TestMdraidStats(t *testing.T) {
125125
SyncAction: "recover",
126126
SyncCompleted: 0.7500458659491194,
127127
},
128+
{
129+
Device: "md7",
130+
Level: "container",
131+
ArrayState: "inactive",
132+
MetadataVersion: "1.2",
133+
Disks: 0,
134+
UUID: "0e51f6d1-b357-2712-8eaa-31f6f597be6b",
135+
},
128136
}
129137

130138
if diff := cmp.Diff(want, got); diff != "" {

testdata/fixtures.ttar

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4478,6 +4478,37 @@ Lines: 1
44784478
5f529b25-6efd-46e4-99a2-31f6f597be6b
44794479
Mode: 444
44804480
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4481+
Directory: fixtures/sys/block/md7
4482+
Mode: 755
4483+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4484+
Directory: fixtures/sys/block/md7/md
4485+
Mode: 755
4486+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4487+
Path: fixtures/sys/block/md7/md/array_state
4488+
Lines: 1
4489+
inactive
4490+
Mode: 644
4491+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4492+
Path: fixtures/sys/block/md7/md/level
4493+
Lines: 1
4494+
container
4495+
Mode: 644
4496+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4497+
Path: fixtures/sys/block/md7/md/metadata_version
4498+
Lines: 1
4499+
1.2
4500+
Mode: 644
4501+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4502+
Path: fixtures/sys/block/md7/md/raid_disks
4503+
Lines: 1
4504+
4505+
Mode: 644
4506+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
4507+
Path: fixtures/sys/block/md7/md/uuid
4508+
Lines: 1
4509+
0e51f6d1-b357-2712-8eaa-31f6f597be6b
4510+
Mode: 444
4511+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44814512
Directory: fixtures/sys/block/sda
44824513
Mode: 755
44834514
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

0 commit comments

Comments
 (0)