Setting mount point for linux_raid_member partitions.

This commit is contained in:
Caio Carvalho 2018-08-14 15:07:48 +02:00
parent 213162c1a8
commit 1c714c7854
4 changed files with 18 additions and 27 deletions

View File

@ -369,9 +369,9 @@ QStringList SoftwareRAID::getDevicePathList(const QString &path)
return result;
}
bool SoftwareRAID::isRaidPath(const QString &path)
bool SoftwareRAID::isRaidPath(const QString &devicePath)
{
return !getDetail(path).isEmpty();
return !getDetail(devicePath).isEmpty();
}
bool SoftwareRAID::createSoftwareRAID(Report &report,
@ -437,32 +437,20 @@ bool SoftwareRAID::reassembleSoftwareRAID(Report& report, const QString &deviceN
return stopSoftwareRAID(report, deviceNode) && assembleSoftwareRAID(deviceNode);
}
bool SoftwareRAID::isRaidMember(const QString &path)
QString SoftwareRAID::getRaidArrayName(const QString &partitionPath)
{
QFile mdstat(QStringLiteral("/proc/mdstat"));
ExternalCommand cmd(QStringLiteral("mdadm"),
{ QStringLiteral("--misc"), QStringLiteral("--query"), partitionPath });
if (!mdstat.open(QIODevice::ReadOnly))
return false;
if (cmd.run(-1) && cmd.exitCode() == 0) {
QRegularExpression ex(QStringLiteral("device active raid\\d+\\s([\\/\\w]+)."));
QRegularExpressionMatch match = ex.match(cmd.output());
QTextStream stream(&mdstat);
QString content = stream.readAll();
mdstat.close();
QRegularExpression re(QStringLiteral("(\\w+)\\[\\d+\\]"));
QRegularExpressionMatchIterator i = re.globalMatch(content);
while (i.hasNext()) {
QRegularExpressionMatch reMatch = i.next();
QString match = QStringLiteral("/dev/") + reMatch.captured(1);
if (match == path)
return true;
if (match.hasMatch())
return match.captured(1);
}
return false;
return QString();
}
void SoftwareRAID::initPartitions()

View File

@ -70,7 +70,7 @@ public:
static QString getUUID(const QString& path);
static QStringList getDevicePathList(const QString& path);
static bool isRaidPath(const QString& path);
static bool isRaidPath(const QString& devicePath);
static bool createSoftwareRAID(Report& report,
const QString& name,
@ -87,7 +87,7 @@ public:
static bool reassembleSoftwareRAID(Report& report, const QString& deviceNode);
static bool isRaidMember(const QString& path);
static QString getRaidArrayName(const QString& partitionPath);
protected:
void initPartitions() override;

View File

@ -18,6 +18,7 @@
*************************************************************************/
#include "core/fstab.h"
#include "core/raid/softwareraid.h"
#include "fs/filesystem.h"
#include "fs/lvm2_pv.h"
@ -125,6 +126,8 @@ QString FileSystem::detectMountPoint(FileSystem* fs, const QString& partitionPat
{
if (fs->type() == FileSystem::Type::Lvm2_PV)
return FS::lvm2_pv::getVGName(partitionPath);
else if (fs->type() == FileSystem::Type::LinuxRaidMember)
return SoftwareRAID::getRaidArrayName(partitionPath);
if (partitionPath.isEmpty()) // Happens when during initial scan LUKS is closed
return QString();

View File

@ -125,7 +125,7 @@ bool DeleteOperation::canDelete(const Partition* p)
return false;
}
else if (p->fileSystem().type() == FileSystem::Type::LinuxRaidMember) {
if (SoftwareRAID::isRaidMember(p->partitionPath()))
if (!SoftwareRAID::getRaidArrayName(p->partitionPath()).isEmpty())
return false;
}
else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) {
@ -138,7 +138,7 @@ bool DeleteOperation::canDelete(const Partition* p)
return false;
}
else if (fs->type() == FileSystem::Type::LinuxRaidMember) {
if (SoftwareRAID::isRaidMember(p->partitionPath()))
if (!SoftwareRAID::getRaidArrayName(p->partitionPath()).isEmpty())
return false;
}
}