From 02b640bfdfc53bcf2af10b140988419abf585b62 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Fri, 18 Aug 2017 15:26:41 -0700 Subject: [PATCH] nvmf: Add a pointer to the target to the subsystem This eliminates a couple of references to g_nvmf_tgt and sets the stage for eliminating that global entirely in the future. Change-Id: I068d0874cc8ba122be780e8dbd55bb1efabe10b7 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/374876 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- lib/nvmf/ctrlr.c | 13 ++++++++----- lib/nvmf/nvmf_internal.h | 2 ++ lib/nvmf/subsystem.c | 16 +++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index 9417ab31c..95aacb658 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -59,7 +59,10 @@ spdk_nvmf_ctrlr_create(struct spdk_nvmf_subsystem *subsystem, struct spdk_nvmf_fabric_connect_cmd *connect_cmd, struct spdk_nvmf_fabric_connect_data *connect_data) { - struct spdk_nvmf_ctrlr *ctrlr; + struct spdk_nvmf_ctrlr *ctrlr; + struct spdk_nvmf_tgt *tgt; + + tgt = subsystem->tgt; ctrlr = calloc(1, sizeof(*ctrlr)); if (ctrlr == NULL) { @@ -88,7 +91,7 @@ spdk_nvmf_ctrlr_create(struct spdk_nvmf_subsystem *subsystem, ctrlr->async_event_config.raw = 0; ctrlr->num_qpairs = 0; ctrlr->subsys = subsystem; - ctrlr->max_qpairs_allowed = g_nvmf_tgt.opts.max_qpairs_per_ctrlr; + ctrlr->max_qpairs_allowed = tgt->opts.max_qpairs_per_ctrlr; memcpy(ctrlr->hostid, connect_data->hostid, sizeof(ctrlr->hostid)); @@ -100,7 +103,7 @@ spdk_nvmf_ctrlr_create(struct spdk_nvmf_subsystem *subsystem, ctrlr->vcprop.cap.raw = 0; ctrlr->vcprop.cap.bits.cqr = 1; /* NVMe-oF specification required */ - ctrlr->vcprop.cap.bits.mqes = g_nvmf_tgt.opts.max_queue_depth - 1; /* max queue depth */ + ctrlr->vcprop.cap.bits.mqes = tgt->opts.max_queue_depth - 1; /* max queue depth */ ctrlr->vcprop.cap.bits.ams = 0; /* optional arb mechanisms */ ctrlr->vcprop.cap.bits.to = 1; /* ready timeout - 500 msec units */ ctrlr->vcprop.cap.bits.dstrd = 0; /* fixed to 0 for NVMe-oF */ @@ -235,9 +238,9 @@ spdk_nvmf_ctrlr_connect(struct spdk_nvmf_qpair *qpair, * SQSIZE is a 0-based value, so it must be at least 1 (minimum queue depth is 2) and * strictly less than max_queue_depth. */ - if (cmd->sqsize == 0 || cmd->sqsize >= g_nvmf_tgt.opts.max_queue_depth) { + if (cmd->sqsize == 0 || cmd->sqsize >= subsystem->tgt->opts.max_queue_depth) { SPDK_ERRLOG("Invalid SQSIZE %u (min 1, max %u)\n", - cmd->sqsize, g_nvmf_tgt.opts.max_queue_depth - 1); + cmd->sqsize, subsystem->tgt->opts.max_queue_depth - 1); INVALID_CONNECT_CMD(sqsize); return; } diff --git a/lib/nvmf/nvmf_internal.h b/lib/nvmf/nvmf_internal.h index 3f3730493..76e81e572 100644 --- a/lib/nvmf/nvmf_internal.h +++ b/lib/nvmf/nvmf_internal.h @@ -86,6 +86,8 @@ struct spdk_nvmf_subsystem { enum spdk_nvmf_subtype subtype; bool is_removed; + struct spdk_nvmf_tgt *tgt; + char sn[MAX_SN_LEN + 1]; struct spdk_nvmf_ns ns[MAX_VIRTUAL_NAMESPACE]; diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index 597dd8e22..53dbfc6c4 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -165,9 +165,11 @@ spdk_nvmf_create_subsystem(const char *nqn, return NULL; } - g_nvmf_tgt.current_subsystem_id++; + subsystem->tgt = &g_nvmf_tgt; - subsystem->id = g_nvmf_tgt.current_subsystem_id; + subsystem->tgt->current_subsystem_id++; + + subsystem->id = subsystem->tgt->current_subsystem_id; subsystem->subtype = type; subsystem->cb_ctx = cb_ctx; subsystem->connect_cb = connect_cb; @@ -177,8 +179,8 @@ spdk_nvmf_create_subsystem(const char *nqn, TAILQ_INIT(&subsystem->hosts); TAILQ_INIT(&subsystem->ctrlrs); - TAILQ_INSERT_TAIL(&g_nvmf_tgt.subsystems, subsystem, entries); - g_nvmf_tgt.discovery_genctr++; + TAILQ_INSERT_TAIL(&subsystem->tgt->subsystems, subsystem, entries); + subsystem->tgt->discovery_genctr++; return subsystem; } @@ -213,8 +215,8 @@ spdk_nvmf_delete_subsystem(struct spdk_nvmf_subsystem *subsystem) spdk_nvmf_subsystem_bdev_detach(subsystem); - TAILQ_REMOVE(&g_nvmf_tgt.subsystems, subsystem, entries); - g_nvmf_tgt.discovery_genctr++; + TAILQ_REMOVE(&subsystem->tgt->subsystems, subsystem, entries); + subsystem->tgt->discovery_genctr++; free(subsystem); } @@ -240,7 +242,7 @@ spdk_nvmf_subsystem_add_host(struct spdk_nvmf_subsystem *subsystem, const char * } TAILQ_INSERT_HEAD(&subsystem->hosts, host, link); - g_nvmf_tgt.discovery_genctr++; + subsystem->tgt->discovery_genctr++; return 0; }