Commit 30bbf3d9 authored by Changpeng Liu's avatar Changpeng Liu Committed by Jim Harris
Browse files

nvme: move probe context as a internal data structure



Users should not access the internal probe context fields when
using the asynchronous probe API, so change spdk_nvme_probe_async()
to let it can only return the probe context pointer.

Change-Id: I0413c2d8db6cbe4539ad80919ed34dd621a9df70
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/445870


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 2fefd9f5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@

### nvme

Added asynchronous probe support.  New APIs spdk_nvme_probe_ctx_init(), spdk_nvme_probe_async()
and spdk_nvme_probe_poll_async() were added to enable this feature.
Added asynchronous probe support.  New APIs spdk_nvme_probe_async() and
spdk_nvme_probe_poll_async() were added to enable this feature.

### raid

+11 −28
Original line number Diff line number Diff line
@@ -566,19 +566,14 @@ struct spdk_nvme_ctrlr *spdk_nvme_connect(const struct spdk_nvme_transport_id *t
		const struct spdk_nvme_ctrlr_opts *opts,
		size_t opts_size);

struct spdk_nvme_probe_ctx {
	struct spdk_nvme_transport_id		trid;
	void					*cb_ctx;
	spdk_nvme_probe_cb			probe_cb;
	spdk_nvme_attach_cb			attach_cb;
	spdk_nvme_remove_cb			remove_cb;
	TAILQ_HEAD(, spdk_nvme_ctrlr)		init_ctrlrs;
};
struct spdk_nvme_probe_ctx;

/**
 * Initialize a context to track the probe result based on transport ID.
 * Probe and add controllers to the probe context list.
 *
 * Users must call spdk_nvme_probe_poll_async() to initialize
 * controllers in the probe context list to the READY state.
 *
 * \param probe_ctx Context used to track probe actions.
 * \param trid The transport ID indicating which bus to enumerate. If the trtype
 * is PCIe or trid is NULL, this will scan the local PCIe bus. If the trtype is
 * RDMA, the traddr and trsvcid must point at the location of an NVMe-oF discovery
@@ -592,26 +587,14 @@ struct spdk_nvme_probe_ctx {
 * spdk_nvme_probe() call but are no longer attached to the system. Optional;
 * specify NULL if removal notices are not desired.
 *
 * \return probe context on success, NULL on failure.
 */
void spdk_nvme_probe_ctx_init(struct spdk_nvme_probe_ctx *probe_ctx,
			      const struct spdk_nvme_transport_id *trid,
struct spdk_nvme_probe_ctx *spdk_nvme_probe_async(const struct spdk_nvme_transport_id *trid,
		void *cb_ctx,
		spdk_nvme_probe_cb probe_cb,
		spdk_nvme_attach_cb attach_cb,
		spdk_nvme_remove_cb remove_cb);

/**
 * Probe and add controllers to the probe context list.
 *
 * Users must call spdk_nvme_probe_poll_async() to initialize
 * controllers in the probe context list to the READY state.
 *
 * \param probe_ctx Context used to track probe actions.
 *
 * \return 0 on success, -1 on failure.
 */
int spdk_nvme_probe_async(struct spdk_nvme_probe_ctx *probe_ctx);

/**
 * Start controllers in the context list.
 *
+37 −20
Original line number Diff line number Diff line
@@ -585,6 +585,22 @@ spdk_nvme_probe_internal(struct spdk_nvme_probe_ctx *probe_ctx,
	return 0;
}

static void
spdk_nvme_probe_ctx_init(struct spdk_nvme_probe_ctx *probe_ctx,
			 const struct spdk_nvme_transport_id *trid,
			 void *cb_ctx,
			 spdk_nvme_probe_cb probe_cb,
			 spdk_nvme_attach_cb attach_cb,
			 spdk_nvme_remove_cb remove_cb)
{
	probe_ctx->trid = *trid;
	probe_ctx->cb_ctx = cb_ctx;
	probe_ctx->probe_cb = probe_cb;
	probe_ctx->attach_cb = attach_cb;
	probe_ctx->remove_cb = remove_cb;
	TAILQ_INIT(&probe_ctx->init_ctrlrs);
}

int
spdk_nvme_probe(const struct spdk_nvme_transport_id *trid, void *cb_ctx,
		spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb,
@@ -1046,33 +1062,34 @@ spdk_nvme_prchk_flags_str(uint32_t prchk_flags)
	}
}

void
spdk_nvme_probe_ctx_init(struct spdk_nvme_probe_ctx *probe_ctx,
			 const struct spdk_nvme_transport_id *trid,
struct spdk_nvme_probe_ctx *
spdk_nvme_probe_async(const struct spdk_nvme_transport_id *trid,
		      void *cb_ctx,
		      spdk_nvme_probe_cb probe_cb,
		      spdk_nvme_attach_cb attach_cb,
		      spdk_nvme_remove_cb remove_cb)
{
	probe_ctx->trid = *trid;
	probe_ctx->cb_ctx = cb_ctx;
	probe_ctx->probe_cb = probe_cb;
	probe_ctx->attach_cb = attach_cb;
	probe_ctx->remove_cb = remove_cb;
	TAILQ_INIT(&probe_ctx->init_ctrlrs);
}

int
spdk_nvme_probe_async(struct spdk_nvme_probe_ctx *probe_ctx)
{
	int rc;
	struct spdk_nvme_probe_ctx *probe_ctx;

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

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

	spdk_nvme_probe_ctx_init(probe_ctx, trid, cb_ctx, probe_cb, attach_cb, remove_cb);
	rc = spdk_nvme_probe_internal(probe_ctx, false);
	if (rc != 0) {
		free(probe_ctx);
		return NULL;
	}

	return spdk_nvme_probe_internal(probe_ctx, false);
	return probe_ctx;
}

bool
+9 −0
Original line number Diff line number Diff line
@@ -691,6 +691,15 @@ struct spdk_nvme_ctrlr {
	uint32_t			outstanding_aborts;
};

struct spdk_nvme_probe_ctx {
	struct spdk_nvme_transport_id		trid;
	void					*cb_ctx;
	spdk_nvme_probe_cb			probe_cb;
	spdk_nvme_attach_cb			attach_cb;
	spdk_nvme_remove_cb			remove_cb;
	TAILQ_HEAD(, spdk_nvme_ctrlr)		init_ctrlrs;
};

struct nvme_driver {
	pthread_mutex_t			lock;