iscsi: Change the ordering to alloc string of options at initialization

In JSON-RPC, string is allocated unconditionally in decode operation.
Hence if string is allocated in opts_init(), it will be overwritten without
any notice.

This patch is to keep compatibility to the config file and adjust to the
upcoming JSON-RPC for options initialization.

Change-Id: I6c16f2af7f34d052aabceb5bc4ebe2fc9d82714a
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/407846
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-05-04 11:32:43 +09:00 committed by Jim Harris
parent c512303c30
commit 24cf63c47a

View File

@ -589,8 +589,8 @@ spdk_iscsi_opts_init(struct spdk_iscsi_opts *opts)
opts->req_discovery_auth = false;
opts->req_discovery_auth_mutual = false;
opts->discovery_auth_group = 0;
opts->authfile = strdup(SPDK_ISCSI_DEFAULT_AUTHFILE);
opts->nodebase = strdup(SPDK_ISCSI_DEFAULT_NODEBASE);
opts->authfile = NULL;
opts->nodebase = NULL;
opts->min_connections_per_core = DEFAULT_CONNECTIONS_PER_LCORE;
}
@ -601,7 +601,7 @@ spdk_iscsi_opts_free(struct spdk_iscsi_opts *opts)
free(opts->nodebase);
}
static void
static int
spdk_iscsi_read_config_file_params(struct spdk_conf_section *sp,
struct spdk_iscsi_opts *opts)
{
@ -625,14 +625,21 @@ spdk_iscsi_read_config_file_params(struct spdk_conf_section *sp,
val = spdk_conf_section_get_val(sp, "AuthFile");
if (val != NULL) {
free(opts->authfile);
opts->authfile = strdup(val);
if (!opts->authfile) {
SPDK_ERRLOG("strdup() failed for AuthFile\n");
return -ENOMEM;
}
}
val = spdk_conf_section_get_val(sp, "NodeBase");
if (val != NULL) {
free(opts->nodebase);
opts->nodebase = strdup(val);
if (!opts->nodebase) {
free(opts->authfile);
SPDK_ERRLOG("strdup() failed for NodeBase\n");
return -ENOMEM;
}
}
MaxSessions = spdk_conf_section_get_intval(sp, "MaxSessions");
@ -722,19 +729,27 @@ spdk_iscsi_read_config_file_params(struct spdk_conf_section *sp,
if (min_conn_per_core >= 0) {
opts->min_connections_per_core = min_conn_per_core;
}
return 0;
}
static int
spdk_iscsi_opts_verify(struct spdk_iscsi_opts *opts)
{
if (!opts->authfile) {
SPDK_ERRLOG("opts->authfile is NULL\n");
return -EINVAL;
opts->authfile = strdup(SPDK_ISCSI_DEFAULT_AUTHFILE);
if (opts->authfile == NULL) {
SPDK_ERRLOG("strdup() failed for default authfile\n");
return -ENOMEM;
}
}
if (!opts->nodebase) {
SPDK_ERRLOG("opts->nodebase is NULL\n");
return -EINVAL;
opts->nodebase = strdup(SPDK_ISCSI_DEFAULT_NODEBASE);
if (opts->nodebase == NULL) {
SPDK_ERRLOG("strdup() failed for default nodebase\n");
return -ENOMEM;
}
}
if (opts->MaxSessions == 0 || opts->MaxSessions > 65535) {
@ -851,7 +866,11 @@ spdk_iscsi_initialize_global_params(void)
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_iscsi_read_config_file_parmas\n");
sp = spdk_conf_find_section(NULL, "iSCSI");
if (sp != NULL) {
spdk_iscsi_read_config_file_params(sp, &opts);
rc = spdk_iscsi_read_config_file_params(sp, &opts);
if (rc != 0) {
SPDK_ERRLOG("spdk_iscsi_read_config_file_params() failed\n");
return rc;
}
}
rc = spdk_iscsi_set_global_params(&opts);