memory: match DIMM ID even more precisely
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/53791 attemps to fix the
common error #12 in memory resource. However, it's still not perfect.
There is an edge case that Partition objects have wrong paths like
/xyz/openbmc_project/Inventory/Item/dimm1, where this partition
will still be parsed as a partition of dimm1.
This commit corrects this by making path checking explicitly different
for DIMM and Partition objects: one check filename, the other check
filename of the parent path.
Tested:
1. /redfish/v1/Systems/system/Memory/dimm0
```
{
"@odata.id": "/redfish/v1/Systems/system/Memory/dimm0",
"@odata.type": "#Memory.v1_11_0.Memory",
"AllowedSpeedsMHz": [],
"BaseModuleType": "RDIMM",
"BusWidthBits": 0,
"CapacityMiB": 1024,
"DataWidthBits": 0,
"ErrorCorrection": "NoECC",
"FirmwareRevision": "0",
"Id": "dimm0",
"Name": "DIMM Slot",
"OperatingSpeedMhz": 0,
"RankCount": 0,
"Regions": [
{
"MemoryClassification": "Volatile",
"OffsetMiB": 0,
"PassphraseEnabled": false,
"RegionId": "",
"SizeMiB": 1024
},
{
"MemoryClassification": "Volatile",
"OffsetMiB": 0,
"PassphraseEnabled": false,
"RegionId": "",
"SizeMiB": 1024
}
],
"Status": {
"Health": "OK",
"HealthRollup": "OK",
"State": "Enabled"
}
}
```
2. No validator errors on Memory Resource.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: Ic078b5046ac3397e398f050ed7b54ebadcb2aa32
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index 209fa1b..8996082 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -816,15 +816,6 @@
"xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition");
}
-inline bool pathContainsDimmId(const std::string& path, std::string_view dimmId)
-{
- sdbusplus::message::object_path objectPath(path);
- // for /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1 or
- // /xyz/openbmc_project/Inventory/Item/Dimm1
- return !dimmId.empty() && (objectPath.filename() == dimmId ||
- objectPath.parent_path().filename() == dimmId);
-}
-
inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> aResp,
const std::string& dimmId)
{
@@ -841,31 +832,31 @@
return;
}
bool found = false;
- for (const auto& [path, object] : subtree)
+ for (const auto& [rawPath, object] : subtree)
{
- if (pathContainsDimmId(path, dimmId))
+ sdbusplus::message::object_path path(rawPath);
+ for (const auto& [service, interfaces] : object)
{
- for (const auto& [service, interfaces] : object)
+ for (const auto& interface : interfaces)
{
- for (const auto& interface : interfaces)
+ if (interface ==
+ "xyz.openbmc_project.Inventory.Item.Dimm" &&
+ path.filename() == dimmId)
{
- if (interface ==
- "xyz.openbmc_project.Inventory.Item.Dimm")
- {
- getDimmDataByService(aResp, dimmId, service, path);
- found = true;
- }
+ getDimmDataByService(aResp, dimmId, service, rawPath);
+ found = true;
+ }
- // partitions are separate as there can be multiple
- // per
- // device, i.e.
- // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
- // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
- if (interface ==
- "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition")
- {
- getDimmPartitionData(aResp, service, path);
- }
+ // partitions are separate as there can be multiple
+ // per
+ // device, i.e.
+ // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition1
+ // /xyz/openbmc_project/Inventory/Item/Dimm1/Partition2
+ if (interface ==
+ "xyz.openbmc_project.Inventory.Item.PersistentMemory.Partition" &&
+ path.parent_path().filename() == dimmId)
+ {
+ getDimmPartitionData(aResp, service, rawPath);
}
}
}