From b9e8dc71f7fa8b768bad914a2f756b84454ee73b Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Fri, 21 Jun 2019 08:29:25 +0200 Subject: [PATCH] env_dpdk/pci: cleanup locks Put the locks inside cleanup_pci_devices(). This serves as cleanup. Change-Id: I040b28006e5584d1f33af26b63cafedbafe04fdb Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458934 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: John Kariuki --- lib/env_dpdk/pci.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index e8aeea3fc..31dec6f58 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -177,6 +177,7 @@ cleanup_pci_devices(void) { struct spdk_pci_device *dev, *tmp; + pthread_mutex_lock(&g_pci_mutex); /* cleanup removed devices */ TAILQ_FOREACH_SAFE(dev, &g_pci_devices, internal.tailq, tmp) { if (!dev->internal.removed) { @@ -194,6 +195,7 @@ cleanup_pci_devices(void) TAILQ_INSERT_TAIL(&g_pci_devices, dev, internal.tailq); spdk_vtophys_pci_device_added(dev->dev_handle); } + pthread_mutex_unlock(&g_pci_mutex); } void @@ -340,9 +342,7 @@ spdk_pci_device_detach(struct spdk_pci_device *dev) dev->internal.attached = false; dev->detach(dev); - pthread_mutex_lock(&g_pci_mutex); cleanup_pci_devices(); - pthread_mutex_unlock(&g_pci_mutex); } int @@ -356,9 +356,7 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver, spdk_pci_addr_fmt(bdf, sizeof(bdf), pci_address); - pthread_mutex_lock(&g_pci_mutex); cleanup_pci_devices(); - pthread_mutex_unlock(&g_pci_mutex); TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) { if (spdk_pci_addr_compare(&dev->addr, pci_address) == 0) { @@ -409,9 +407,7 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver, driver->cb_arg = NULL; driver->cb_fn = NULL; - pthread_mutex_lock(&g_pci_mutex); cleanup_pci_devices(); - pthread_mutex_unlock(&g_pci_mutex); return rc == 0 ? 0 : -1; } @@ -427,8 +423,9 @@ spdk_pci_enumerate(struct spdk_pci_driver *driver, struct spdk_pci_device *dev; int rc; - pthread_mutex_lock(&g_pci_mutex); cleanup_pci_devices(); + + pthread_mutex_lock(&g_pci_mutex); TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) { if (dev->internal.attached || dev->internal.driver != driver || @@ -463,9 +460,7 @@ spdk_pci_enumerate(struct spdk_pci_driver *driver, driver->cb_arg = NULL; driver->cb_fn = NULL; - pthread_mutex_lock(&g_pci_mutex); cleanup_pci_devices(); - pthread_mutex_unlock(&g_pci_mutex); return 0; }