dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
803fb7
From 88eb414beca3ab29f40a6e422faa790ddaae2918 Mon Sep 17 00:00:00 2001
803fb7
From: Tom Gundersen <teg@jklm.no>
803fb7
Date: Wed, 1 Apr 2015 16:51:02 +0200
803fb7
Subject: [PATCH] udev: net_id - support multi-port enpo* device names
803fb7
803fb7
I'd argue that having firmware labels for such devices makes
803fb7
no sense, but they exist, so make sure we handle them as best
803fb7
as we can.
803fb7
---
803fb7
 src/udev/udev-builtin-net_id.c | 33 +++++++++++++++++++++++++--------
803fb7
 1 file changed, 25 insertions(+), 8 deletions(-)
803fb7
803fb7
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
803fb7
index 99caa0a2a..6a5ada688 100644
803fb7
--- a/src/udev/udev-builtin-net_id.c
803fb7
+++ b/src/udev/udev-builtin-net_id.c
803fb7
@@ -35,7 +35,7 @@
803fb7
  * Type of names:
803fb7
  *   b<number>                             -- BCMA bus core number
803fb7
  *   ccw<name>                             -- CCW bus group name
803fb7
- *   o<index>                              -- on-board device index number
803fb7
+ *   o<index>[d<dev_port>]                 -- on-board device index number
803fb7
  *   s<slot>[f<function>][d<dev_port>]     -- hotplug slot index number
803fb7
  *   x<MAC>                                -- MAC address
803fb7
  *   [P<domain>]p<bus>s<slot>[f<function>][d<dev_id>/<dev_port>]
803fb7
@@ -128,22 +128,39 @@ struct netnames {
803fb7
 
803fb7
 /* retrieve on-board index number and label from firmware */
803fb7
 static int dev_pci_onboard(struct udev_device *dev, struct netnames *names) {
803fb7
-        const char *index;
803fb7
+        unsigned dev_port = 0;
803fb7
+        size_t l;
803fb7
+        char *s;
803fb7
+        const char *attr;
803fb7
         int idx;
803fb7
 
803fb7
         /* ACPI _DSM  -- device specific method for naming a PCI or PCI Express device */
803fb7
-        index = udev_device_get_sysattr_value(names->pcidev, "acpi_index");
803fb7
+        attr = udev_device_get_sysattr_value(names->pcidev, "acpi_index");
803fb7
         /* SMBIOS type 41 -- Onboard Devices Extended Information */
803fb7
-        if (!index)
803fb7
-                index = udev_device_get_sysattr_value(names->pcidev, "index");
803fb7
-        if (!index)
803fb7
+        if (!attr)
803fb7
+                attr = udev_device_get_sysattr_value(names->pcidev, "index");
803fb7
+        if (!attr)
803fb7
                 return -ENOENT;
803fb7
-        idx = strtoul(index, NULL, 0);
803fb7
+
803fb7
+        idx = strtoul(attr, NULL, 0);
803fb7
         if (idx <= 0)
803fb7
                 return -EINVAL;
803fb7
-        snprintf(names->pci_onboard, sizeof(names->pci_onboard), "o%d", idx);
803fb7
+
803fb7
+        /* kernel provided multi-device index */
803fb7
+        attr = udev_device_get_sysattr_value(dev, "dev_port");
803fb7
+        if (attr)
803fb7
+                dev_port = strtol(attr, NULL, 10);
803fb7
+
803fb7
+        s = names->pci_onboard;
803fb7
+        l = sizeof(names->pci_onboard);
803fb7
+        l = strpcpyf(&s, l, "o%d", idx);
803fb7
+        if (dev_port > 0)
803fb7
+                l = strpcpyf(&s, l, "d%d", dev_port);
803fb7
+        if (l == 0)
803fb7
+                names->pci_onboard[0] = '\0';
803fb7
 
803fb7
         names->pci_onboard_label = udev_device_get_sysattr_value(names->pcidev, "label");
803fb7
+
803fb7
         return 0;
803fb7
 }
803fb7