Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 66 additions & 50 deletions service/diskoperation/DeviceStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,22 @@
}
}

bool DeviceStorage::getDiskInfoFromHwinfo(const QString &devicePath)

Check warning on line 355 in service/diskoperation/DeviceStorage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getDiskInfoFromHwinfo' is never used.
{
qDebug() << "Getting disk info from hwinfo for device:" << devicePath;
QString cmd = QString("hwinfo --disk --only %1").arg(devicePath);
QString outPut;
QString error;
if (Utils::executCmd(cmd, outPut, error) != 0) {
qDebug() << "Failed to execute hwinfo command, error:" << error;
return false;
if (!m_hwinfoOutputCached) {
QString cmd = QString("hwinfo --disk --only %1").arg(devicePath);
QString error;
if (Utils::executCmd(cmd, m_cachedHwinfoOutput, error) != 0) {
qDebug() << "Failed to execute hwinfo command, error:" << error;
return false;
}
m_hwinfoOutputCached = true;
}

QMap<QString, QString> mapInfo;

getMapInfoFromInput(outPut, mapInfo);
getMapInfoFromInput(m_cachedHwinfoOutput, mapInfo);

setHwinfoInfo(mapInfo);

Expand Down Expand Up @@ -442,17 +444,20 @@
qDebug() << "DeviceStorage::getMapInfoFromInput END";
}

bool DeviceStorage::getDiskInfoFromLshw(const QString &devicePath)

Check warning on line 447 in service/diskoperation/DeviceStorage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getDiskInfoFromLshw' is never used.
{
qDebug() << "DeviceStorage::getDiskInfoFromLshw BEGIN";
QString outPut, error;
if (Utils::executCmd("lshw -C disk", outPut, error) != 0) {
qDebug() << "Failed to execute lshw command, error:" << error;
return false;
if (!m_lshwOutputCached) {
QString error;
if (Utils::executCmd("lshw -C disk", m_cachedLshwOutput, error) != 0) {
qDebug() << "Failed to execute lshw command, error:" << error;
return false;
}
m_lshwOutputCached = true;
}

QString diskInfo;
QStringList list = outPut.split("*-disk");
QStringList list = m_cachedLshwOutput.split("*-disk");
foreach (const QString &item, list) {
QStringList list2 = item.split("*-namespace");
foreach (const QString &item2, list2) {
Expand Down Expand Up @@ -570,27 +575,30 @@
qDebug() << "DeviceStorage::loadLsblkInfo END";
}

bool DeviceStorage::getDiskInfoFromSmartCtl(const QString &devicePath)

Check warning on line 578 in service/diskoperation/DeviceStorage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getDiskInfoFromSmartCtl' is never used.
{
qDebug() << "DeviceStorage::getDiskInfoFromSmartCtl BEGIN";
QString cmd = QString("smartctl --all %1").arg(devicePath);
QString outPut, error;
int exitcode = Utils::executCmd(cmd, outPut, error);
if (!m_smartctlOutputCached) {
QString cmd = QString("smartctl --all %1").arg(devicePath);
QString error;
int exitcode = Utils::executCmd(cmd, m_cachedSmartctlOutput, error);

if (outPut.contains("Please specify device type with the -d option")) {
qDebug() << "need to specify device type";
cmd = QString("smartctl --all -d sat %1").arg(devicePath);
exitcode = Utils::executCmd(cmd, outPut, error);
}
if (m_cachedSmartctlOutput.contains("Please specify device type with the -d option")) {
qDebug() << "need to specify device type";
cmd = QString("smartctl --all -d sat %1").arg(devicePath);
exitcode = Utils::executCmd(cmd, m_cachedSmartctlOutput, error);
}

if (exitcode != 0) {
qDebug() << "Failed to execute smartctl command, error:" << error;
return false;
if (exitcode != 0) {
qDebug() << "Failed to execute smartctl command, error:" << error;
return false;
}
m_smartctlOutputCached = true;
}

QMap<QString, QString> mapInfo;

getMapInfoFromSmartctl(mapInfo, outPut);
getMapInfoFromSmartctl(mapInfo, m_cachedSmartctlOutput);

addInfoFromSmartctl(mapInfo);

Expand All @@ -598,25 +606,28 @@
return true;
}

void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model)

Check warning on line 609 in service/diskoperation/DeviceStorage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getDiskInfoModel' is never used.
{
qDebug() << "DeviceStorage::getDiskInfoModel BEGIN";
QString cmd = QString("smartctl --all %1").arg(devicePath);
QString outPut, error;
int exitcode = Utils::executCmd(cmd, outPut, error);
if (!m_smartctlOutputCached) {
QString cmd = QString("smartctl --all %1").arg(devicePath);
QString error;
int exitcode = Utils::executCmd(cmd, m_cachedSmartctlOutput, error);

if (outPut.contains("Please specify device type with the -d option")) {
qDebug() << "need to specify device type";
cmd = QString("smartctl --all -d sat %1").arg(devicePath);
exitcode = Utils::executCmd(cmd, outPut, error);
}
if (m_cachedSmartctlOutput.contains("Please specify device type with the -d option")) {
qDebug() << "need to specify device type";
cmd = QString("smartctl --all -d sat %1").arg(devicePath);
exitcode = Utils::executCmd(cmd, m_cachedSmartctlOutput, error);
}

if (exitcode != 0) {
qDebug() << "Failed to execute smartctl command, error:" << error;
return;
if (exitcode != 0) {
qDebug() << "Failed to execute smartctl command, error:" << error;
return;
}
m_smartctlOutputCached = true;
}

QStringList infoList = outPut.split("\n");
QStringList infoList = m_cachedSmartctlOutput.split("\n");
for (int i = 0; i < infoList.size(); i++) {
QString info = infoList[i];
if(info.startsWith("Device Model:") || info.startsWith("Product:") || info.startsWith("Model Number:")){
Expand All @@ -626,14 +637,16 @@
}
}

cmd = "lshw -C disk";
exitcode = Utils::executCmd(cmd, outPut, error);
if (exitcode != 0) {
qDebug() << "Failed to execute lshw command, error:" << error;
return;
if (!m_lshwOutputCached) {
QString error;
if (Utils::executCmd("lshw -C disk", m_cachedLshwOutput, error) != 0) {
qDebug() << "Failed to execute lshw command, error:" << error;
return;
}
m_lshwOutputCached = true;
}

infoList = outPut.split("*-disk\n");
infoList = m_cachedLshwOutput.split("*-disk\n");
for (int i =0; i < infoList.size(); i++) {
if(infoList[i].contains(devicePath)) {
qDebug() << "found devicePath in lshw output";
Expand Down Expand Up @@ -759,15 +772,18 @@

if (interface.isEmpty()) {
qDebug() << "interface is empty";
QString cmd = QString("hwinfo --disk --only %1").arg(devicePath);
QString outPut, error;
int exitcode = Utils::executCmd(cmd, outPut, error);
if (exitcode != 0) {
interface = "UnKnow";
qDebug() << "Failed to execute hwinfo command, error:" << error;
return;
if (!m_hwinfoOutputCached) {
QString cmd = QString("hwinfo --disk --only %1").arg(devicePath);
QString error;
int exitcode = Utils::executCmd(cmd, m_cachedHwinfoOutput, error);
if (exitcode != 0) {
interface = "UnKnow";
qDebug() << "Failed to execute hwinfo command, error:" << error;
return;
}
m_hwinfoOutputCached = true;
}
QStringList outPutList = outPut.split("(");
QStringList outPutList = m_cachedHwinfoOutput.split("(");
interface = outPutList[outPutList.size() - 1].split(" ")[0];
}
qDebug() << "DeviceStorage::getDiskInfoInterface END";
Expand Down
7 changes: 7 additions & 0 deletions service/diskoperation/DeviceStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class DeviceStorage

private:
void getMapInfoFromInput(const QString &info, QMap<QString, QString> &mapInfo);
QString m_cachedSmartctlOutput;
QString m_cachedHwinfoOutput;
QString m_cachedLshwOutput;
bool m_smartctlOutputCached = false;
bool m_hwinfoOutputCached = false;
bool m_lshwOutputCached = false;


void getMapInfoFromHwinfo(const QString &info, QMap<QString, QString> &mapInfo, const QString &ch = QString(": "));

Expand Down
Loading