iscsi: Don't ignore wrong value of parameters at initialization

In the current implementation, even if global parameters in the config file
are wrong, they are ignored and default values are applied.

Now JSON config file is under development and is a good chance to break with
past and change to reject wrong parameters.

This patch add verify() function into spdk_iscsi_initialize_iscsi_globals().

Besides, this patch fixes the return code of iscsi_initialize_global_params().

Change-Id: I708a1537746fe6ce22c36d1442f7eaf2a201830e
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/406021
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>
This commit is contained in:
Shuhei Matsumoto 2018-05-04 11:20:40 +09:00 committed by Jim Harris
parent 8712f366e0
commit c512303c30

View File

@ -637,53 +637,26 @@ spdk_iscsi_read_config_file_params(struct spdk_conf_section *sp,
MaxSessions = spdk_conf_section_get_intval(sp, "MaxSessions");
if (MaxSessions >= 0) {
if (MaxSessions == 0) {
SPDK_ERRLOG("MaxSessions == 0 invalid, ignoring\n");
} else if (MaxSessions > 65535) {
SPDK_ERRLOG("MaxSessions == %d invalid, ignoring\n", MaxSessions);
} else {
opts->MaxSessions = MaxSessions;
}
opts->MaxSessions = MaxSessions;
}
MaxConnectionsPerSession = spdk_conf_section_get_intval(sp, "MaxConnectionsPerSession");
if (MaxConnectionsPerSession >= 0) {
if (MaxConnectionsPerSession == 0) {
SPDK_ERRLOG("MaxConnectionsPerSession == 0 invalid, ignoring\n");
} else if (MaxConnectionsPerSession > 65535) {
SPDK_ERRLOG("MaxConnectionsPerSession == %d invalid, ignoring\n",
MaxConnectionsPerSession);
} else {
opts->MaxConnectionsPerSession = MaxConnectionsPerSession;
}
opts->MaxConnectionsPerSession = MaxConnectionsPerSession;
}
MaxQueueDepth = spdk_conf_section_get_intval(sp, "MaxQueueDepth");
if (MaxQueueDepth >= 0) {
if (MaxQueueDepth == 0) {
SPDK_ERRLOG("MaxQueueDepth == 0 invalid, ignoring\n");
} else if (MaxQueueDepth > 256) {
SPDK_ERRLOG("MaxQueueDepth == %d invalid, ignoring\n", MaxQueueDepth);
} else {
opts->MaxQueueDepth = MaxQueueDepth;
}
opts->MaxQueueDepth = MaxQueueDepth;
}
DefaultTime2Wait = spdk_conf_section_get_intval(sp, "DefaultTime2Wait");
if (DefaultTime2Wait >= 0) {
if (DefaultTime2Wait > 3600) {
SPDK_ERRLOG("DefaultTime2Wait == %d invalid, ignoring\n", DefaultTime2Wait);
} else {
opts->DefaultTime2Wait = DefaultTime2Wait;
}
opts->DefaultTime2Wait = DefaultTime2Wait;
}
DefaultTime2Retain = spdk_conf_section_get_intval(sp, "DefaultTime2Retain");
if (DefaultTime2Retain >= 0) {
if (DefaultTime2Retain > 3600) {
SPDK_ERRLOG("DefaultTime2Retain == %d invalid, ignoring\n", DefaultTime2Retain);
} else {
opts->DefaultTime2Retain = DefaultTime2Retain;
}
opts->DefaultTime2Retain = DefaultTime2Retain;
}
opts->ImmediateData = spdk_conf_section_get_boolval(sp, "ImmediateData",
opts->ImmediateData);
@ -697,12 +670,7 @@ spdk_iscsi_read_config_file_params(struct spdk_conf_section *sp,
ErrorRecoveryLevel = spdk_conf_section_get_intval(sp, "ErrorRecoveryLevel");
if (ErrorRecoveryLevel >= 0) {
if (ErrorRecoveryLevel > 2) {
SPDK_ERRLOG("ErrorRecoveryLevel %d not supported, keeping existing %d\n",
ErrorRecoveryLevel, opts->ErrorRecoveryLevel);
} else {
opts->ErrorRecoveryLevel = ErrorRecoveryLevel;
}
opts->ErrorRecoveryLevel = ErrorRecoveryLevel;
}
timeout = spdk_conf_section_get_intval(sp, "Timeout");
if (timeout >= 0) {
@ -710,11 +678,7 @@ spdk_iscsi_read_config_file_params(struct spdk_conf_section *sp,
}
nopininterval = spdk_conf_section_get_intval(sp, "NopInInterval");
if (nopininterval >= 0) {
if (nopininterval > MAX_NOPININTERVAL) {
SPDK_ERRLOG("NopInInterval == %d invalid, ignoring\n", nopininterval);
} else {
opts->nopininterval = nopininterval;
}
opts->nopininterval = nopininterval;
}
val = spdk_conf_section_get_val(sp, "DiscoveryAuthMethod");
if (val != NULL) {
@ -761,7 +725,7 @@ spdk_iscsi_read_config_file_params(struct spdk_conf_section *sp,
}
static int
spdk_iscsi_set_global_params(struct spdk_iscsi_opts *opts)
spdk_iscsi_opts_verify(struct spdk_iscsi_opts *opts)
{
if (!opts->authfile) {
SPDK_ERRLOG("opts->authfile is NULL\n");
@ -773,6 +737,52 @@ spdk_iscsi_set_global_params(struct spdk_iscsi_opts *opts)
return -EINVAL;
}
if (opts->MaxSessions == 0 || opts->MaxSessions > 65535) {
SPDK_ERRLOG("%d is invalid. MaxSessions must be more than 0 and no more than 65535\n",
opts->MaxSessions);
return -EINVAL;
}
if (opts->MaxConnectionsPerSession == 0 || opts->MaxConnectionsPerSession > 65535) {
SPDK_ERRLOG("%d is invalid. MaxConnectionsPerSession must be more than 0 and no more than 65535\n",
opts->MaxConnectionsPerSession);
return -EINVAL;
}
if (opts->MaxQueueDepth == 0 || opts->MaxQueueDepth > 256) {
SPDK_ERRLOG("%d is invalid. MaxQueueDepth must be more than 0 and no more than 256\n",
opts->MaxQueueDepth);
return -EINVAL;
}
if (opts->DefaultTime2Wait > 3600) {
SPDK_ERRLOG("%d is invalid. DefaultTime2Wait must be no more than 3600\n",
opts->DefaultTime2Wait);
return -EINVAL;
}
if (opts->DefaultTime2Retain > 3600) {
SPDK_ERRLOG("%d is invalid. DefaultTime2Retain must be no more than 3600\n",
opts->DefaultTime2Retain);
return -EINVAL;
}
if (opts->ErrorRecoveryLevel > 2) {
SPDK_ERRLOG("ErrorRecoveryLevel %d is not supported.\n", opts->ErrorRecoveryLevel);
return -EINVAL;
}
if (opts->timeout < 0) {
SPDK_ERRLOG("%d is invalid. timeout must not be less than 0\n", opts->timeout);
return -EINVAL;
}
if (opts->nopininterval < 0 || opts->nopininterval > MAX_NOPININTERVAL) {
SPDK_ERRLOG("%d is invalid. nopinterval must be between 0 and %d\n",
opts->nopininterval, MAX_NOPININTERVAL);
return -EINVAL;
}
if (!spdk_iscsi_check_chap_params(opts->no_discovery_auth, opts->req_discovery_auth,
opts->req_discovery_auth_mutual,
opts->discovery_auth_group)) {
@ -780,6 +790,20 @@ spdk_iscsi_set_global_params(struct spdk_iscsi_opts *opts)
return -EINVAL;
}
return 0;
}
static int
spdk_iscsi_set_global_params(struct spdk_iscsi_opts *opts)
{
int rc;
rc = spdk_iscsi_opts_verify(opts);
if (rc != 0) {
SPDK_ERRLOG("spdk_iscsi_opts_verify() failed\n");
return rc;
}
g_spdk_iscsi.authfile = strdup(opts->authfile);
if (!g_spdk_iscsi.authfile) {
SPDK_ERRLOG("failed to strdup for auth file %s\n", opts->authfile);
@ -836,7 +860,7 @@ spdk_iscsi_initialize_global_params(void)
SPDK_ERRLOG("spdk_iscsi_set_global_params() failed\n");
}
return 0;
return rc;
}
static void