Commit b1914d5a authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈
Browse files

consider devices invalid (ignore them) that have smart disabled

when SMART is disabled smartctl will exit0 but contain no smart_status
which means default values get used and the device is considered
invalid. since we don't know what the status is in this situation we'll
consider the entire data set invalid and thereby hide the device.

with the growing amount of potentially discarded (but present) data
blobs it might soon make sense to think about rendering invalid devices
in the KCM with an unknown state so people at least can find out that
their drives aren't being monitored

BUG: 435699
FIXED-IN: 5.22.0
parent 6315fa2a
{
"json_format_version": [
1,
0
],
"smartctl": {
"version": [
7,
1
],
"svn_revision": "5022",
"platform_info": "x86_64-linux-5.4.0-70-generic",
"build_info": "(local build)",
"argv": [
"smartctl",
"--all",
"--json",
"/dev/sdb"
],
"exit_status": 0
},
"device": {
"name": "/dev/sdb",
"info_name": "/dev/sdb [SAT]",
"type": "sat",
"protocol": "ATA"
},
"model_family": "Toshiba 2.5\" HDD MQ01ABD...",
"model_name": "TOSHIBA MQ01ABD050",
"serial_number": "-- REDACTED --",
"wwn": {
"naa": 0,
"oui": 0,
"id": 0
},
"firmware_version": "AX001U",
"user_capacity": {
"blocks": 976773168,
"bytes": 500107862016
},
"logical_block_size": 512,
"physical_block_size": 4096,
"rotation_rate": 5400,
"form_factor": {
"ata_value": 3,
"name": "2.5 inches"
},
"in_smartctl_database": true,
"ata_version": {
"string": "ATA8-ACS (minor revision not indicated)",
"major_value": 504,
"minor_value": 0
},
"sata_version": {
"string": "SATA 2.6",
"value": 31
},
"interface_speed": {
"max": {
"sata_value": 6,
"string": "3.0 Gb/s",
"units_per_second": 30,
"bits_per_unit": 100000000
},
"current": {
"sata_value": 2,
"string": "3.0 Gb/s",
"units_per_second": 30,
"bits_per_unit": 100000000
}
},
"local_time": {
"time_t": 1618334939,
"asctime": "Tue Apr 13 19:28:59 2021 CEST"
}
}
SPDX-License-Identifier: CC0-1.0
SPDX-FileCopyrightText: none
......@@ -13,5 +13,6 @@
<file alias='missing-status.json'>./missing-status.json</file>
<file alias='pass.json'>./pass.json</file>
<file alias='invalid-vbox.json'>./invalid-vbox.json</file>
<file alias='pass-without-status.json'>./pass-without-status.json</file>
</qresource>
</RCC>
......@@ -98,6 +98,21 @@ private Q_SLOTS:
QCOMPARE(data.m_smartctl.failure(), SMART::Failures({SMART::Failure::InternalCommand}));
QVERIFY(!data.m_valid);
}
void testNoSmartStatusNoError()
{
// When SMART is disabled we get no smart_status but also no error. Ought to be invalid all the same and
// ignored.
// https://bugs.kde.org/show_bug.cgi?id=435699
QFile file(QFINDTESTDATA("fixtures/pass-without-status.json"));
QVERIFY(file.open(QFile::ReadOnly));
auto doc = QJsonDocument::fromJson(file.readAll());
SMARTData data(doc);
QCOMPARE(data.m_device, "/dev/sdb");
QCOMPARE(data.m_status.m_passed, false);
QCOMPARE(data.m_smartctl.failure(), SMART::Failures());
QVERIFY(!data.m_valid);
}
};
QTEST_MAIN(SMARTDataTest)
......
......@@ -52,5 +52,14 @@ bool SMARTData::checkValid(const QJsonDocument &document) const
qCDebug(KDED) << "Internal command problems resulted in no smart_status data" << m_device << document.toJson();
return false;
}
const bool noFailure = m_smartctl.failure() == SMART::Failures();
if (!hasSMARTStatus && noFailure) {
// When SMART is disabled we may get a blob back but it will lack any information on the SMART status.
// Unfortunately the fact that SMART was disabled (versus not available etc.) isn't codified in the JSON.
// https://bugs.kde.org/show_bug.cgi?id=435699
qCDebug(KDED) << "SMART support is either disabled or not supported on the device" << m_device << document.toJson();
return false;
}
return true;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment