iscsi: do static initialization of globals that allow it

Change-Id: If6db1fbdcf45f689e315c769ded0e0d8cd90aafd
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/407206
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Pawel Wodkowski 2018-04-06 17:10:30 +02:00 committed by Daniel Verkamp
parent 3142d978c3
commit e548df4ed1
3 changed files with 9 additions and 24 deletions

View File

@ -63,15 +63,12 @@ static uint32_t *g_num_connections;
struct spdk_iscsi_conn *g_conns_array = MAP_FAILED;
static char g_shm_name[64];
static pthread_mutex_t g_conns_mutex;
static pthread_mutex_t g_conns_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct spdk_poller *g_shutdown_timer = NULL;
static uint32_t spdk_iscsi_conn_allocate_reactor(const struct spdk_cpuset *cpumask);
void spdk_iscsi_conn_login_do_work(void *arg);
void spdk_iscsi_conn_full_feature_do_work(void *arg);
static void spdk_iscsi_conn_full_feature_migrate(void *arg1, void *arg2);
static void spdk_iscsi_conn_stop(struct spdk_iscsi_conn *conn);
static void spdk_iscsi_conn_sock_cb(void *arg, struct spdk_sock_group *group,
@ -119,17 +116,11 @@ spdk_find_iscsi_connection_by_id(int cid)
int spdk_initialize_iscsi_conns(void)
{
size_t conns_size = sizeof(struct spdk_iscsi_conn) * MAX_ISCSI_CONNECTIONS;
int conns_array_fd, rc;
int conns_array_fd;
uint32_t i, last_core;
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_iscsi_init\n");
rc = pthread_mutex_init(&g_conns_mutex, NULL);
if (rc != 0) {
SPDK_ERRLOG("mutex_init() failed\n");
return -1;
}
snprintf(g_shm_name, sizeof(g_shm_name), "/spdk_iscsi_conns.%d", spdk_app_get_shm_id());
conns_array_fd = shm_open(g_shm_name, O_RDWR | O_CREAT, 0600);
if (conns_array_fd < 0) {
@ -176,7 +167,6 @@ err:
shm_unlink(g_shm_name);
}
pthread_mutex_destroy(&g_conns_mutex);
return -1;
}

View File

@ -66,7 +66,13 @@
#define HAVE_ARC4RANDOM 1
#endif
struct spdk_iscsi_globals g_spdk_iscsi;
struct spdk_iscsi_globals g_spdk_iscsi = {
.mutex = PTHREAD_MUTEX_INITIALIZER,
.portal_head = TAILQ_HEAD_INITIALIZER(g_spdk_iscsi.portal_head),
.pg_head = TAILQ_HEAD_INITIALIZER(g_spdk_iscsi.pg_head),
.ig_head = TAILQ_HEAD_INITIALIZER(g_spdk_iscsi.ig_head),
.target_head = TAILQ_HEAD_INITIALIZER(g_spdk_iscsi.target_head),
};
/* random value generation */
static void spdk_gen_random(uint8_t *buf, size_t len);

View File

@ -825,23 +825,12 @@ spdk_iscsi_initialize_iscsi_globals(struct spdk_iscsi_opts *opts)
*/
g_spdk_iscsi.MaxConnections = g_spdk_iscsi.MaxSessions;
rc = pthread_mutex_init(&g_spdk_iscsi.mutex, NULL);
if (rc != 0) {
SPDK_ERRLOG("mutex_init() failed\n");
return -1;
}
rc = spdk_iscsi_initialize_all_pools();
if (rc != 0) {
SPDK_ERRLOG("spdk_initialize_all_pools() failed\n");
return -1;
}
TAILQ_INIT(&g_spdk_iscsi.portal_head);
TAILQ_INIT(&g_spdk_iscsi.pg_head);
TAILQ_INIT(&g_spdk_iscsi.ig_head);
TAILQ_INIT(&g_spdk_iscsi.target_head);
spdk_iscsi_log_globals();
return 0;