Adding reassemble method for SoftwareRAID.

This commit is contained in:
Caio Carvalho 2018-07-12 14:38:52 -03:00
parent 3f7c5ca722
commit d8602817f0
3 changed files with 20 additions and 12 deletions

View File

@ -218,22 +218,33 @@ bool SoftwareRAID::deleteSoftwareRAID(Report &report,
return false; return false;
} }
bool SoftwareRAID::assembleSoftwareRAID(const SoftwareRAID &raidDevice) bool SoftwareRAID::assembleSoftwareRAID(const QString& deviceNode)
{ {
if (!isRaidPath(deviceNode))
return false;
ExternalCommand cmd(QStringLiteral("mdadm"), ExternalCommand cmd(QStringLiteral("mdadm"),
{ QStringLiteral("--assemble"), QStringLiteral("--scan"), raidDevice.deviceNode() }); { QStringLiteral("--assemble"), QStringLiteral("--scan"), deviceNode });
return cmd.run(-1) && cmd.exitCode() == 0; return cmd.run(-1) && cmd.exitCode() == 0;
} }
bool SoftwareRAID::stopSoftwareRAID(const SoftwareRAID &raidDevice) bool SoftwareRAID::stopSoftwareRAID(const QString& deviceNode)
{ {
if (!isRaidPath(deviceNode))
return false;
ExternalCommand cmd(QStringLiteral("mdadm"), ExternalCommand cmd(QStringLiteral("mdadm"),
{ QStringLiteral("--stop"), raidDevice.deviceNode() }); { QStringLiteral("--stop"), deviceNode });
return cmd.run(-1) && cmd.exitCode() == 0; return cmd.run(-1) && cmd.exitCode() == 0;
} }
bool SoftwareRAID::reassembleSoftwareRAID(const QString &deviceNode)
{
return stopSoftwareRAID(deviceNode) && assembleSoftwareRAID(deviceNode);
}
void SoftwareRAID::initPartitions() void SoftwareRAID::initPartitions()
{ {

View File

@ -65,9 +65,11 @@ public:
static bool deleteSoftwareRAID(Report& report, static bool deleteSoftwareRAID(Report& report,
SoftwareRAID& raidDevice); SoftwareRAID& raidDevice);
static bool assembleSoftwareRAID(const SoftwareRAID& raidDevice); static bool assembleSoftwareRAID(const QString& deviceNode);
static bool stopSoftwareRAID(const SoftwareRAID& raidDevice); static bool stopSoftwareRAID(const QString& deviceNode);
static bool reassembleSoftwareRAID(const QString& deviceNode);
protected: protected:
void initPartitions() override; void initPartitions() override;

View File

@ -57,12 +57,7 @@ bool SfdiskPartitionTable::commit(quint32 timeout)
ExternalCommand(QStringLiteral("blockdev"), { QStringLiteral("--rereadpt"), m_device->deviceNode() }).run(); ExternalCommand(QStringLiteral("blockdev"), { QStringLiteral("--rereadpt"), m_device->deviceNode() }).run();
ExternalCommand(QStringLiteral("udevadm"), { QStringLiteral("trigger") }).run(); ExternalCommand(QStringLiteral("udevadm"), { QStringLiteral("trigger") }).run();
if (m_device->type() == Device::Type::SoftwareRAID_Device) SoftwareRAID::reassembleSoftwareRAID(m_device->deviceNode());
{
const SoftwareRAID& raid = static_cast<const SoftwareRAID&>(*m_device);
SoftwareRAID::stopSoftwareRAID(raid);
SoftwareRAID::assembleSoftwareRAID(raid);
}
return true; return true;
} }