Support NVMe behind USB bridges.

This commit is contained in:
Alexander Shaduri
2024-05-31 12:50:03 +04:00
parent afd6ce0a1f
commit 25f1c62d2c
4 changed files with 55 additions and 1 deletions
+15
View File
@@ -213,6 +213,21 @@ hz::ExpectedVoid<SmartctlParserError> SmartctlJsonAtaParser::parse_section_info(
}
},
{"device/protocol", _("Smartctl Device Protocol"), // NVMe, ...
[](const nlohmann::json& root_node, const std::string& key, const std::string& displayable_name)
-> hz::ExpectedValue<StorageProperty, SmartctlParserError>
{
if (auto jval = get_node_data<std::string>(root_node, "device/protocol"); jval.has_value()) {
StorageProperty p;
p.set_name(key, key, displayable_name);
p.value = jval.value();
p.show_in_ui = false;
return p;
}
return hz::Unexpected(SmartctlParserError::KeyNotFound, std::format("Error getting key {} from JSON data.", key));
}
},
{"model_family", _("Model Family"), string_formatter()},
{"model_name", _("Device Model"), string_formatter()},
{"serial_number", _("Serial Number"), string_formatter()},
+15
View File
@@ -90,6 +90,21 @@ hz::ExpectedVoid<SmartctlParserError> SmartctlJsonBasicParser::parse_section_bas
}
},
{"device/protocol", _("Smartctl Device Protocol"), // NVMe, ...
[](const nlohmann::json& root_node, const std::string& key, const std::string& displayable_name)
-> hz::ExpectedValue<StorageProperty, SmartctlParserError>
{
if (auto jval = get_node_data<std::string>(root_node, "device/protocol"); jval.has_value()) {
StorageProperty p;
p.set_name(key, key, displayable_name);
p.value = jval.value();
p.show_in_ui = false;
return p;
}
return hz::Unexpected(SmartctlParserError::KeyNotFound, std::format("Error getting key {} from JSON data.", key));
}
},
{"vendor", _("Vendor"), string_formatter()}, // Flash drive
{"scsi_vendor", _("Vendor"), string_formatter()}, // Flash drive
+15
View File
@@ -129,6 +129,21 @@ hz::ExpectedVoid<SmartctlParserError> SmartctlJsonNvmeParser::parse_section_info
}
},
{"device/protocol", _("Smartctl Device Protocol"), // NVMe, ...
[](const nlohmann::json& root_node, const std::string& key, const std::string& displayable_name)
-> hz::ExpectedValue<StorageProperty, SmartctlParserError>
{
if (auto jval = get_node_data<std::string>(root_node, "device/protocol"); jval.has_value()) {
StorageProperty p;
p.set_name(key, key, displayable_name);
p.value = jval.value();
p.show_in_ui = false;
return p;
}
return hz::Unexpected(SmartctlParserError::KeyNotFound, std::format("Error getting key {} from JSON data.", key));
}
},
{"model_name", _("Device Model"), string_formatter()},
{"serial_number", _("Serial Number"), string_formatter()},
{"firmware_version", _("Firmware Version"), string_formatter()},
+10 -1
View File
@@ -597,6 +597,11 @@ void StorageDevice::detect_drive_type_from_properties(const StoragePropertyRepos
// Note: USB flash drives in non-scsi mode do not have this property.
const auto& smartctl_type = device_type_prop.get_value<std::string>();
std::string lowercase_protocol;
if (auto device_protocol_prop = property_repo.lookup_property("device/protocol"); !device_protocol_prop.empty()) {
lowercase_protocol = hz::string_to_lower_copy(device_protocol_prop.get_value<std::string>());
}
if (smartctl_type == "scsi") { // USB flash in scsi mode, optical, scsi, etc.
if (BuildEnv::is_kernel_linux() && get_device_base().starts_with("sr")) {
set_detected_type(StorageDeviceDetectedType::CdDvd);
@@ -616,9 +621,13 @@ void StorageDevice::detect_drive_type_from_properties(const StoragePropertyRepos
} else if (smartctl_type == "nvme") { // NVMe SSD
set_detected_type(StorageDeviceDetectedType::Nvme);
// Try protocol (type may be a USB bridge name)
} else if (lowercase_protocol == "nvme") { // nvme behind USB bridge like "sntrealtek"
set_detected_type(StorageDeviceDetectedType::Nvme);
} else {
// TODO Detect unsupported RAID
debug_out_warn("app", "Unsupported type " << smartctl_type << " reported by smartctl for " << get_device_with_type() << "\n");
debug_out_warn("app", "Unsupported type " << smartctl_type << " (protocol: " << lowercase_protocol << ") reported by smartctl for " << get_device_with_type() << "\n");
}
}