lsvpd/lsvpd-d6f0fad940ca5873d240f8d74529ea36cc20ed3d.patch
Than Ngo 01c6952697 - rebase to 1.7.12
- add support for SCSI loc-code
- Fix catching polymorphic type by value
2021-09-03 14:48:27 +02:00

68 lines
2.3 KiB
Diff

commit d6f0fad940ca5873d240f8d74529ea36cc20ed3d
Author: Kamalesh Babulal <kamalesh@linux.ibm.com>
Date: Mon May 31 15:47:00 2021 +0530
sysfstreecollector: use of_node file to device-tree path
In getDevTreePath(), currently we read the devspec in the sysfs path of
the device to retrive the path represented in /proc/device-tree, some
modern device do not construct devspec file, instead relay on of_node
file, which is a symlink to a file in the device-tree.
Teach getDevTreePath() to check for of_node file, and read the symbolic
link it points too and in case of of_node not available, fall back to
Signed-off-by: Kamalesh Babulal <kamalesh@linux.ibm.com>
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
diff --git a/src/internal/sys_interface/sysfstreecollector.cpp b/src/internal/sys_interface/sysfstreecollector.cpp
index 7e7e13c..f0be417 100644
--- a/src/internal/sys_interface/sysfstreecollector.cpp
+++ b/src/internal/sys_interface/sysfstreecollector.cpp
@@ -957,15 +957,43 @@ esc_subsystem_info:
*/
string SysFSTreeCollector::getDevTreePath(string sysPath)
{
+ string sysFsPath, procDtPath, firmwareDtBase;
struct stat astats;
const char *buf;
char buf2[512];
FILE *fi;
HelperFunctions::fs_fixPath(sysPath);
- sysPath += "/devspec";
+ sysFsPath = sysPath + "/devspec";
+ procDtPath = sysPath + "/of_node";
+ firmwareDtBase = "/sys/firmware/devicetree/base";
- buf = sysPath.c_str();
+ /*
+ * Check for existence of of_node symlink and return the path it
+ * points to. devspec is obsolete now, most of the devices
+ * populate of_node and devspec too. Prefer of_node over
+ * devspec, where it exist and fall back to older logic, in case
+ * of of_node not populated.
+ */
+ buf = procDtPath.c_str();
+ if ((lstat(buf, &astats)) == 0) {
+ // of_node is symlink, follow the link
+ realpath( buf, buf2 );
+ if ( buf2 == NULL ) {
+ return string ("");
+ }
+
+ /*
+ * Trim the leading "/sys/firmware/devicetree/base" from the real
+ * path to match the assumption from devspec format, while used
+ * with /proc/devicetree.
+ */
+ procDtPath = string(buf2);
+ procDtPath.replace(0, firmwareDtBase.length(), "");
+ return procDtPath;
+ }
+
+ buf = sysFsPath.c_str();
if ((lstat(buf, &astats)) != 0) {
return string("");
}