Since /sys is unavailable in build environments, the list of available TCP network interfaces cannot be obtained via /sys/class/net. This patch provides alternative code that uses the SIOCGIFCONF ioctl to get the names of the available TCP network interfaces. diff --git a/src/uct/tcp/tcp_iface.c b/src/uct/tcp/tcp_iface.c index cad4a2709..7c1d2c9de 100644 --- a/src/uct/tcp/tcp_iface.c +++ b/src/uct/tcp/tcp_iface.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include extern ucs_class_t UCS_CLASS_DECL_NAME(uct_tcp_iface_t); @@ -586,6 +588,68 @@ static UCS_CLASS_DEFINE_NEW_FUNC(uct_tcp_iface_t, uct_iface_t, uct_md_h, uct_worker_h, const uct_iface_params_t*, const uct_iface_config_t*); +/* Fetch information about available network devices through an ioctl. */ +static ucs_status_t query_devices_ioctl(uct_md_h md, + uct_tl_device_resource_t **tl_devices_p, + unsigned *num_tl_devices_p) +{ + int sock, err, i; + uct_tl_device_resource_t *resources, *tmp; + unsigned num_resources; + ucs_status_t status; + struct ifconf conf; + struct ifreq reqs[10]; + + conf.ifc_len = sizeof reqs; + conf.ifc_req = reqs; + + sock = socket(SOCK_STREAM, AF_INET, 0); + if (sock < 0) { + ucs_error("socket(2) failed: %m"); + status = UCS_ERR_IO_ERROR; + goto out; + } + + err = ioctl(sock, SIOCGIFCONF, &conf); + if (err < 0) { + ucs_error("SIOCGIFCONF ioctl failed: %m"); + status = UCS_ERR_IO_ERROR; + goto out; + } + + resources = NULL; + num_resources = 0; + for (i = 0; i < conf.ifc_len / sizeof(struct ifreq); i++) { + const char *name = reqs[i].ifr_name; + + if (!ucs_netif_is_active(name)) { + continue; + } + + tmp = ucs_realloc(resources, sizeof(*resources) * (num_resources + 1), + "tcp resources"); + if (tmp == NULL) { + ucs_free(resources); + status = UCS_ERR_NO_MEMORY; + goto out; + } + resources = tmp; + + ucs_snprintf_zero(resources[i].name, sizeof(resources[i].name), + "%s", name); + resources[i].type = UCT_DEVICE_TYPE_NET; + ++num_resources; + } + + *num_tl_devices_p = num_resources; + *tl_devices_p = resources; + status = UCS_OK; + +out: + if (sock >= 0) close(sock); + return status; +} + ucs_status_t uct_tcp_query_devices(uct_md_h md, uct_tl_device_resource_t **devices_p, unsigned *num_devices_p) @@ -599,9 +663,9 @@ ucs_status_t uct_tcp_query_devices(uct_md_h md, dir = opendir(netdev_dir); if (dir == NULL) { - ucs_error("opendir(%s) failed: %m", netdev_dir); - status = UCS_ERR_IO_ERROR; - goto out; + /* When /sys is unavailable, as can be the case in a container, + * resort to a good old 'ioctl'. */ + return query_devices_ioctl(md, devices_p, num_devices_p); } devices = NULL; @@ -655,7 +719,6 @@ ucs_status_t uct_tcp_query_devices(uct_md_h md, out_closedir: closedir(dir); -out: return status; } rialization test case. * gnu/services/configuration.scm (empty-serializer?): New predicate. (base-transducer, tfilter-maybe-value): New procedure. (serialize-configuration): Adapt to use base-transducer. * gnu/services/telephony.scm (jami-account->alist): Use transducers to skip fields that are unserializable or whose field maybe-value is unset. * tests/services/configuration.scm: Remove test-expect-fail. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com> Bruno Victal 2023-04-02services: replace bare serializers with (serializer ...)...* gnu/home/services/shells.scm (home-zsh-configuration)[environment-variables]: Use (serializer ...). (home-bash-configuration)[aliases, environment-variables]: Likewise. (home-fish-configuration)[abbreviations, aliases] [environment-variables]: Likewise. * gnu/services/audio.scm (mpd-configuration)[music-dir, playlist-dir] [endpoints, address, inputs, archive-plugins, input-cache-size] [decoders, filters, playlist-plugins]: Likewise. * gnu/services/linux.scm (fstrim-configuration)[extra-arguments]: Likewise. * gnu/services/security.scm (fail2ban-jail-configuration)[backend] [log-encoding, extra-content]: Likewise. * tests/services/configuration.scm: Update tests. ("serialize-configuration [deprecated]"): New test. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Bruno Victal 2023-04-02services: configuration: Add user-defined sanitizer support....This changes the 'custom-serializer' field into a generic 'extra-args' field that can be extended to support new literals. Within extra-args, the literals 'sanitizer' and 'serializer' allow for user-defined sanitization and serialization procedures respectively. The 'empty-serializer' was also added as a literal to be used as before. To prevent confusion between the new “explicit” style of specifying a sanitizer, and the old “implicit” style, the latter has been deprecated, and a warning is issued if it is encountered. * gnu/services/configuration.scm (define-configuration-helper): Rename 'custom-serializer' to 'extra-args'. Add support for literals 'sanitizer', 'serializer' and 'empty-serializer'. Rename procedure 'field-sanitizer' to 'default-field-sanitizer' to avoid syntax clash. Only define default field sanitizers if user-defined ones are absent. (normalize-extra-args): New variable. (<configuration-field>)[sanitizer]: New field. * doc/guix.texi (Complex Configurations): Document the newly added literals. * tests/services/configuration.scm: Add tests for the new literals. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Bruno Victal