diff --git a/CHANGELOG.md b/CHANGELOG.md index c9998a315..1b8fa2401 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,10 @@ New APIs, `spdk_nvme_ctrlr_disconnect`, `spdk_nvme_ctrlr_reconnect_async`, and the existing APIs,`spdk_nvme_ctrlr_reset_async` and `spdk_nvme_ctrlr_reset_poll_async` were deprecated. +### env + +Added spdk_pci_for_each_device. + ## 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 db6b5d4a6..4768adfbb 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -788,6 +788,14 @@ struct spdk_pci_driver *spdk_pci_nvme_get_driver(void); */ int spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx); +/** + * Call the provided function pointer for every enumerated PCI device. + * + * \param ctx Context parameter to pass to fn. + * \param fn Function to call for each PCI device + */ +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 diff --git a/lib/env_dpdk/Makefile b/lib/env_dpdk/Makefile index 19b0e7be6..f2669004a 100644 --- a/lib/env_dpdk/Makefile +++ b/lib/env_dpdk/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk SO_VER := 7 -SO_MINOR := 0 +SO_MINOR := 1 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 b0a2fc8ec..09a1eb14e 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -762,6 +762,18 @@ spdk_pci_enumerate(struct spdk_pci_driver *driver, return 0; } +void +spdk_pci_for_each_device(void *ctx, void (*fn)(void *ctx, struct spdk_pci_device *dev)) +{ + struct spdk_pci_device *dev; + + pthread_mutex_lock(&g_pci_mutex); + TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) { + fn(ctx, dev); + } + pthread_mutex_unlock(&g_pci_mutex); +} + struct spdk_pci_device * spdk_pci_get_first_device(void) { diff --git a/lib/env_dpdk/spdk_env_dpdk.map b/lib/env_dpdk/spdk_env_dpdk.map index 712228de1..bceeb0f80 100644 --- a/lib/env_dpdk/spdk_env_dpdk.map +++ b/lib/env_dpdk/spdk_env_dpdk.map @@ -59,6 +59,7 @@ spdk_pci_ioat_get_driver; 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;