Commit 5ebc9350 authored by Ben Walker's avatar Ben Walker Committed by Tomasz Zawadzki
Browse files

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: default avatarBen Walker <benjamin.walker@intel.com>
Change-Id: I41a6877b782cb927d9ac7d206ccd36a8195efc42
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4346


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
parent ed1b7852
Loading
Loading
Loading
Loading
+5 −40
Original line number Diff line number Diff line
@@ -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;
	}

	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;
	g_conns_array = calloc(MAX_ISCSI_CONNECTIONS, sizeof(struct spdk_iscsi_conn));
	if (g_conns_array == NULL) {
		return -ENOMEM;
	}

	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
+0 −2
Original line number Diff line number Diff line
@@ -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);

+0 −1
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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