DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ben Walker <benjamin.walker@intel.com>
To: dev@dpdk.org
Cc: Ben Walker <benjamin.walker@intel.com>
Subject: [dpdk-dev] [PATCH v3 1/3] pci: rte_eal_pci_scan now handles removal of PCI devices
Date: Thu,  9 Feb 2017 09:59:57 -0700	[thread overview]
Message-ID: <20170209165959.28082-1-benjamin.walker@intel.com> (raw)
In-Reply-To: <1479931644-78960-4-git-send-email-benjamin.walker@intel.com>

rte_eal_pci_scan can be called repeatedly to re-scan the PCI
bus. If a device was removed from the system, the associated
driver will automatically be unloaded.

Signed-off-by: Ben Walker <benjamin.walker@intel.com>
---

Only code style changes compared to last submission. It is also rebased
onto the latest from master, which had no conflicts.

 lib/librte_eal/linuxapp/eal/eal_pci.c | 70 +++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index e2fc219..2eed405 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -446,7 +446,77 @@ rte_eal_pci_scan(void)
 	DIR *dir;
 	char dirname[PATH_MAX];
 	struct rte_pci_addr addr;
+	struct rte_pci_device *dev, *tmp;
+
+	/* Search the device list for devices that are no longer present
+	 * on the system and remove them.
+	 */
+	TAILQ_FOREACH_SAFE(dev, &pci_device_list, next, tmp) {
+		int found = 0;
+
+		dir = opendir(pci_get_sysfs_path());
+		if (dir == NULL) {
+			RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
+				__func__, strerror(errno));
+			return -1;
+		}
+
+		while ((e = readdir(dir)) != NULL) {
+			if (e->d_name[0] == '.')
+				continue;
+
+			if (parse_pci_addr_format(e->d_name, sizeof(e->d_name),
+						  &addr) != 0)
+				continue;
+
+			if (rte_eal_compare_pci_addr(&addr, &dev->addr) == 0) {
+				found = 1;
+				break;
+			}
+		}
+
+		if (!found) {
+
+			RTE_LOG(DEBUG, EAL,
+				"PCI device "PCI_PRI_FMT" was removed.\n",
+				addr.domain, addr.bus, addr.devid,
+				addr.function);
+
+			if (dev->driver) {
+				/* A driver was loaded against this device.
+				 * Unload it.
+				 */
+				RTE_LOG(DEBUG, EAL,
+					"  Unload driver: %x:%x %s\n",
+					dev->id.vendor_id, dev->id.device_id,
+					dev->driver->driver.name);
+
+				if (dev->driver->remove) {
+					/* It doesn't matter what remove
+					 * returns - we're removing the
+					 * device either way.
+					 */
+					dev->driver->remove(dev);
+				}
+
+				/* clear driver structure */
+				dev->driver = NULL;
+
+				if (dev->driver->drv_flags &
+				    RTE_PCI_DRV_NEED_MAPPING)
+					rte_eal_pci_unmap_device(dev);
+			}
+
+			TAILQ_REMOVE(&pci_device_list, dev, next);
+			free(dev);
+		}
+
+		closedir(dir);
+	}
 
+	/* Search sysfs for all PCI devices and add them to the
+	 * device list
+	 */
 	dir = opendir(pci_get_sysfs_path());
 	if (dir == NULL) {
 		RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
-- 
2.9.3

  parent reply	other threads:[~2017-02-09 17:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-23 19:36 [dpdk-dev] Improved PCI hotplug support Ben Walker
2016-11-23 19:36 ` [dpdk-dev] [PATCH 1/7] pci: If a driver's probe function fails, unmap resources Ben Walker
2016-11-23 19:36 ` [dpdk-dev] [PATCH 2/7] pci: Separate detaching ethernet ports from PCI devices Ben Walker
2016-11-23 19:36 ` [dpdk-dev] [PATCH 3/7] pci: Pass rte_pci_addr to functions instead of separate args Ben Walker
2016-11-23 19:36 ` [dpdk-dev] [PATCH 4/7] pci: rte_eal_pci_scan now handles removal of PCI devices Ben Walker
2016-11-23 19:36 ` [dpdk-dev] [PATCH 5/7] pci: Move driver registration above pci scan Ben Walker
2016-11-23 19:36 ` [dpdk-dev] [PATCH 6/7] pci: Combine rte_eal_pci_scan and rte_eal_pci_probe Ben Walker
2016-11-23 19:36 ` [dpdk-dev] [PATCH 7/7] pci: Clarify interfaces for dynamic attach/detach of drivers Ben Walker
2016-11-23 20:07 ` [dpdk-dev] [PATCH v2 1/7] pci: If a driver's probe function fails, unmap resources Ben Walker
2016-11-23 20:07   ` [dpdk-dev] [PATCH v2 2/7] pci: Separate detaching ethernet ports from PCI devices Ben Walker
2016-11-25  9:25     ` Shreyansh Jain
2016-11-23 20:07   ` [dpdk-dev] [PATCH v2 3/7] pci: Pass rte_pci_addr to functions instead of separate args Ben Walker
2016-11-25 10:33     ` Shreyansh Jain
2016-12-01  6:26     ` Shreyansh Jain
2016-12-02 16:16       ` Walker, Benjamin
2016-11-23 20:07   ` [dpdk-dev] [PATCH v2 4/7] pci: rte_eal_pci_scan now handles removal of PCI devices Ben Walker
2016-11-25 10:44     ` Shreyansh Jain
2017-02-09 16:59     ` Ben Walker [this message]
2017-02-09 16:59       ` [dpdk-dev] [PATCH v3 2/3] pci: Move driver registration above pci scan Ben Walker
2017-02-09 16:59       ` [dpdk-dev] [PATCH v3 3/3] pci: Clarify interfaces for dynamic attach/detach of drivers Ben Walker
2019-01-23 16:19       ` [dpdk-dev] [PATCH v3 1/3] pci: rte_eal_pci_scan now handles removal of PCI devices Ferruh Yigit
2016-11-23 20:07   ` [dpdk-dev] [PATCH v2 5/7] pci: Move driver registration above pci scan Ben Walker
2016-11-23 20:07   ` [dpdk-dev] [PATCH v2 6/7] pci: Combine rte_eal_pci_scan and rte_eal_pci_probe Ben Walker
2016-11-25 10:56     ` Shreyansh Jain
2016-11-23 20:07   ` [dpdk-dev] [PATCH v2 7/7] pci: Clarify interfaces for dynamic attach/detach of drivers Ben Walker
2016-12-03  6:55     ` Shreyansh Jain
2016-11-25  9:21   ` [dpdk-dev] [PATCH v2 1/7] pci: If a driver's probe function fails, unmap resources Shreyansh Jain
2016-12-21 16:19     ` Thomas Monjalon
2017-01-04 17:39       ` Thomas Monjalon
2017-01-09 17:12         ` Thomas Monjalon
2017-01-11 17:10   ` [dpdk-dev] [PATCH v3 1/3] " Ben Walker
2017-01-11 17:10     ` [dpdk-dev] [PATCH v3 2/3] pci: Separate detaching ethernet ports from PCI devices Ben Walker
2017-01-11 17:10     ` [dpdk-dev] [PATCH v3 3/3] pci: Pass rte_pci_addr to functions instead of separate args Ben Walker
2017-01-12 14:58       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170209165959.28082-1-benjamin.walker@intel.com \
    --to=benjamin.walker@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).