From d028fb695697723d93ff131e7715b0e7a671a540 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 7 Jul 2016 16:08:48 -0700 Subject: [PATCH] nvmf: Eliminate two stage initialization of sessions Everything can be done when the session is created. Change-Id: I7cb38c093b2b1b69460cabba465828eed0cec432 Signed-off-by: Ben Walker --- lib/nvmf/conn.c | 8 ----- lib/nvmf/conn.h | 5 --- lib/nvmf/request.c | 12 +++---- lib/nvmf/session.c | 89 ++++++++++++++++++++++++---------------------- lib/nvmf/session.h | 3 -- 5 files changed, 51 insertions(+), 66 deletions(-) diff --git a/lib/nvmf/conn.c b/lib/nvmf/conn.c index 1c7b8ae65b..de0c98590e 100644 --- a/lib/nvmf/conn.c +++ b/lib/nvmf/conn.c @@ -302,14 +302,6 @@ void spdk_shutdown_nvmf_conns(void) rte_get_master_lcore(), spdk_nvmf_conn_check_shutdown, NULL); } -void -nvmf_init_conn_properites(struct spdk_nvmf_conn *conn, - struct nvmf_session *session, - struct spdk_nvmf_fabric_connect_rsp *response) -{ - nvmf_init_session_properties(session); -} - static void spdk_nvmf_conn_do_work(void *arg) { diff --git a/lib/nvmf/conn.h b/lib/nvmf/conn.h index 3dd298c2a6..04420b29fe 100644 --- a/lib/nvmf/conn.h +++ b/lib/nvmf/conn.h @@ -79,11 +79,6 @@ void spdk_shutdown_nvmf_conns(void); struct spdk_nvmf_conn * spdk_nvmf_allocate_conn(void); -void -nvmf_init_conn_properites(struct spdk_nvmf_conn *conn, - struct nvmf_session *session, - struct spdk_nvmf_fabric_connect_rsp *response); - int spdk_nvmf_startup_conn(struct spdk_nvmf_conn *conn); #endif /* NVMF_CONN_H */ diff --git a/lib/nvmf/request.c b/lib/nvmf/request.c index b4fcb15401..e1974dd694 100644 --- a/lib/nvmf/request.c +++ b/lib/nvmf/request.c @@ -403,7 +403,6 @@ nvmf_process_connect(struct spdk_nvmf_request *req) struct spdk_nvmf_fabric_connect_data *connect_data; struct spdk_nvmf_fabric_connect_rsp *response; struct spdk_nvmf_conn *conn = req->conn; - struct nvmf_session *session; if (req->length < sizeof(struct spdk_nvmf_fabric_connect_data)) { SPDK_ERRLOG("Connect command data length 0x%x too small\n", req->length); @@ -441,12 +440,11 @@ nvmf_process_connect(struct spdk_nvmf_request *req) conn->type = CONN_TYPE_AQ; } - session = nvmf_connect(conn, connect, connect_data, response); - if (session != NULL) { - conn->sess = session; - if (conn->type == CONN_TYPE_AQ) { - nvmf_init_conn_properites(conn, session, response); - } + conn->sess = nvmf_connect(conn, connect, connect_data, response); + if (!conn->sess) { + SPDK_ERRLOG("Unable to allocate session\n"); + req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR; + return true; } /* Allocate RDMA reqs according to the queue depth and conn type*/ diff --git a/lib/nvmf/session.c b/lib/nvmf/session.c index 8a0c073cb3..8a03d63d17 100644 --- a/lib/nvmf/session.c +++ b/lib/nvmf/session.c @@ -40,48 +40,6 @@ #include "spdk/trace.h" #include "spdk/nvme_spec.h" -static struct nvmf_session * -nvmf_create_session(const char *subnqn) -{ - struct nvmf_session *session; - struct spdk_nvmf_subsystem *subsystem; - - SPDK_TRACELOG(SPDK_TRACE_NVMF, "nvmf_create_session:\n"); - - /* locate the previously provisioned subsystem */ - subsystem = nvmf_find_subsystem(subnqn); - if (subsystem == NULL) - return NULL; - - session = calloc(1, sizeof(struct nvmf_session)); - if (session == NULL) - goto exit; - - subsystem->num_sessions++; - session->cntlid = 0; /* Subsystems only have one controller by design, so cntlid is 0 */ - TAILQ_INSERT_HEAD(&subsystem->sessions, session, entries); - - SPDK_TRACELOG(SPDK_TRACE_NVMF, "nvmf_create_session: allocated session cntlid %d\n", - session->cntlid); - TAILQ_INIT(&session->connections); - session->num_connections = 0; - session->is_valid = 1; - session->subsys = subsystem; - session->max_connections_allowed = g_nvmf_tgt.MaxConnectionsPerSession; - -exit: - return session; -} - -static void -nvmf_delete_session(struct nvmf_session *session) -{ - session->subsys->num_sessions--; - TAILQ_REMOVE(&session->subsys->sessions, session, entries); - - free(session); -} - static void nvmf_init_discovery_session_properties(struct nvmf_session *session) { @@ -202,7 +160,7 @@ nvmf_init_nvme_session_properties(struct nvmf_session *session) session->vcprop.csts.raw); } -void +static void nvmf_init_session_properties(struct nvmf_session *session) { if (session->subsys->subtype == SPDK_NVMF_SUB_NVME) { @@ -212,6 +170,51 @@ nvmf_init_session_properties(struct nvmf_session *session) } } +static struct nvmf_session * +nvmf_create_session(const char *subnqn) +{ + struct nvmf_session *session; + struct spdk_nvmf_subsystem *subsystem; + + SPDK_TRACELOG(SPDK_TRACE_NVMF, "nvmf_create_session:\n"); + + /* locate the previously provisioned subsystem */ + subsystem = nvmf_find_subsystem(subnqn); + if (subsystem == NULL) { + return NULL; + } + + session = calloc(1, sizeof(struct nvmf_session)); + if (session == NULL) { + return NULL; + } + + subsystem->num_sessions++; + session->cntlid = 0; /* Subsystems only have one controller by design, so cntlid is 0 */ + TAILQ_INSERT_HEAD(&subsystem->sessions, session, entries); + + SPDK_TRACELOG(SPDK_TRACE_NVMF, "nvmf_create_session: allocated session cntlid %d\n", + session->cntlid); + TAILQ_INIT(&session->connections); + session->num_connections = 0; + session->is_valid = 1; + session->subsys = subsystem; + session->max_connections_allowed = g_nvmf_tgt.MaxConnectionsPerSession; + + nvmf_init_session_properties(session); + + return session; +} + +static void +nvmf_delete_session(struct nvmf_session *session) +{ + session->subsys->num_sessions--; + TAILQ_REMOVE(&session->subsys->sessions, session, entries); + + free(session); +} + static struct nvmf_session * nvmf_find_session_by_id(const char *subnqn, uint16_t cntl_id) { diff --git a/lib/nvmf/session.h b/lib/nvmf/session.h index cb1c4c3415..7da7196207 100644 --- a/lib/nvmf/session.h +++ b/lib/nvmf/session.h @@ -83,9 +83,6 @@ nvmf_connect(struct spdk_nvmf_conn *conn, void nvmf_disconnect(struct nvmf_session *session, struct spdk_nvmf_conn *conn); -void -nvmf_init_session_properties(struct nvmf_session *session); - void nvmf_property_get(struct nvmf_session *session, struct spdk_nvmf_fabric_prop_get_cmd *cmd,