]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: drop old kernels (<4.20) support
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Apr 2025 20:15:45 +0000 (05:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Apr 2025 18:40:14 +0000 (03:40 +0900)
Since kernel v4.20, specifically since
https://github.com/torvalds/linux/commit/9b8b2a323008aedd39a8debb861b825707f01420
IP-over-Infiniband driver also uses dev_port.

As our baseline on the kernel is v5.4. Let's remove the fallback code.
For more details about the fallback, see
https://github.com/systemd/systemd/pull/10082#issuecomment-421416461

src/udev/udev-builtin-net_id.c

index a86ff1d18d92c90a812e28d6900ad95aee69311e..eaef7d56b2d82650d54284c12061678504a9d8bf 100644 (file)
@@ -168,47 +168,7 @@ static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, cha
         return -ENOENT;
 }
 
-static int get_dev_port(sd_device *dev, bool fallback_to_dev_id, unsigned *ret) {
-        unsigned v;
-        int r;
-
-        assert(dev);
-        assert(ret);
-
-        /* Get kernel provided port index for the case when multiple ports on a single PCI function. */
-
-        r = device_get_sysattr_unsigned_filtered(dev, "dev_port", &v);
-        if (r < 0)
-                return r;
-        if (r > 0) {
-                /* Found a positive index. Let's use it. */
-                *ret = v;
-                return 1; /* positive */
-        }
-        assert(v == 0);
-
-        /* With older kernels IP-over-InfiniBand network interfaces sometimes erroneously provide the port
-         * number in the 'dev_id' sysfs attribute instead of 'dev_port', which thus stays initialized as 0. */
-
-        if (fallback_to_dev_id) {
-                unsigned iftype;
-
-                r = device_get_sysattr_unsigned_filtered(dev, "type", &iftype);
-                if (r < 0)
-                        return r;
-
-                fallback_to_dev_id = (iftype == ARPHRD_INFINIBAND);
-        }
-
-        if (fallback_to_dev_id)
-                return device_get_sysattr_unsigned_filtered(dev, "dev_id", ret);
-
-        /* Otherwise, return the original index 0. */
-        *ret = 0;
-        return 0; /* zero */
-}
-
-static int get_port_specifier(sd_device *dev, bool fallback_to_dev_id, char **ret) {
+static int get_port_specifier(sd_device *dev, char **ret) {
         const char *phys_port_name;
         unsigned dev_port;
         char *buf;
@@ -247,7 +207,7 @@ static int get_port_specifier(sd_device *dev, bool fallback_to_dev_id, char **re
 
         /* Then, try to use the kernel provided port index for the case when multiple ports on a single PCI
          * function. */
-        r = get_dev_port(dev, fallback_to_dev_id, &dev_port);
+        r = device_get_sysattr_unsigned_filtered(dev, "dev_port", &dev_port);
         if (r < 0)
                 return log_device_debug_errno(dev, r, "Failed to get device port index: %m");
         if (r > 0) {
@@ -313,7 +273,7 @@ static int names_pci_onboard(UdevEvent *event, sd_device *pci_dev, const char *p
         if (r < 0)
                 return r;
 
-        r = get_port_specifier(dev, /* fallback_to_dev_id = */ false, &port);
+        r = get_port_specifier(dev, &port);
         if (r < 0)
                 return r;
 
@@ -689,7 +649,7 @@ static int names_pci_slot(UdevEvent *event, sd_device *pci_dev, const char *pref
         if (r < 0)
                 return r;
 
-        r = get_port_specifier(dev, /* fallback_to_dev_id = */ true, &port);
+        r = get_port_specifier(dev, &port);
         if (r < 0)
                 return r;