Blame SOURCES/0001-Fix-regression-introduced-by-the-addslot-function.patch

247641
From 783de6c93b01fec3f3cb8682156a21417567db9f Mon Sep 17 00:00:00 2001
247641
From: Narendra K <narendra_k@dell.com>
247641
Date: Wed, 4 Sep 2013 20:32:14 +0530
247641
Subject: [PATCH] Fix regression introduced by the addslot function
247641
247641
This patch reverts the following commits
247641
247641
1452ea7125b5e713b80459f7b528d5562438f3d5
247641
0bb870f09a34b6c505fcefdbcf85cfcc1aa5ca97
247641
247641
The commits introduced addslot function to implement naming for
247641
devices which have more than one physical port sharing the same
247641
PCI b/d/f. But the port determination logic in 'addslot' function
247641
could
247641
result in more than one interface on a given PCI slot getting same
247641
port number when renames are happening in parallel. This patch
247641
restores the logic that existed in version 0.3.11 to determine
247641
port number of an interface.
247641
247641
Fixes Fedora bz-782145.
247641
---
247641
 src/bios_device.c   | 59 ------------------------------------
247641
 src/bios_device.h   |  3 --
247641
 src/naming_policy.c |  6 ++--
247641
 src/pci.c           | 86 ++++++++++++++++++++++++++++++-----------------------
247641
 4 files changed, 50 insertions(+), 104 deletions(-)
247641
247641
diff --git a/src/bios_device.c b/src/bios_device.c
247641
index a8827ec..132877e 100644
247641
--- a/src/bios_device.c
247641
+++ b/src/bios_device.c
247641
@@ -217,32 +217,6 @@ static void match_pci_and_eth_devs(struct libbiosdevname_state *state)
247641
 	struct pci_device *p;
247641
 	struct bios_device *b;
247641
 	struct network_device *n;
247641
-
247641
-	list_for_each_entry(n, &state->network_devices, node) {
247641
-		p = find_dev_by_pci_name(state, n->drvinfo.bus_info);
247641
-		if (!p)
247641
-			continue;
247641
-
247641
-		b = malloc(sizeof(*b));
247641
-		if (!b)
247641
-			continue;
247641
-		memset(b, 0, sizeof(*b));
247641
-		INIT_LIST_HEAD(&b->node);
247641
-		b->pcidev = p;
247641
-		b->netdev = n;
247641
-		b->slot_num = -1;
247641
-		b->port_num = -1;
247641
-		claim_netdev(b->netdev);
247641
-		list_add(&b->node, &state->bios_devices);
247641
-	}
247641
-}
247641
-
247641
-
247641
-static void match_eth_and_pci_devs(struct libbiosdevname_state *state)
247641
-{
247641
-	struct pci_device *p;
247641
-	struct bios_device *b;
247641
-	struct network_device *n;
247641
 	char pci_name[40];
247641
 
247641
 	list_for_each_entry(p, &state->pci_devices, node) {
247641
@@ -261,8 +235,6 @@ static void match_eth_and_pci_devs(struct libbiosdevname_state *state)
247641
 		INIT_LIST_HEAD(&b->node);
247641
 		b->pcidev = p;
247641
 		b->netdev = n;
247641
-		b->slot_num = -1;
247641
-		b->port_num = -1;
247641
 		claim_netdev(b->netdev);
247641
 		list_add(&b->node, &state->bios_devices);
247641
 	}
247641
@@ -286,8 +258,6 @@ static void match_unknown_eths(struct libbiosdevname_state *state)
247641
 		memset(b, 0, sizeof(*b));
247641
 		INIT_LIST_HEAD(&b->node);
247641
 		b->netdev = n;
247641
-		b->slot_num = -1;
247641
-		b->port_num = -1;
247641
 		list_add(&b->node, &state->bios_devices);
247641
 	}
247641
 }
247641
@@ -355,32 +325,6 @@ static void find_duplicates(struct libbiosdevname_state *state)
247641
 	}
247641
 }
247641
 
