Commit 40a9d6a0 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

bdev/nvme: add entry_ctx_in_use



We will now keep a list of the possible paths to
the discovery subsystem.  One of them will be the
path we are currently connected to (which at service
start, is the path specified by the user).

Additional entries are added for discovery log page
entries referencing the discovery subsystem.

When the discovery service starts, we just have the
initial entry in the list - the discovery poller
tries to connect to it, and if the connect starts
successfully, removes it from the list and points
ctx->entry_ctx_in_use to it.

This will be useful later when we want to iterate
through the available paths to the discovery
subsystem if the current path fails.

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


Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
parent 5428fb01
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -4329,6 +4329,7 @@ struct discovery_ctx {
	struct spdk_nvme_detach_ctx		*detach_ctx;
	struct spdk_nvme_ctrlr			*ctrlr;
	struct spdk_nvme_transport_id		trid;
	struct discovery_entry_ctx		*entry_ctx_in_use;
	struct spdk_poller			*poller;
	struct spdk_nvme_ctrlr_opts		drv_opts;
	struct spdk_nvmf_discovery_log_page	*log_page;
@@ -4639,6 +4640,7 @@ static int
discovery_poller(void *arg)
{
	struct discovery_ctx *ctx = arg;
	struct spdk_nvme_transport_id *trid;
	int rc;

	if (ctx->detach) {
@@ -4665,9 +4667,15 @@ discovery_poller(void *arg)
			free_discovery_ctx(ctx);
		}
	} else if (ctx->probe_ctx == NULL && ctx->ctrlr == NULL) {
		ctx->probe_ctx = spdk_nvme_connect_async(&ctx->trid, &ctx->drv_opts, discovery_attach_cb);
		if (ctx->probe_ctx == NULL) {
		assert(ctx->entry_ctx_in_use == NULL);
		ctx->entry_ctx_in_use = TAILQ_FIRST(&ctx->discovery_entry_ctxs);
		trid = &ctx->entry_ctx_in_use->trid;
		ctx->probe_ctx = spdk_nvme_connect_async(trid, &ctx->drv_opts, discovery_attach_cb);
		if (ctx->probe_ctx) {
			TAILQ_REMOVE(&ctx->discovery_entry_ctxs, ctx->entry_ctx_in_use, tailq);
		} else {
			DISCOVERY_ERRLOG(ctx, "could not start discovery connect\n");
			ctx->entry_ctx_in_use = NULL;
		}
	} else if (ctx->probe_ctx) {
		rc = spdk_nvme_probe_poll_async(ctx->probe_ctx);
@@ -4700,6 +4708,7 @@ bdev_nvme_start_discovery(struct spdk_nvme_transport_id *trid,
			  struct spdk_nvme_ctrlr_opts *drv_opts)
{
	struct discovery_ctx *ctx;
	struct discovery_entry_ctx *discovery_entry_ctx;

	ctx = calloc(1, sizeof(*ctx));
	if (ctx == NULL) {
@@ -4723,6 +4732,14 @@ bdev_nvme_start_discovery(struct spdk_nvme_transport_id *trid,
		free_discovery_ctx(ctx);
		return -ENOMEM;
	}
	discovery_entry_ctx = create_discovery_entry_ctx(ctx, trid);
	if (discovery_entry_ctx == NULL) {
		DISCOVERY_ERRLOG(ctx, "could not allocate new entry_ctx\n");
		free_discovery_ctx(ctx);
		return -ENOMEM;
	}

	TAILQ_INSERT_TAIL(&ctx->discovery_entry_ctxs, discovery_entry_ctx, tailq);
	spdk_thread_send_msg(g_bdev_nvme_init_thread, start_discovery_poller, ctx);
	return 0;
}