Commit e14876e1 authored by Krzysztof Karas's avatar Krzysztof Karas Committed by Tomasz Zawadzki
Browse files

lib/nvme: add spdk_nvme_scan_attached()



Calling spdk_nvme_probe/_async(), at some point, results in attaching
to all available devices for a given trid at some point. This is
inconvenient when user would  want to process events for attached
controllers only.

Change-Id: Idcfe5b5bb70081f5c8043527e19695104887ddba
Signed-off-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23574


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
parent 1d6dfcbe
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1100,6 +1100,18 @@ int spdk_nvme_detach_poll_async(struct spdk_nvme_detach_ctx *detach_ctx);
 */
void spdk_nvme_detach_poll(struct spdk_nvme_detach_ctx *detach_ctx);

/**
 * Scan attached controllers for events.
 *
 * This function lets user act on events such as hot-remove without a need to
 * enable hotplug explicitly. Only attached devices will be checked.
 *
 * \param trid Transport ID.
 *
 * \returns 0 on success, negative on failure.
 */
int spdk_nvme_scan_attached(const struct spdk_nvme_transport_id *trid);

/**
 * Update the transport ID for a given controller.
 *
+26 −0
Original line number Diff line number Diff line
@@ -1504,6 +1504,32 @@ spdk_nvme_prchk_flags_str(uint32_t prchk_flags)
	}
}

int
spdk_nvme_scan_attached(const struct spdk_nvme_transport_id *trid)
{
	int rc;
	struct spdk_nvme_probe_ctx *probe_ctx;

	rc = nvme_driver_init();
	if (rc != 0) {
		return rc;
	}

	probe_ctx = calloc(1, sizeof(*probe_ctx));
	if (!probe_ctx) {
		return -ENOMEM;
	}

	nvme_probe_ctx_init(probe_ctx, trid, NULL, NULL, NULL, NULL, NULL);

	nvme_robust_mutex_lock(&g_spdk_nvme_driver->lock);
	rc = nvme_transport_ctrlr_scan_attached(probe_ctx);
	nvme_robust_mutex_unlock(&g_spdk_nvme_driver->lock);
	free(probe_ctx);

	return rc < 0 ? rc : 0;
}

struct spdk_nvme_probe_ctx *
spdk_nvme_probe_async(const struct spdk_nvme_transport_id *trid,
		      void *cb_ctx,
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
	spdk_nvme_detach_async;
	spdk_nvme_detach_poll_async;
	spdk_nvme_detach_poll;
	spdk_nvme_scan_attached;

	spdk_nvme_pcie_set_hotplug_filter;

+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ DEFINE_STUB(spdk_nvme_transport_available, bool,
DEFINE_STUB(spdk_pci_event_listen, int, (void), 0);
DEFINE_STUB(spdk_nvme_poll_group_process_completions, int64_t, (struct spdk_nvme_poll_group *group,
		uint32_t completions_per_qpair, spdk_nvme_disconnected_qpair_cb disconnected_qpair_cb), 0);
DEFINE_STUB(nvme_transport_ctrlr_scan_attached, int, (struct spdk_nvme_probe_ctx *probe_ctx), 0);

static bool ut_destruct_called = false;
void
+5 −0
Original line number Diff line number Diff line
@@ -63,6 +63,11 @@ DEFINE_STUB(nvme_ctrlr_get_current_process,
	    (struct spdk_nvme_ctrlr *ctrlr),
	    (struct spdk_nvme_ctrlr_process *)(uintptr_t)0x1);

DEFINE_STUB(nvme_transport_ctrlr_scan_attached,
	    int,
	    (struct spdk_nvme_probe_ctx *probe_ctx),
	    0);

int
spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx)
{
Loading