]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: use FOREACH_DEVICE_CHILD_WITH_SUFFIX() macro 24757/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Sep 2022 04:13:02 +0000 (13:13 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 22 Sep 2022 22:03:19 +0000 (07:03 +0900)
src/network/networkd-sriov.c

index 26757b996c964998571c1b70cded7b33c5f9f766..77ada236025a16d05e64d0458584b4a37b3dc99c 100644 (file)
@@ -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")))
-                        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;