1ff636
From 74b66951fcd54e6ab51023f60cc021fe355be1a8 Mon Sep 17 00:00:00 2001
1ff636
From: Tom Gundersen <teg@jklm.no>
1ff636
Date: Sat, 25 Oct 2014 17:10:11 +0200
1ff636
Subject: [PATCH] udev: net_id - correctly name netdevs based on dev_port when
1ff636
 set
1ff636
1ff636
Upstream, dev_id was replaced by dev_port, and the same happened for some kernel
1ff636
drivers. This logic is not in the RHEL7 kernel, except for one new driver which
1ff636
uses dev_port, but never used dev_id in the past.
1ff636
1ff636
To give proper names to these devices, fall back to using dev_port when dev_id
1ff636
is not set. This does not affect any existing drivers.
1ff636
1ff636
(rhel only)
1ff636
1ff636
Resolves: #1155996
1ff636
1ff636
Conflicts:
1ff636
	src/udev/udev-builtin-net_id.c
1ff636
1ff636
Conflicts:
1ff636
	src/udev/udev-builtin-net_id.c
1ff636
---
1ff636
 src/udev/udev-builtin-net_id.c | 26 ++++++++++++++++----------
1ff636
 1 file changed, 16 insertions(+), 10 deletions(-)
1ff636
1ff636
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
1ff636
index 37ff1b8..99caa0a 100644
1ff636
--- a/src/udev/udev-builtin-net_id.c
1ff636
+++ b/src/udev/udev-builtin-net_id.c
1ff636
@@ -38,7 +38,7 @@
1ff636
  *   o<index>                              -- 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_port>]
1ff636
+ *   [P<domain>]p<bus>s<slot>[f<function>][d<dev_id>/<dev_port>]
1ff636
  *                                         -- PCI geographical location
1ff636
  *   [P<domain>]p<bus>s<slot>[f<function>][u<port>][..][c<config>][i<interface>]
1ff636
  *                                         -- USB port number chain
1ff636
@@ -169,7 +169,7 @@ static bool is_pci_multifunction(struct udev_device *dev) {
1ff636
 
1ff636
 static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
1ff636
         struct udev *udev = udev_device_get_udev(names->pcidev);
1ff636
-        unsigned domain, bus, slot, func, dev_port = 0;
1ff636
+        unsigned domain, bus, slot, func, dev_id = 0;
1ff636
         size_t l;
1ff636
         char *s;
1ff636
         const char *attr;
1ff636
@@ -183,9 +183,15 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
1ff636
                 return -ENOENT;
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
+        attr = udev_device_get_sysattr_value(dev, "dev_id");
1ff636
+        if (attr) {
1ff636
+                dev_id = strtol(attr, NULL, 16);
1ff636
+                if (dev_id == 0) {
1ff636
+                        attr = udev_device_get_sysattr_value(dev, "dev_port");
1ff636
+                        if (attr)
1ff636
+                                dev_id = strtol(attr, NULL, 16);
1ff636
+                }
1ff636
+        }
1ff636
 
1ff636
         /* compose a name based on the raw kernel's PCI bus, slot numbers */
1ff636
         s = names->pci_path;
1ff636
@@ -194,9 +200,9 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
1ff636
                 l = strpcpyf(&s, l, "P%u", domain);
1ff636
         l = strpcpyf(&s, l, "p%us%u", bus, slot);
1ff636
         if (func > 0 || is_pci_multifunction(names->pcidev))
1ff636
-                l = strpcpyf(&s, l, "f%u", func);
1ff636
-        if (dev_port > 0)
1ff636
-                l = strpcpyf(&s, l, "d%u", dev_port);
1ff636
+                l = strpcpyf(&s, l, "f%d", func);
1ff636
+        if (dev_id > 0)
1ff636
+                l = strpcpyf(&s, l, "d%d", dev_id);
1ff636
         if (l == 0)
1ff636
                 names->pci_path[0] = '\0';
1ff636
 
1ff636
@@ -245,8 +251,8 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
1ff636
                 l = strpcpyf(&s, l, "s%d", hotplug_slot);
1ff636
                 if (func > 0 || is_pci_multifunction(names->pcidev))
1ff636
                         l = strpcpyf(&s, l, "f%d", func);
1ff636
-                if (dev_port > 0)
1ff636
-                        l = strpcpyf(&s, l, "d%d", dev_port);
1ff636
+                if (dev_id > 0)
1ff636
+                        l = strpcpyf(&s, l, "d%d", dev_id);
1ff636
                 if (l == 0)
1ff636
                         names->pci_path[0] = '\0';
1ff636
         }