-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmart_array_raid_60_reader.cpp
More file actions
86 lines (70 loc) · 2.81 KB
/
smart_array_raid_60_reader.cpp
File metadata and controls
86 lines (70 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "smart_array_raid_60_reader.hpp"
namespace sg
{
SmartArrayRaid60Reader::SmartArrayRaid60Reader(const SmartArrayRaid60ReaderOptions &options)
{
if (options.driveReaders.size() < 6)
{
throw std::invalid_argument("For RAID 60 at least 8 drives must be provided (two for each parity group can be missing but still they have to be in the driveReaders list represented with nullptr)");
}
u16 drivesPerParityGroup = options.driveReaders.size() / options.parityGroups;
if (drivesPerParityGroup < 4)
{
throw std::invalid_argument("For RAID 60 there must be at least 4 drives per parity group.");
}
if (drivesPerParityGroup * options.parityGroups != options.driveReaders.size())
{
throw std::invalid_argument("For RAID 60 number of provided drives must be divisible by parity groups.");
}
std::vector<std::shared_ptr<DriveReader>> parityGroupsReaders;
SmartArrayRaid6ReaderOptions parityOptions;
int missingDrives = 0;
for (auto drive : options.driveReaders)
{
parityOptions.readerName += (drive ? drive->name() : "X") + " ";
if (!drive)
{
missingDrives++;
if (missingDrives > 2)
{
throw std::invalid_argument("For RAID 60 only 2 missing drives per parity group are allowed.");
}
}
parityOptions.driveReaders.push_back(drive);
if (parityOptions.driveReaders.size() == drivesPerParityGroup)
{
// Remove leading space
parityOptions.readerName.erase(parityOptions.readerName.end() - 1);
parityOptions.stripeSize = options.stripeSize;
parityOptions.parityDelay = options.parityDelay;
parityOptions.size = options.size / options.parityGroups;
parityOptions.offset = options.offset;
parityGroupsReaders.push_back(
std::make_shared<SmartArrayRaid6Reader>(parityOptions)
);
parityOptions = SmartArrayRaid6ReaderOptions();
missingDrives = 0;
}
}
SmartArrayRaid0ReaderOptions reader0Options {
.stripeSize = options.stripeSize * (drivesPerParityGroup - 2),
.driveReaders = parityGroupsReaders,
.readerName = "RAID 60 - Raid 0 reader",
.size = options.size,
// Offset is zero here, because in raid 60 raid 0 is not
// "touching" physical drives direcly but rather thru
// raid 6 readers
.offset = 0,
.nometadata = true
};
this->raid0Reader = std::make_unique<SmartArrayRaid0Reader>(reader0Options);
}
int SmartArrayRaid60Reader::read(void *buf, u32 len, u64 offset)
{
return this->raid0Reader->read(buf, len, offset);
}
u64 SmartArrayRaid60Reader::driveSize()
{
return this->raid0Reader->driveSize();
}
} // end namespace sg