* 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"
}
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);
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")))
- continue;
-
- if (sd_device_new_child(&pci_virtfn_dev, pci_dev, de->d_name) < 0)
+ n = startswith(name, "virtfn");
+ if (isempty(n) || !in_charset(n, DIGITS))
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;