Initial Software RAID creation.
This commit is contained in:
parent
0201171956
commit
fed87159da
|
@ -380,7 +380,26 @@ bool SoftwareRAID::createSoftwareRAID(Report &report,
|
||||||
const qint32 raidLevel,
|
const qint32 raidLevel,
|
||||||
const qint32 chunkSize)
|
const qint32 chunkSize)
|
||||||
{
|
{
|
||||||
return false;
|
QStringList args;
|
||||||
|
args << QStringLiteral("--create") << name;
|
||||||
|
args << QStringLiteral("--level=") + QString::number(raidLevel);
|
||||||
|
args << QStringLiteral("--chunk=") + QString::number(chunkSize);
|
||||||
|
args << QStringLiteral("--raid-devices=") + QString::number(devicePathList.size());
|
||||||
|
|
||||||
|
for (const QString path : qAsConst(devicePathList)) {
|
||||||
|
if (!eraseDeviceMDSuperblock(path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
args << path;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExternalCommand cmd(QStringLiteral("mdadm"), args);
|
||||||
|
|
||||||
|
if (!cmd.run(-1) || cmd.exitCode() != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: Support custom config files.
|
||||||
|
return updateConfigurationFile(QStringLiteral("/etc/mdadm.conf"), cmd.output());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoftwareRAID::deleteSoftwareRAID(Report &report,
|
bool SoftwareRAID::deleteSoftwareRAID(Report &report,
|
||||||
|
@ -456,6 +475,30 @@ qint64 SoftwareRAID::mappedSector(const QString &partitionPath, qint64 sector) c
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SoftwareRAID::eraseDeviceMDSuperblock(const QString &path)
|
||||||
|
{
|
||||||
|
ExternalCommand cmd(QStringLiteral("mdadm"),
|
||||||
|
{ QStringLiteral("--misc"), QStringLiteral("--zero-superblock"), path});
|
||||||
|
|
||||||
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SoftwareRAID::updateConfigurationFile(const QString &configurationPath, const QString &info)
|
||||||
|
{
|
||||||
|
QFile config(configurationPath);
|
||||||
|
|
||||||
|
if (!config.open(QIODevice::WriteOnly | QIODevice::Append))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QTextStream out(&config);
|
||||||
|
|
||||||
|
out << info << QLatin1Char('\n');
|
||||||
|
|
||||||
|
config.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QString SoftwareRAID::getDetail(const QString &path)
|
QString SoftwareRAID::getDetail(const QString &path)
|
||||||
{
|
{
|
||||||
ExternalCommand cmd(QStringLiteral("mdadm"),
|
ExternalCommand cmd(QStringLiteral("mdadm"),
|
||||||
|
|
|
@ -95,6 +95,10 @@ protected:
|
||||||
qint64 mappedSector(const QString &partitionPath, qint64 sector) const override;
|
qint64 mappedSector(const QString &partitionPath, qint64 sector) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool eraseDeviceMDSuperblock(const QString& path);
|
||||||
|
|
||||||
|
static bool updateConfigurationFile(const QString& configurationPath, const QString& info);
|
||||||
|
|
||||||
static QString getDetail(const QString& path);
|
static QString getDetail(const QString& path);
|
||||||
|
|
||||||
static QString getRAIDConfiguration(const QString& configurationPath);
|
static QString getRAIDConfiguration(const QString& configurationPath);
|
||||||
|
|
Loading…
Reference in New Issue