Commit 13fbf885 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

env: add spdk_pci_for_each_device



This is a safer alternative to spdk_pci_get_first/next_device,
since those APIs do not hold the lock between calls.

Future patches will remove those APIs, and change callers to
use this new API instead.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I71c7e8c1feb9112da8be32a8056b30e105e30463
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10655


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
parent 59f3cdac
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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
+8 −0
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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
+12 −0
Original line number Diff line number Diff line
@@ -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)
{
+1 −0
Original line number Diff line number Diff line
@@ -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;