From 5ebc93507b358416b2c312f16c47ae9f8a1f27ce Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Wed, 23 Sep 2020 10:37:48 -0700 Subject: [PATCH] iscsi: Allocate connections array from regular memory No longer required to allocate from shared memory. No tools use this anymore. This removes the final call to the event library from iscsi, so we also drop that dependency. Signed-off-by: Ben Walker Change-Id: I41a6877b782cb927d9ac7d206ccd36a8195efc42 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4346 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk --- lib/iscsi/conn.c | 45 +++++-------------------------------- lib/iscsi/conn.h | 2 -- lib/iscsi/iscsi_subsystem.c | 1 - mk/spdk.lib_deps.mk | 2 +- 4 files changed, 6 insertions(+), 44 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index 5038afb57..5e3769eec 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -36,7 +36,6 @@ #include "spdk/endian.h" #include "spdk/env.h" -#include "spdk/event.h" #include "spdk/likely.h" #include "spdk/thread.h" #include "spdk/queue.h" @@ -62,9 +61,7 @@ memset(&(conn)->portal, 0, sizeof(*(conn)) - \ offsetof(struct spdk_iscsi_conn, portal)); -struct spdk_iscsi_conn *g_conns_array = MAP_FAILED; -static int g_conns_array_fd = -1; -static char g_shm_name[64]; +static struct spdk_iscsi_conn *g_conns_array = NULL; static TAILQ_HEAD(, spdk_iscsi_conn) g_free_conns = TAILQ_HEAD_INITIALIZER(g_free_conns); static TAILQ_HEAD(, spdk_iscsi_conn) g_active_conns = TAILQ_HEAD_INITIALIZER(g_active_conns); @@ -119,58 +116,26 @@ free_conn(struct spdk_iscsi_conn *conn) static void _iscsi_conns_cleanup(void) { - if (g_conns_array != MAP_FAILED) { - munmap(g_conns_array, sizeof(struct spdk_iscsi_conn) * - MAX_ISCSI_CONNECTIONS); - g_conns_array = MAP_FAILED; - } - - if (g_conns_array_fd >= 0) { - close(g_conns_array_fd); - g_conns_array_fd = -1; - shm_unlink(g_shm_name); - } + free(g_conns_array); } int initialize_iscsi_conns(void) { - size_t conns_size = sizeof(struct spdk_iscsi_conn) * MAX_ISCSI_CONNECTIONS; uint32_t i; SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_iscsi_init\n"); - snprintf(g_shm_name, sizeof(g_shm_name), "/spdk_iscsi_conns.%d", spdk_app_get_shm_id()); - g_conns_array_fd = shm_open(g_shm_name, O_RDWR | O_CREAT, 0600); - if (g_conns_array_fd < 0) { - SPDK_ERRLOG("could not shm_open %s\n", g_shm_name); - goto err; + g_conns_array = calloc(MAX_ISCSI_CONNECTIONS, sizeof(struct spdk_iscsi_conn)); + if (g_conns_array == NULL) { + return -ENOMEM; } - if (ftruncate(g_conns_array_fd, conns_size) != 0) { - SPDK_ERRLOG("could not ftruncate\n"); - goto err; - } - g_conns_array = mmap(0, conns_size, PROT_READ | PROT_WRITE, MAP_SHARED, - g_conns_array_fd, 0); - - if (g_conns_array == MAP_FAILED) { - SPDK_ERRLOG("could not mmap cons array file %s (%d)\n", g_shm_name, errno); - goto err; - } - - memset(g_conns_array, 0, conns_size); - for (i = 0; i < MAX_ISCSI_CONNECTIONS; i++) { g_conns_array[i].id = i; TAILQ_INSERT_TAIL(&g_free_conns, &g_conns_array[i], conn_link); } return 0; - -err: - _iscsi_conns_cleanup(); - - return -1; } static void diff --git a/lib/iscsi/conn.h b/lib/iscsi/conn.h index c1ccb0ffc..9900b5095 100644 --- a/lib/iscsi/conn.h +++ b/lib/iscsi/conn.h @@ -199,8 +199,6 @@ struct spdk_iscsi_conn { TAILQ_ENTRY(spdk_iscsi_conn) conn_link; }; -extern struct spdk_iscsi_conn *g_conns_array; - void iscsi_task_cpl(struct spdk_scsi_task *scsi_task); void iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task); diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index 0f66dcb41..bcf3df149 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -45,7 +45,6 @@ #include "iscsi/task.h" #include "iscsi/tgt_node.h" -#include "spdk_internal/event.h" #include "spdk_internal/log.h" struct spdk_iscsi_opts *g_spdk_iscsi_opts = NULL; diff --git a/mk/spdk.lib_deps.mk b/mk/spdk.lib_deps.mk index d0e3c6df7..98c03d4f9 100644 --- a/mk/spdk.lib_deps.mk +++ b/mk/spdk.lib_deps.mk @@ -86,7 +86,7 @@ DEPDIRS-nvmf += rdma endif DEPDIRS-scsi := log util thread $(JSON_LIBS) trace bdev -DEPDIRS-iscsi := log sock util conf thread $(JSON_LIBS) trace event scsi +DEPDIRS-iscsi := log sock util conf thread $(JSON_LIBS) trace scsi DEPDIRS-vhost = log util conf thread $(JSON_LIBS) bdev scsi ifeq ($(CONFIG_VHOST_INTERNAL_LIB),y) DEPDIRS-vhost += rte_vhost