Updating mdadm config file through a application helper.
This commit is contained in:
parent
aaffe54161
commit
8083306d66
|
@ -247,7 +247,7 @@ qint32 SoftwareRAID::getRaidLevel(const QString &path)
|
||||||
QRegularExpression re(QStringLiteral("Raid Level :\\s+\\w+(\\d+)"));
|
QRegularExpression re(QStringLiteral("Raid Level :\\s+\\w+(\\d+)"));
|
||||||
QRegularExpressionMatch reMatch = re.match(output);
|
QRegularExpressionMatch reMatch = re.match(output);
|
||||||
if (reMatch.hasMatch())
|
if (reMatch.hasMatch())
|
||||||
return reMatch.captured(1).toLongLong();
|
return reMatch.captured(1).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -263,10 +263,8 @@ qint64 SoftwareRAID::getChunkSize(const QString &path)
|
||||||
// Look sector size for the first device/partition on the list, as RAID 1 is composed by mirrored devices
|
// Look sector size for the first device/partition on the list, as RAID 1 is composed by mirrored devices
|
||||||
ExternalCommand sectorSize(QStringLiteral("blockdev"), { QStringLiteral("--getss"), device });
|
ExternalCommand sectorSize(QStringLiteral("blockdev"), { QStringLiteral("--getss"), device });
|
||||||
|
|
||||||
if (sectorSize.run(-1) && sectorSize.exitCode() == 0) {
|
if (sectorSize.run(-1) && sectorSize.exitCode() == 0)
|
||||||
int sectors = sectorSize.output().trimmed().toLongLong();
|
return sectorSize.output().trimmed().toLongLong();
|
||||||
return sectors;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -279,7 +277,6 @@ qint64 SoftwareRAID::getChunkSize(const QString &path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 SoftwareRAID::getTotalChunk(const QString &path)
|
qint64 SoftwareRAID::getTotalChunk(const QString &path)
|
||||||
|
@ -382,16 +379,18 @@ bool SoftwareRAID::createSoftwareRAID(Report &report,
|
||||||
const qint32 raidLevel,
|
const qint32 raidLevel,
|
||||||
const qint32 chunkSize)
|
const qint32 chunkSize)
|
||||||
{
|
{
|
||||||
|
QString path = QStringLiteral("/dev/") + name;
|
||||||
|
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << QStringLiteral("--create") << name;
|
args << QStringLiteral("--create") << path;
|
||||||
args << QStringLiteral("--level=") + QString::number(raidLevel);
|
args << QStringLiteral("--level=") + QString::number(raidLevel);
|
||||||
args << QStringLiteral("--chunk=") + QString::number(chunkSize);
|
args << QStringLiteral("--chunk=") + QString::number(chunkSize);
|
||||||
args << QStringLiteral("--raid-devices=") + QString::number(devicePathList.size());
|
args << QStringLiteral("--raid-devices=") + QString::number(devicePathList.size());
|
||||||
|
|
||||||
for (const QString path : qAsConst(devicePathList)) {
|
for (const QString &p : qAsConst(devicePathList)) {
|
||||||
eraseDeviceMDSuperblock(path);
|
eraseDeviceMDSuperblock(p);
|
||||||
|
|
||||||
args << path;
|
args << p;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExternalCommand cmd(report, QStringLiteral("mdadm"), args);
|
ExternalCommand cmd(report, QStringLiteral("mdadm"), args);
|
||||||
|
@ -399,8 +398,9 @@ bool SoftwareRAID::createSoftwareRAID(Report &report,
|
||||||
if (!cmd.run(-1) || cmd.exitCode() != 0)
|
if (!cmd.run(-1) || cmd.exitCode() != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO: Support custom config files.
|
updateConfigurationFile(path);
|
||||||
return updateConfigurationFile(name);
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoftwareRAID::deleteSoftwareRAID(Report &report,
|
bool SoftwareRAID::deleteSoftwareRAID(Report &report,
|
||||||
|
@ -462,6 +462,8 @@ void SoftwareRAID::initPartitions()
|
||||||
|
|
||||||
qint64 SoftwareRAID::mappedSector(const QString &partitionPath, qint64 sector) const
|
qint64 SoftwareRAID::mappedSector(const QString &partitionPath, qint64 sector) const
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(partitionPath);
|
||||||
|
Q_UNUSED(sector);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,24 +475,12 @@ bool SoftwareRAID::eraseDeviceMDSuperblock(const QString &path)
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoftwareRAID::updateConfigurationFile(const QString &deviceName)
|
bool SoftwareRAID::updateConfigurationFile(const QString &path)
|
||||||
{
|
{
|
||||||
// TODO: Don't use QFile, it is not authenticated and will fail without sudo
|
ExternalCommand cmd(QStringLiteral("/usr/") + QStringLiteral(LIBEXECDIRPATH) + QStringLiteral("/kpmcore_mdadmupdateconf"),
|
||||||
QFile config(raidConfigurationFilePath());
|
{ path, raidConfigurationFilePath() });
|
||||||
|
|
||||||
if (!config.open(QIODevice::WriteOnly | QIODevice::Append))
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
||||||
return false;
|
|
||||||
|
|
||||||
QTextStream out(&config);
|
|
||||||
|
|
||||||
QString info = getDeviceInformation(deviceName);
|
|
||||||
|
|
||||||
if (!info.isEmpty())
|
|
||||||
out << info << QLatin1Char('\n');
|
|
||||||
|
|
||||||
config.close();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SoftwareRAID::getDetail(const QString &path)
|
QString SoftwareRAID::getDetail(const QString &path)
|
||||||
|
|
|
@ -103,7 +103,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
static bool eraseDeviceMDSuperblock(const QString& path);
|
static bool eraseDeviceMDSuperblock(const QString& path);
|
||||||
|
|
||||||
static bool updateConfigurationFile(const QString& deviceName);
|
static bool updateConfigurationFile(const QString& path);
|
||||||
|
|
||||||
static QString getDetail(const QString& path);
|
static QString getDetail(const QString& path);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,14 @@ add_executable(kpmcore_externalcommand
|
||||||
util/externalcommandhelper.cpp
|
util/externalcommandhelper.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_executable(kpmcore_mdadmupdateconf
|
||||||
|
util/mdadmupdateconf.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_definitions(
|
||||||
|
-DLIBEXECDIRPATH="${LIBEXEC_INSTALL_DIR}"
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(kpmcore_externalcommand
|
target_link_libraries(kpmcore_externalcommand
|
||||||
qca-qt5
|
qca-qt5
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
|
@ -49,6 +57,7 @@ target_link_libraries(kpmcore_externalcommand
|
||||||
KF5::I18n
|
KF5::I18n
|
||||||
)
|
)
|
||||||
|
|
||||||
|
install(TARGETS kpmcore_mdadmupdateconf DESTINATION ${LIBEXEC_INSTALL_DIR})
|
||||||
install(TARGETS kpmcore_externalcommand DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
|
install(TARGETS kpmcore_externalcommand DESTINATION ${KAUTH_HELPER_INSTALL_DIR})
|
||||||
install( FILES util/org.kde.kpmcore.helperinterface.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d )
|
install( FILES util/org.kde.kpmcore.helperinterface.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d )
|
||||||
install( FILES util/org.kde.kpmcore.applicationinterface.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d )
|
install( FILES util/org.kde.kpmcore.applicationinterface.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d )
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#ifndef KPMCORE_EXTERNALCOMMAND_WHITELIST_H
|
#ifndef KPMCORE_EXTERNALCOMMAND_WHITELIST_H
|
||||||
#define KPMCORE_EXTERNALCOMMAND_WHITELIST_H
|
#define KPMCORE_EXTERNALCOMMAND_WHITELIST_H
|
||||||
|
|
||||||
QString allowedCommands[] = {
|
const QString allowedCommands[] = {
|
||||||
// TODO try to remove these later
|
// TODO try to remove these later
|
||||||
QStringLiteral("mv"),
|
QStringLiteral("mv"),
|
||||||
QStringLiteral("dd"),
|
QStringLiteral("dd"),
|
||||||
|
@ -101,7 +101,8 @@ QStringLiteral("xfs_repair"),
|
||||||
QStringLiteral("mkfs.xfs"),
|
QStringLiteral("mkfs.xfs"),
|
||||||
QStringLiteral("xfs_copy"),
|
QStringLiteral("xfs_copy"),
|
||||||
QStringLiteral("xfs_growfs"),
|
QStringLiteral("xfs_growfs"),
|
||||||
QStringLiteral("zpool")
|
QStringLiteral("zpool"),
|
||||||
|
QStringLiteral("kpmcore_mdadmupdateconf")
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc != 3)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
char command[] = "mdadm --detail --scan ";
|
||||||
|
|
||||||
|
strcat(command, argv[1]);
|
||||||
|
|
||||||
|
strcat(command, " >> ");
|
||||||
|
|
||||||
|
strcat(command, argv[2]);
|
||||||
|
|
||||||
|
system(command);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue