Commit 3c61b8ca authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

bdev/nvme: extract stopping discovery to a function



For now, it's only called from a single location,
bdev_nvme_stop_discovery, but it'll make it possible to stop the
discovery from other places.

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


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 623105bb
Loading
Loading
Loading
Loading
+28 −20
Original line number Diff line number Diff line
@@ -4858,6 +4858,33 @@ 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)
{
	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;
		struct nvme_path_id path = {};

		entry_ctx = TAILQ_FIRST(&ctx->nvm_entry_ctxs);
		path.trid = entry_ctx->trid;
		bdev_nvme_delete(entry_ctx->name, &path);
		TAILQ_REMOVE(&ctx->nvm_entry_ctxs, entry_ctx, tailq);
		free(entry_ctx);
	}

	while (!TAILQ_EMPTY(&ctx->discovery_entry_ctxs)) {
		struct discovery_entry_ctx *entry_ctx;

		entry_ctx = TAILQ_FIRST(&ctx->discovery_entry_ctxs);
		TAILQ_REMOVE(&ctx->discovery_entry_ctxs, entry_ctx, tailq);
		free(entry_ctx);
	}
}

static void
discovery_remove_controllers(struct discovery_ctx *ctx)
{
@@ -5242,26 +5269,7 @@ bdev_nvme_stop_discovery(const char *name, spdk_bdev_nvme_stop_discovery_fn cb_f
			if (ctx->stop) {
				return -EALREADY;
			}
			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;
				struct nvme_path_id path = {};

				entry_ctx = TAILQ_FIRST(&ctx->nvm_entry_ctxs);
				path.trid = entry_ctx->trid;
				bdev_nvme_delete(entry_ctx->name, &path);
				TAILQ_REMOVE(&ctx->nvm_entry_ctxs, entry_ctx, tailq);
				free(entry_ctx);
			}
			while (!TAILQ_EMPTY(&ctx->discovery_entry_ctxs)) {
				struct discovery_entry_ctx *entry_ctx;

				entry_ctx = TAILQ_FIRST(&ctx->discovery_entry_ctxs);
				TAILQ_REMOVE(&ctx->discovery_entry_ctxs, entry_ctx, tailq);
				free(entry_ctx);
			}
			stop_discovery(ctx, cb_fn, cb_ctx);
			return 0;
		}
	}