Commit 1ea419ec authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

nvme: restart discovery log when genctr changes



Each portion of the discovery log has a header which
includes a 'genctr'. This number indicates the
current generation of the discovery log. If this
number changes during the process of fetching the
discovery log in multiple chunks, wait for the
current fetch to complete, but then start over.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 6a520ae6
Loading
Loading
Loading
Loading
+39 −8
Original line number Diff line number Diff line
@@ -44,11 +44,37 @@ struct nvme_discovery_ctx {
	uint32_t				outstanding_commands;
};

static void
get_log_page_completion_final(void *cb_arg, const struct spdk_nvme_cpl *cpl)
{
	struct nvme_discovery_ctx *ctx = cb_arg;
	int rc;

	if (spdk_nvme_cpl_is_error(cpl)) {
		free(ctx->log_page);
		ctx->cb_fn(ctx->cb_arg, 0, cpl, NULL);
		free(ctx);
		return;
	}

	/* Compare original genctr with latest genctr. If it changed, we need to restart. */
	if (ctx->log_page->genctr == ctx->genctr) {
		ctx->cb_fn(ctx->cb_arg, 0, cpl, ctx->log_page);
	} else {
		free(ctx->log_page);
		rc = spdk_nvme_ctrlr_get_discovery_log_page(ctx->ctrlr, ctx->cb_fn, ctx->cb_arg);
		if (rc != 0) {
			ctx->cb_fn(ctx->cb_arg, rc, NULL, NULL);
		}
	}
	free(ctx);
}

static void
get_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
{
	struct nvme_discovery_ctx *ctx = cb_arg;
	struct spdk_nvmf_discovery_log_page *log_page;
	int rc;

	if (spdk_nvme_cpl_is_error(cpl)) {
		/* Only save the cpl for the first error that we encounter. */
@@ -61,17 +87,22 @@ get_log_page_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)
		return;
	}

	if (!spdk_nvme_cpl_is_error(&ctx->cpl)) {
		log_page = ctx->log_page;
	} else {
		/* We had an error, so don't return the log page to the caller. */
		log_page = NULL;
	if (spdk_nvme_cpl_is_error(&ctx->cpl)) {
		free(ctx->log_page);
		ctx->cb_fn(ctx->cb_arg, 0, &ctx->cpl, NULL);
		free(ctx);
		return;
	}

	ctx->cb_fn(ctx->cb_arg, 0, &ctx->cpl, log_page);
	rc = spdk_nvme_ctrlr_cmd_get_log_page(ctx->ctrlr, SPDK_NVME_LOG_DISCOVERY, 0,
					      &ctx->genctr, sizeof(ctx->genctr), 0,
					      get_log_page_completion_final, ctx);
	if (rc != 0) {
		free(ctx->log_page);
		ctx->cb_fn(ctx->cb_arg, rc, NULL, NULL);
		free(ctx);
	}
}

static void
discovery_log_header_completion(void *cb_arg, const struct spdk_nvme_cpl *cpl)