lib/iscsi: Remove dry run processing from portal config file parsing

Dry run processing in iscsi_parse_portal() now only checks if
portal string is not NULL. Portals are managed not by fixed size
array but linked list now. Hence dry run processing is not needed
itself now.

So remove the dry_run parameter from iscsi_parse_portal() and
the dry run loop in iscsi_parse_portal_grp().

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ib7cb444b51581b8ee603388aad34bc58d1cc9023
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/493
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-01-19 23:43:04 -05:00 committed by Tomasz Zawadzki
parent 16724dc135
commit aefe3fe23c
2 changed files with 34 additions and 68 deletions

View File

@ -215,8 +215,7 @@ iscsi_portal_close(struct spdk_iscsi_portal *p)
}
static int
iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip,
int dry_run)
iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip)
{
char *host = NULL, *port = NULL;
int len, rc = -1;
@ -244,46 +243,38 @@ iscsi_parse_portal(const char *portalstring, struct spdk_iscsi_portal **ip,
}
}
if (!dry_run) {
len = p - portalstring;
host = malloc(len + 1);
if (host == NULL) {
SPDK_ERRLOG("malloc() failed for host\n");
goto error_out;
}
memcpy(host, portalstring, len);
host[len] = '\0';
len = p - portalstring;
host = malloc(len + 1);
if (host == NULL) {
SPDK_ERRLOG("malloc() failed for host\n");
goto error_out;
}
memcpy(host, portalstring, len);
host[len] = '\0';
/* Port number (IPv4 and IPv6 are the same) */
if (p[0] == '\0') {
if (!dry_run) {
port = malloc(PORTNUMSTRLEN);
if (!port) {
SPDK_ERRLOG("malloc() failed for port\n");
goto error_out;
}
snprintf(port, PORTNUMSTRLEN, "%d", DEFAULT_PORT);
}
} else {
if (!dry_run) {
p++;
len = strlen(p);
port = malloc(len + 1);
if (port == NULL) {
SPDK_ERRLOG("malloc() failed for port\n");
goto error_out;
}
memcpy(port, p, len);
port[len] = '\0';
}
}
if (!dry_run) {
*ip = spdk_iscsi_portal_create(host, port);
if (!*ip) {
port = malloc(PORTNUMSTRLEN);
if (!port) {
SPDK_ERRLOG("malloc() failed for port\n");
goto error_out;
}
snprintf(port, PORTNUMSTRLEN, "%d", DEFAULT_PORT);
} else {
p++;
len = strlen(p);
port = malloc(len + 1);
if (port == NULL) {
SPDK_ERRLOG("malloc() failed for port\n");
goto error_out;
}
memcpy(port, p, len);
port[len] = '\0';
}
*ip = spdk_iscsi_portal_create(host, port);
if (!*ip) {
goto error_out;
}
rc = 0;
@ -389,7 +380,7 @@ iscsi_parse_portal_grp(struct spdk_conf_section *sp)
struct spdk_iscsi_portal *p;
const char *val;
char *label, *portal;
int portals = 0, i = 0, rc = 0;
int i = 0, rc = 0;
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "add portal group (from config file) %d\n",
spdk_conf_section_get_num(sp));
@ -399,38 +390,13 @@ iscsi_parse_portal_grp(struct spdk_conf_section *sp)
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "Comment %s\n", val);
}
/* counts number of definitions */
for (i = 0; ; i++) {
/*
* label is no longer used, but we keep it in the config
* file definition so that we do not break existing config
* files.
*/
label = spdk_conf_section_get_nmval(sp, "Portal", i, 0);
portal = spdk_conf_section_get_nmval(sp, "Portal", i, 1);
if (label == NULL || portal == NULL) {
break;
}
rc = iscsi_parse_portal(portal, &p, 1);
if (rc < 0) {
SPDK_ERRLOG("parse portal error (%s)\n", portal);
return -1;
}
}
portals = i;
if (portals > MAX_PORTAL) {
SPDK_ERRLOG("%d > MAX_PORTAL\n", portals);
return -1;
}
pg = spdk_iscsi_portal_grp_create(spdk_conf_section_get_num(sp));
if (!pg) {
SPDK_ERRLOG("portal group malloc error (%s)\n", spdk_conf_section_get_name(sp));
return -1;
}
for (i = 0; i < portals; i++) {
for (i = 0; ; i++) {
label = spdk_conf_section_get_nmval(sp, "Portal", i, 0);
portal = spdk_conf_section_get_nmval(sp, "Portal", i, 1);
if (label == NULL || portal == NULL) {
@ -438,7 +404,7 @@ iscsi_parse_portal_grp(struct spdk_conf_section *sp)
goto error;
}
rc = iscsi_parse_portal(portal, &p, 0);
rc = iscsi_parse_portal(portal, &p);
if (rc < 0) {
SPDK_ERRLOG("parse portal error (%s)\n", portal);
goto error;

View File

@ -147,7 +147,7 @@ parse_portal_ipv4_normal_case(void)
struct spdk_iscsi_portal *p = NULL;
int rc;
rc = iscsi_parse_portal(string, &p, 0);
rc = iscsi_parse_portal(string, &p);
CU_ASSERT(rc == 0);
SPDK_CU_ASSERT_FATAL(p != NULL);
CU_ASSERT(strcmp(p->host, host_str) == 0);
@ -167,7 +167,7 @@ parse_portal_ipv6_normal_case(void)
struct spdk_iscsi_portal *p = NULL;
int rc;
rc = iscsi_parse_portal(string, &p, 0);
rc = iscsi_parse_portal(string, &p);
CU_ASSERT(rc == 0);
SPDK_CU_ASSERT_FATAL(p != NULL);
CU_ASSERT(strcmp(p->host, host_str) == 0);
@ -186,7 +186,7 @@ parse_portal_ipv4_skip_port_case(void)
struct spdk_iscsi_portal *p = NULL;
int rc;
rc = iscsi_parse_portal(string, &p, 0);
rc = iscsi_parse_portal(string, &p);
CU_ASSERT(rc == 0);
SPDK_CU_ASSERT_FATAL(p != NULL);
CU_ASSERT(strcmp(p->host, host_str) == 0);
@ -205,7 +205,7 @@ parse_portal_ipv6_skip_port_case(void)
struct spdk_iscsi_portal *p = NULL;
int rc;
rc = iscsi_parse_portal(string, &p, 0);
rc = iscsi_parse_portal(string, &p);
CU_ASSERT(rc == 0);
SPDK_CU_ASSERT_FATAL(p != NULL);
CU_ASSERT(strcmp(p->host, host_str) == 0);