1 Since /sys is unavailable in build environments, the list of available
2 TCP network interfaces cannot be obtained via /sys/class/net. This patch
3 provides alternative code that uses the SIOCGIFCONF ioctl to get the
4 names of the available TCP network interfaces.
6 diff --git a/src/uct/tcp/tcp_iface.c b/src/uct/tcp/tcp_iface.c
7 index 81ad459..10024a6 100644
8 --- a/src/uct/tcp/tcp_iface.c
9 +++ b/src/uct/tcp/tcp_iface.c
12 #include <netinet/tcp.h>
15 +#include <sys/ioctl.h>
17 static ucs_config_field_t uct_tcp_iface_config_table[] = {
18 {"", "MAX_SHORT=8k", NULL,
19 @@ -483,6 +485,70 @@ static UCS_CLASS_DEFINE_NEW_FUNC(uct_tcp_iface_t, uct_iface_t, uct_md_h,
20 uct_worker_h, const uct_iface_params_t*,
21 const uct_iface_config_t*);
23 +/* Fetch information about available network devices through an ioctl. */
24 +static ucs_status_t query_devices_ioctl(uct_md_h md,
25 + uct_tl_resource_desc_t **resource_p,
26 + unsigned *num_resources_p)
29 + uct_tl_resource_desc_t *resources, *tmp;
30 + unsigned num_resources;
31 + ucs_status_t status;
33 + struct ifreq reqs[10];
35 + conf.ifc_len = sizeof reqs;
36 + conf.ifc_req = reqs;
38 + sock = socket(SOCK_STREAM, AF_INET, 0);
40 + ucs_error("socket(2) failed: %m");
41 + status = UCS_ERR_IO_ERROR;
45 + err = ioctl(sock, SIOCGIFCONF, &conf);
47 + ucs_error("SIOCGIFCONF ioctl failed: %m");
48 + status = UCS_ERR_IO_ERROR;
54 + for (i = 0; i < conf.ifc_len / sizeof(struct ifreq); i++) {
55 + const char *name = reqs[i].ifr_name;
57 + if (!ucs_netif_is_active(name)) {
61 + tmp = ucs_realloc(resources, sizeof(*resources) * (num_resources + 1),
64 + ucs_free(resources);
65 + status = UCS_ERR_NO_MEMORY;
70 + ucs_snprintf_zero(resources[i].tl_name, sizeof(resources[i].tl_name),
71 + "%s", UCT_TCP_NAME);
72 + ucs_snprintf_zero(resources[i].dev_name, sizeof(resources[i].dev_name),
74 + resources[i].dev_type = UCT_DEVICE_TYPE_NET;
78 + *num_resources_p = num_resources;
79 + *resource_p = resources;
83 + if (sock >= 0) close(sock);
87 static ucs_status_t uct_tcp_query_tl_resources(uct_md_h md,
88 uct_tl_resource_desc_t **resource_p,
89 unsigned *num_resources_p)
90 @@ -496,9 +562,9 @@ static ucs_status_t uct_tcp_query_tl_resources(uct_md_h md,
92 dir = opendir(netdev_dir);
94 - ucs_error("opendir(%s) failed: %m", netdev_dir);
95 - status = UCS_ERR_IO_ERROR;
97 + /* When /sys is unavailable, as can be the case in a container,
98 + * resort to a good old 'ioctl'. */
99 + return query_devices_ioctl(md, resource_p, num_resources_p);
103 @@ -543,6 +609,5 @@ static ucs_status_t uct_tcp_query_tl_resources(uct_md_h md,