daandemeyer / rpms / systemd

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