247641
-extern int addslot(struct libbiosdevname_state *state, int slot);
247641
-
247641
-/* Fix for RHBZ 816536/757743/756164/: Cards with same PCI but multiple ports
247641
- * chelsio, mellanox */
247641
-static int check_ports(struct libbiosdevname_state *state)
247641
-{
247641
-	struct pci_device *dev;
247641
-	struct bios_device *a;
247641
-        int slot = 0;
247641
-
247641
-	list_for_each_entry(a, &state->bios_devices, node) {
247641
-		dev = a->pcidev;
247641
-		if (dev == NULL || dev->is_sriov_virtual_function || dev->vpd_port != INT_MAX)
247641
-			continue;
247641
-		if (dev->physical_slot != PHYSICAL_SLOT_UNKNOWN) {
247641
-			a->slot_num = dev->physical_slot;
247641
-			slot = addslot(state, 0x1000 + dev->physical_slot);
247641
-                        if (slot<0)
247641
-                                return slot;
247641
-                        a->port_num = slot;
247641
-		}
247641
-	}
247641
-
247641
-        return 0;
247641
-}
247641
-
247641
 void * setup_bios_devices(int namingpolicy, const char *prefix)
247641
 {
247641
 	int rc=1;
247641
@@ -396,9 +340,6 @@ void * setup_bios_devices(int namingpolicy, const char *prefix)
247641
 	get_eths(state);
247641
 	match_all(state);
247641
 	sort_device_list(state);
247641
-	rc = check_ports(state);
247641
-        if (rc)
247641
-                goto out;
247641
 	rc = assign_bios_network_names(state, namingpolicy, prefix);
247641
 	if (rc)
247641
 		goto out;
247641
diff --git a/src/bios_device.h b/src/bios_device.h
247641
index d1ef911..690ed6f 100644
247641
--- a/src/bios_device.h
247641
+++ b/src/bios_device.h
247641
@@ -19,9 +19,6 @@ struct bios_device {
247641
 	struct pci_device *pcidev;
247641
 	char *bios_name;
247641
 	int duplicate;
247641
-
247641
-	int slot_num;
247641
-	int port_num;
247641
 };
247641
 
247641
 static inline int is_pci(const struct bios_device *dev)
247641
diff --git a/src/naming_policy.c b/src/naming_policy.c
247641
index fe7b934..4f2033c 100644
247641
--- a/src/naming_policy.c
247641
+++ b/src/naming_policy.c
247641
@@ -59,8 +59,8 @@ static void use_physical(const struct libbiosdevname_state *state, const char *p
247641
 					portnum = vf->sysfs_index;
247641
 				else if (vf->uses_smbios & HAS_SMBIOS_INSTANCE && is_pci_smbios_type_ethernet(vf))
247641
 					portnum = vf->smbios_instance;
247641
-				else if (dev->port_num != -1)
247641
-					portnum = dev->port_num;
247641
+				else if (vf->embedded_index_valid)
247641
+					portnum = vf->embedded_index;
247641
 				if (portnum != INT_MAX) {	
247641
 					snprintf(location, sizeof(location), "%s%u", prefix, portnum);
247641
 					known=1;
247641
@@ -70,8 +70,6 @@ static void use_physical(const struct libbiosdevname_state *state, const char *p
247641
 				snprintf(location, sizeof(location), "p%u", dev->pcidev->physical_slot);
247641
 				if (dev->pcidev->vpd_port < INT_MAX)
247641
 					portnum = dev->pcidev->vpd_port;
247641
-				else if (dev->port_num != -1)
247641
-					portnum = dev->port_num;
247641
 				else if (!dev->pcidev->is_sriov_virtual_function)
247641
 				  	portnum = dev->pcidev->index_in_slot;
247641
 				else
247641
diff --git a/src/pci.c b/src/pci.c
247641
index b64fc3f..7aa32fc 100644
247641
--- a/src/pci.c
247641
+++ b/src/pci.c
247641
@@ -637,26 +637,6 @@ void free_pci_devices(struct libbiosdevname_state *state)
247641
 	}
247641
 }
247641
 
247641
-int addslot(struct libbiosdevname_state *state, int slot)
247641
-{
247641
-	struct slotlist *s;
247641
-
247641
-	list_for_each_entry(s, &state->slots, node) {
247641
-		if (s->slot == slot) {
247641
-			return ++s->count;
247641
-		}
247641
-	}
247641
-	s = malloc(sizeof(*s));
247641
-        if(!s)
247641
-                return -1;
247641
-	INIT_LIST_HEAD(&s->node);
247641
-	s->slot = slot;
247641
-	s->count = 0;
247641
-	list_add(&s->node, &state->slots);
247641
-
247641
-	return ++s->count;
247641
-}
247641
-
247641
 static int set_pci_slots(struct libbiosdevname_state *state)
247641
 {
247641
 	struct pci_device *dev;
247641
@@ -665,29 +645,56 @@ static int set_pci_slots(struct libbiosdevname_state *state)
247641
 	list_for_each_entry(dev, &state->pci_devices, node) {
247641
 		dev_to_slot(state, dev);
247641
 	}
247641
+}
247641
 
247641
-	/* Get mapping for each slot */
247641
-	list_for_each_entry(dev, &state->pci_devices, node) {
247641
-		if (dev->is_sriov_virtual_function || !is_pci_network(dev) || dev->vpd_port != INT_MAX) {
247641
+static int set_pci_slot_index(struct libbiosdevname_state *state)
247641
+{
247641
+	struct pci_device *pcidev;
247641
+	int prevslot=-1;
247641
+	int index=1;
247641
+
247641
+	/* only iterate over the PCI devices, because the bios_device list may be incomplete due to renames happening in parallel */
247641
+	list_for_each_entry(pcidev, &state->pci_devices, node) {
247641
+		if (pcidev->physical_slot == 0) /* skip embedded devices */
247641
+ 			continue;
247641
+		if (!is_pci_network(pcidev)) /* only look at PCI network devices */
247641
 			continue;
247641
-		}
247641
-		if (dev->physical_slot == 0) {
247641
-			dev->embedded_index_valid = 1;
247641
-			slot = addslot(state, 0);
247641
-                        if (slot<0)
247641
-                                return slot;
247641
-                        dev->embedded_index = slot;
247641
-		} else if (dev->physical_slot != PHYSICAL_SLOT_UNKNOWN) {
247641
-			slot = addslot(state, dev->physical_slot);
247641
-                        if (slot<0)
247641
-                                return slot;
247641
-                        dev->index_in_slot = slot;
247641
-		}
247641
-	}
247641
+		if (pcidev->is_sriov_virtual_function) /* skip sriov VFs, they're handled later */
247641
+			continue;
247641
+		if (pcidev->physical_slot != prevslot) {
247641
+			index=1;
247641
+			prevslot = pcidev->physical_slot;
247641
+ 		}
247641
+		else
247641
+			index++;
247641
+		pcidev->index_in_slot = index;
247641
+ 	}
247641
+	return 0;
247641
+}
247641
+ 
247641
+static int set_embedded_index(struct libbiosdevname_state *state)
247641
+{
247641
+	struct pci_device *pcidev;
247641
+	int index=1;
247641
 
247641
-        return 0;
247641
+	list_for_each_entry(pcidev, &state->pci_devices, node) {
247641
+		if (pcidev->physical_slot != 0) /* skip non-embedded devices */
247641
+			continue;
247641
+		if (!is_pci_network(pcidev)) /* only look at PCI network devices */
247641
+			continue;
247641
+		if (pcidev->is_sriov_virtual_function) /* skip sriov VFs, they're handled later */
247641
+			continue;
247641
+		if (pcidev->vpd_port != INT_MAX)
247641
+			continue;
247641
+		pcidev->embedded_index = index;
247641
+		pcidev->embedded_index_valid = 1;
247641
+		index++;
247641
+	}
247641
+	return 0;
247641
 }
247641
 
247641
+
247641
+
247641
 static void set_sriov_pf_vf(struct libbiosdevname_state *state)
247641
 {
247641
 	struct pci_device *vf;
247641
@@ -774,6 +781,9 @@ int get_pci_devices(struct libbiosdevname_state *state)
247641
 	rc = set_pci_slots(state);
247641
         if(rc)
247641
                 goto out;
247641
+
247641
+        set_embedded_index(state);
247641
+	set_pci_slot_index(state);
247641
 	set_sriov_pf_vf(state);
247641
 
247641
 out:
247641
-- 
247641
1.8.3.1
247641