Skip to content

Commit 6aaa2fa

Browse files
committed
linux: bring back OS dev discovery support for old sysfs
/sys/class/<class>/<name> isn't a symlink containing the PCI bus, it's a directory. Use /sys/class/<class>/<name>/device instead. Thanks to Mikhail Khalilov for reporting the issue (on a 2.6.18-238.19.1.el5 kernel). Signed-off-by: Brice Goglin <[email protected]>
1 parent 4724b29 commit 6aaa2fa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

hwloc/topology-linux.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,8 +4550,16 @@ hwloc_linuxfs_find_osdev_parent(struct hwloc_backend *backend, int root_fd,
45504550
int err;
45514551

45524552
err = hwloc_readlink(osdevpath, path, sizeof(path), root_fd);
4553-
if (err < 0)
4554-
return NULL;
4553+
if (err < 0) {
4554+
/* /sys/class/<class>/<name> is a directory instead of a symlink on old kernels (at least around 2.6.18 and 2.6.25).
4555+
* The link to parse can be found in /sys/class/<class>/<name>/device instead, at least for "/pci..."
4556+
*/
4557+
char olddevpath[256];
4558+
snprintf(olddevpath, sizeof(olddevpath), "%s/device", osdevpath);
4559+
err = hwloc_readlink(olddevpath, path, sizeof(path), root_fd);
4560+
if (err < 0)
4561+
return NULL;
4562+
}
45554563
path[err] = '\0';
45564564

45574565
if (!allowvirtual) {

0 commit comments

Comments
 (0)