diff --git a/src/network/networkd-sriov.c b/src/network/networkd-sriov.c index 26757b996c..77ada23602 100644 --- a/src/network/networkd-sriov.c +++ b/src/network/networkd-sriov.c @@ -2,7 +2,7 @@ * Copyright © 2020 VMware, Inc. */ #include "device-enumerator-private.h" -#include "dirent-util.h" +#include "device-util.h" #include "fd-util.h" #include "networkd-link.h" #include "networkd-manager.h" @@ -229,9 +229,8 @@ static int link_set_sr_iov_phys_port(Link *link) { } static int link_set_sr_iov_virt_ports(Link *link) { - const char *dev_port, *pci_syspath; - _cleanup_closedir_ DIR *dir = NULL; - sd_device *pci_dev; + const char *dev_port, *name; + sd_device *pci_dev, *child; int r; assert(link); @@ -250,28 +249,15 @@ static int link_set_sr_iov_virt_ports(Link *link) { if (r < 0) return r; - r = sd_device_get_syspath(pci_dev, &pci_syspath); - if (r < 0) - return r; - - dir = opendir(pci_syspath); - if (!dir) - return -errno; - - FOREACH_DIRENT_ALL(de, dir, break) { - _cleanup_(sd_device_unrefp) sd_device *pci_virtfn_dev = NULL; - - if (de->d_type != DT_LNK) - continue; + FOREACH_DEVICE_CHILD_WITH_SUFFIX(pci_dev, child, name) { + const char *n; /* Accept name prefixed with "virtfn", but refuse "virtfn" itself. */ - if (isempty(startswith(de->d_name, "virtfn"))) + n = startswith(name, "virtfn"); + if (isempty(n) || !in_charset(n, DIGITS)) continue; - if (sd_device_new_child(&pci_virtfn_dev, pci_dev, de->d_name) < 0) - continue; - - r = find_ifindex_from_pci_dev_port(pci_virtfn_dev, dev_port); + r = find_ifindex_from_pci_dev_port(child, dev_port); if (r < 0) continue;