Commit 8e3d44f7 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

bdev/nvme: delay stopping discovery with in-progress attach



This ensures that we wait until all attaches are completed before a
discovery is stopped.  Otherwise we would try to delete bdevs and free
their entry contexts before they're attached leading to a segfault.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I943d8cc60bf7e977a4939013975b0a03ac06cce9
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18372


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent bc6764aa
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -6152,11 +6152,16 @@ build_trid_from_log_page_entry(struct spdk_nvme_transport_id *trid,
}

static void
stop_discovery(struct discovery_ctx *ctx, spdk_bdev_nvme_stop_discovery_fn cb_fn, void *cb_ctx)
_stop_discovery(void *_ctx)
{
	struct discovery_ctx *ctx = _ctx;

	if (ctx->attach_in_progress > 0) {
		spdk_thread_send_msg(spdk_get_thread(), _stop_discovery, ctx);
		return;
	}

	ctx->stop = true;
	ctx->stop_cb_fn = cb_fn;
	ctx->cb_ctx = cb_ctx;

	while (!TAILQ_EMPTY(&ctx->nvm_entry_ctxs)) {
		struct discovery_entry_ctx *entry_ctx;
@@ -6181,6 +6186,20 @@ stop_discovery(struct discovery_ctx *ctx, spdk_bdev_nvme_stop_discovery_fn cb_fn
	ctx->entry_ctx_in_use = NULL;
}

static void
stop_discovery(struct discovery_ctx *ctx, spdk_bdev_nvme_stop_discovery_fn cb_fn, void *cb_ctx)
{
	ctx->stop_cb_fn = cb_fn;
	ctx->cb_ctx = cb_ctx;

	if (ctx->attach_in_progress > 0) {
		DISCOVERY_INFOLOG(ctx, "stopping discovery with attach_in_progress: %"PRIu32"\n",
				  ctx->attach_in_progress);
	}

	_stop_discovery(ctx);
}

static void
remove_discovery_entry(struct nvme_ctrlr *nvme_ctrlr)
{