env_dpdk/pci: cleanup locks

Put the locks inside cleanup_pci_devices().
This serves as cleanup.

Change-Id: I040b28006e5584d1f33af26b63cafedbafe04fdb
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458934
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: John Kariuki <John.K.Kariuki@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-06-21 08:29:25 +02:00 committed by Ben Walker
parent fe511d03d2
commit b9e8dc71f7

View File

@ -177,6 +177,7 @@ cleanup_pci_devices(void)
{ {
struct spdk_pci_device *dev, *tmp; struct spdk_pci_device *dev, *tmp;
pthread_mutex_lock(&g_pci_mutex);
/* cleanup removed devices */ /* cleanup removed devices */
TAILQ_FOREACH_SAFE(dev, &g_pci_devices, internal.tailq, tmp) { TAILQ_FOREACH_SAFE(dev, &g_pci_devices, internal.tailq, tmp) {
if (!dev->internal.removed) { if (!dev->internal.removed) {
@ -194,6 +195,7 @@ cleanup_pci_devices(void)
TAILQ_INSERT_TAIL(&g_pci_devices, dev, internal.tailq); TAILQ_INSERT_TAIL(&g_pci_devices, dev, internal.tailq);
spdk_vtophys_pci_device_added(dev->dev_handle); spdk_vtophys_pci_device_added(dev->dev_handle);
} }
pthread_mutex_unlock(&g_pci_mutex);
} }
void void
@ -340,9 +342,7 @@ spdk_pci_device_detach(struct spdk_pci_device *dev)
dev->internal.attached = false; dev->internal.attached = false;
dev->detach(dev); dev->detach(dev);
pthread_mutex_lock(&g_pci_mutex);
cleanup_pci_devices(); cleanup_pci_devices();
pthread_mutex_unlock(&g_pci_mutex);
} }
int int
@ -356,9 +356,7 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver,
spdk_pci_addr_fmt(bdf, sizeof(bdf), pci_address); spdk_pci_addr_fmt(bdf, sizeof(bdf), pci_address);
pthread_mutex_lock(&g_pci_mutex);
cleanup_pci_devices(); cleanup_pci_devices();
pthread_mutex_unlock(&g_pci_mutex);
TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) { TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) {
if (spdk_pci_addr_compare(&dev->addr, pci_address) == 0) { 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_arg = NULL;
driver->cb_fn = NULL; driver->cb_fn = NULL;
pthread_mutex_lock(&g_pci_mutex);
cleanup_pci_devices(); cleanup_pci_devices();
pthread_mutex_unlock(&g_pci_mutex);
return rc == 0 ? 0 : -1; return rc == 0 ? 0 : -1;
} }
@ -427,8 +423,9 @@ spdk_pci_enumerate(struct spdk_pci_driver *driver,
struct spdk_pci_device *dev; struct spdk_pci_device *dev;
int rc; int rc;
pthread_mutex_lock(&g_pci_mutex);
cleanup_pci_devices(); cleanup_pci_devices();
pthread_mutex_lock(&g_pci_mutex);
TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) { TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) {
if (dev->internal.attached || if (dev->internal.attached ||
dev->internal.driver != driver || dev->internal.driver != driver ||
@ -463,9 +460,7 @@ spdk_pci_enumerate(struct spdk_pci_driver *driver,
driver->cb_arg = NULL; driver->cb_arg = NULL;
driver->cb_fn = NULL; driver->cb_fn = NULL;
pthread_mutex_lock(&g_pci_mutex);
cleanup_pci_devices(); cleanup_pci_devices();
pthread_mutex_unlock(&g_pci_mutex);
return 0; return 0;
} }