Skip to content

Commit 716275f

Browse files
bgoglinndenoyelle
authored andcommitted
linuxio: ude dev_port in favor of dev_id when available in net device sysfs directories
dev_id is somehow deprecated for exposing the port number. Mostly matters for IB devices. Thanks to Thomas Gruber for the report. Signed-off-by: Brice Goglin <[email protected]>
1 parent fff6140 commit 716275f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

hwloc/topology-linux.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5947,6 +5947,7 @@ hwloc_linuxfs_net_class_fillinfos(int root_fd,
59475947
struct stat st;
59485948
char path[296]; /* osdevpath <= 256 */
59495949
char address[128];
5950+
int err;
59505951
snprintf(path, sizeof(path), "%s/address", osdevpath);
59515952
if (!hwloc_read_path_by_length(path, address, sizeof(address), root_fd)) {
59525953
char *eol = strchr(address, '\n');
@@ -5957,8 +5958,14 @@ hwloc_linuxfs_net_class_fillinfos(int root_fd,
59575958
snprintf(path, sizeof(path), "%s/device/infiniband", osdevpath);
59585959
if (!hwloc_stat(path, &st, root_fd)) {
59595960
char hexid[16];
5960-
snprintf(path, sizeof(path), "%s/dev_id", osdevpath);
5961-
if (!hwloc_read_path_by_length(path, hexid, sizeof(hexid), root_fd)) {
5961+
snprintf(path, sizeof(path), "%s/dev_port", osdevpath);
5962+
err = hwloc_read_path_by_length(path, hexid, sizeof(hexid), root_fd);
5963+
if (err < 0) {
5964+
/* fallback t dev_id for old kernels/drivers */
5965+
snprintf(path, sizeof(path), "%s/dev_id", osdevpath);
5966+
err = hwloc_read_path_by_length(path, hexid, sizeof(hexid), root_fd);
5967+
}
5968+
if (!err) {
59625969
char *eoid;
59635970
unsigned long port;
59645971
port = strtoul(hexid, &eoid, 0);

0 commit comments

Comments
 (0)