From 2b65309b6c29b4fc61ed9be20ef3044b60a69b63 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 10 Dec 2021 16:02:04 -0700 Subject: [PATCH] env: remove spdk_pci_get_[first|next]_device These APIs are not safe, since they do not hold the pci device lock across calls, which can cause problems if a device is inserted or removed while handles returned by these APIs are being used. Signed-off-by: Jim Harris Change-Id: I01a80f26d0a0ca4cdfc7181359932b38da8dd43a Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10659 Reviewed-by: Konrad Sztyber Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot --- CHANGELOG.md | 5 +++++ include/spdk/env.h | 19 ------------------- lib/env_dpdk/Makefile | 4 ++-- lib/env_dpdk/pci.c | 12 ------------ lib/env_dpdk/spdk_env_dpdk.map | 2 -- 5 files changed, 7 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b8fa24014..2fe38792df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,11 @@ were deprecated. Added spdk_pci_for_each_device. +Removed spdk_pci_get_first_device and spdk_pci_get_next_device. These APIs were unsafe, because +they did not account for PCI devices being inserted or removed while the caller was using handles +returned from these APIs. Existing users of these APIs should switch to spdk_pci_for_each_device +instead. + ## v21.10 Structure `spdk_nvmf_target_opts` has been extended with new member `discovery_filter` which allows to specify diff --git a/include/spdk/env.h b/include/spdk/env.h index 4768adfbbf..1f627efe82 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -796,25 +796,6 @@ int spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, */ void spdk_pci_for_each_device(void *ctx, void (*fn)(void *ctx, struct spdk_pci_device *dev)); -/** - * Begin iterating over enumerated PCI device by calling this function to get - * the first PCI device. If there no PCI devices enumerated, return NULL - * - * \return a pointer to a PCI device on success, NULL otherwise. - */ -struct spdk_pci_device *spdk_pci_get_first_device(void); - -/** - * Continue iterating over enumerated PCI devices. - * If no additional PCI devices, return NULL - * - * \param prev Previous PCI device returned from \ref spdk_pci_get_first_device - * or \ref spdk_pci_get_next_device - * - * \return a pointer to the next PCI device on success, NULL otherwise. - */ -struct spdk_pci_device *spdk_pci_get_next_device(struct spdk_pci_device *prev); - /** * Map a PCI BAR in the current process. * diff --git a/lib/env_dpdk/Makefile b/lib/env_dpdk/Makefile index f2669004a8..795fc4f7ad 100644 --- a/lib/env_dpdk/Makefile +++ b/lib/env_dpdk/Makefile @@ -34,8 +34,8 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -SO_VER := 7 -SO_MINOR := 1 +SO_VER := 8 +SO_MINOR := 0 CFLAGS += $(ENV_CFLAGS) C_SRCS = env.c memory.c pci.c init.c threads.c diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index 09a1eb14e0..5d9c48a552 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -774,18 +774,6 @@ spdk_pci_for_each_device(void *ctx, void (*fn)(void *ctx, struct spdk_pci_device pthread_mutex_unlock(&g_pci_mutex); } -struct spdk_pci_device * -spdk_pci_get_first_device(void) -{ - return TAILQ_FIRST(&g_pci_devices); -} - -struct spdk_pci_device * -spdk_pci_get_next_device(struct spdk_pci_device *prev) -{ - return TAILQ_NEXT(prev, internal.tailq); -} - int spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar, void **mapped_addr, uint64_t *phys_addr, uint64_t *size) diff --git a/lib/env_dpdk/spdk_env_dpdk.map b/lib/env_dpdk/spdk_env_dpdk.map index bceeb0f804..1e76799223 100644 --- a/lib/env_dpdk/spdk_env_dpdk.map +++ b/lib/env_dpdk/spdk_env_dpdk.map @@ -60,8 +60,6 @@ spdk_pci_virtio_get_driver; spdk_pci_enumerate; spdk_pci_for_each_device; - spdk_pci_get_first_device; - spdk_pci_get_next_device; spdk_pci_device_map_bar; spdk_pci_device_unmap_bar; spdk_pci_device_get_domain;