From 5428fb013364fa9682bd91936401c79be4c5bdf3 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 25 Feb 2022 01:16:40 +0000 Subject: [PATCH] bdev/nvme: add function to create an entry_ctx for discovery This reduces some code duplication since the same function will be reused in an upcoming patch. Signed-off-by: Jim Harris Change-Id: Id6764171ff93c95de49792a4488f2c205b8eddb6 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11769 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Shuhei Matsumoto --- module/bdev/nvme/bdev_nvme.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index aca37e2e4..4be9bda8e 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -4468,6 +4468,24 @@ discovery_attach_controller_done(void *cb_ctx, size_t bdev_count, int rc) } } +static struct discovery_entry_ctx * +create_discovery_entry_ctx(struct discovery_ctx *ctx, struct spdk_nvme_transport_id *trid) +{ + struct discovery_entry_ctx *new_ctx; + + new_ctx = calloc(1, sizeof(*new_ctx)); + if (new_ctx == NULL) { + DISCOVERY_ERRLOG(ctx, "could not allocate new entry_ctx\n"); + return NULL; + } + + new_ctx->ctx = ctx; + memcpy(&new_ctx->trid, trid, sizeof(*trid)); + spdk_nvme_ctrlr_get_default_ctrlr_opts(&new_ctx->drv_opts, sizeof(new_ctx->drv_opts)); + snprintf(new_ctx->drv_opts.hostnqn, sizeof(new_ctx->drv_opts.hostnqn), "%s", ctx->hostnqn); + return new_ctx; +} + static void discovery_log_page_cb(void *cb_arg, int rc, const struct spdk_nvme_cpl *cpl, struct spdk_nvmf_discovery_log_page *log_page) @@ -4495,18 +4513,15 @@ discovery_log_page_cb(void *cb_arg, int rc, const struct spdk_nvme_cpl *cpl, new_entry = &log_page->entries[i]; if (new_entry->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) { struct discovery_entry_ctx *new_ctx; + struct spdk_nvme_transport_id trid; - new_ctx = calloc(1, sizeof(*new_ctx)); + build_trid_from_log_page_entry(&trid, new_entry); + new_ctx = create_discovery_entry_ctx(ctx, &trid); if (new_ctx == NULL) { DISCOVERY_ERRLOG(ctx, "could not allocate new entry_ctx\n"); break; } - new_ctx->ctx = ctx; - memcpy(&new_ctx->entry, new_entry, sizeof(*new_entry)); - build_trid_from_log_page_entry(&new_ctx->trid, new_entry); - spdk_nvme_ctrlr_get_default_ctrlr_opts(&new_ctx->drv_opts, sizeof(new_ctx->drv_opts)); - snprintf(new_ctx->drv_opts.hostnqn, sizeof(new_ctx->drv_opts.hostnqn), "%s", ctx->hostnqn); TAILQ_INSERT_TAIL(&ctx->discovery_entry_ctxs, new_ctx, tailq); continue; }