diff --git a/app/nvmf_tgt/conf.c b/app/nvmf_tgt/conf.c index e5286f0b9..d36649ea8 100644 --- a/app/nvmf_tgt/conf.c +++ b/app/nvmf_tgt/conf.c @@ -437,10 +437,11 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) int i, ret; uint64_t mask; int lcore = 0; + int num = spdk_conf_section_get_num(sp); nqn = spdk_conf_section_get_val(sp, "NQN"); if (nqn == NULL) { - SPDK_ERRLOG("No NQN specified for Subsystem %d\n", sp->num); + SPDK_ERRLOG("No NQN specified for Subsystem %d\n", num); return -1; } @@ -449,7 +450,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) lcore = spdk_conf_section_get_intval(sp, "Core"); if (lcore < 0) { lcore = 0; - for (i = 0; i < sp->num; i++) { + for (i = 0; i < num; i++) { lcore = spdk_nvmf_allocate_lcore(mask, lcore); lcore++; } @@ -458,7 +459,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) mode_str = spdk_conf_section_get_val(sp, "Mode"); if (mode_str == NULL) { - SPDK_ERRLOG("No Mode specified for Subsystem %d\n", sp->num); + SPDK_ERRLOG("No Mode specified for Subsystem %d\n", num); return -1; } @@ -531,7 +532,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) /* Parse NVMe section */ bdf = spdk_conf_section_get_val(sp, "NVMe"); if (bdf == NULL) { - SPDK_ERRLOG("Subsystem %d: missing NVMe directive\n", sp->num); + SPDK_ERRLOG("Subsystem %d: missing NVMe directive\n", num); return -1; } @@ -552,7 +553,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) } if (!ctx.found) { - SPDK_ERRLOG("Could not find NVMe controller for Subsystem%d\n", sp->num); + SPDK_ERRLOG("Could not find NVMe controller for Subsystem%d\n", num); return -1; } } else { @@ -561,7 +562,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) sn = spdk_conf_section_get_val(sp, "SN"); if (sn == NULL) { - SPDK_ERRLOG("Subsystem %d: missing serial number\n", sp->num); + SPDK_ERRLOG("Subsystem %d: missing serial number\n", num); return -1; } if (spdk_nvmf_validate_sn(sn) != 0) { @@ -570,7 +571,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) namespace = spdk_conf_section_get_val(sp, "Namespace"); if (namespace == NULL) { - SPDK_ERRLOG("Subsystem %d: missing Namespace directive\n", sp->num); + SPDK_ERRLOG("Subsystem %d: missing Namespace directive\n", num); return -1; } diff --git a/include/spdk/conf.h b/include/spdk/conf.h index 63beea2ca..284531629 100644 --- a/include/spdk/conf.h +++ b/include/spdk/conf.h @@ -75,6 +75,8 @@ struct spdk_conf_section *spdk_conf_first_section(struct spdk_conf *cp); struct spdk_conf_section *spdk_conf_next_section(struct spdk_conf_section *sp); bool spdk_conf_section_match_prefix(const struct spdk_conf_section *sp, const char *name_prefix); +const char *spdk_conf_section_get_name(const struct spdk_conf_section *sp); +int spdk_conf_section_get_num(const struct spdk_conf_section *sp); char *spdk_conf_section_get_nmval(struct spdk_conf_section *sp, const char *key, int idx1, int idx2); char *spdk_conf_section_get_nval(struct spdk_conf_section *sp, const char *key, int idx); diff --git a/lib/conf/conf.c b/lib/conf/conf.c index 0ed07891f..7af1a93c4 100644 --- a/lib/conf/conf.c +++ b/lib/conf/conf.c @@ -325,6 +325,18 @@ spdk_conf_section_match_prefix(const struct spdk_conf_section *sp, const char *n return strncasecmp(sp->name, name_prefix, strlen(name_prefix)) == 0; } +const char * +spdk_conf_section_get_name(const struct spdk_conf_section *sp) +{ + return sp->name; +} + +int +spdk_conf_section_get_num(const struct spdk_conf_section *sp) +{ + return sp->num; +} + char * spdk_conf_section_get_nmval(struct spdk_conf_section *sp, const char *key, int idx1, int idx2) { diff --git a/lib/event/app.c b/lib/event/app.c index 5c812bde9..47bae056a 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -254,7 +254,7 @@ spdk_app_init(struct spdk_app_opts *opts) fprintf(stderr, "Could not read config file %s\n", opts->config_file); exit(EXIT_FAILURE); } - if (config->section == NULL) { + if (spdk_conf_first_section(config) == NULL) { fprintf(stderr, "Invalid config file %s\n", opts->config_file); exit(EXIT_FAILURE); } diff --git a/lib/iscsi/init_grp.c b/lib/iscsi/init_grp.c index cc7a44d28..7f4f838f8 100644 --- a/lib/iscsi/init_grp.c +++ b/lib/iscsi/init_grp.c @@ -65,8 +65,9 @@ spdk_iscsi_init_grp_create_from_configfile(struct spdk_conf_section *sp) int num_initiator_names; int num_initiator_masks; char **initiators = NULL, **netmasks = NULL; + int tag = spdk_conf_section_get_num(sp); - SPDK_TRACELOG(SPDK_TRACE_DEBUG, "add initiator group %d\n", sp->num); + SPDK_TRACELOG(SPDK_TRACE_DEBUG, "add initiator group %d\n", tag); val = spdk_conf_section_get_val(sp, "Comment"); if (val != NULL) { @@ -145,7 +146,7 @@ spdk_iscsi_init_grp_create_from_configfile(struct spdk_conf_section *sp) } } - rc = spdk_iscsi_init_grp_create_from_initiator_list(sp->num, + rc = spdk_iscsi_init_grp_create_from_initiator_list(tag, num_initiator_names, initiators, num_initiator_masks, netmasks); if (rc < 0) { goto cleanup; @@ -307,7 +308,7 @@ spdk_iscsi_init_grp_array_create(void) sp = spdk_conf_first_section(NULL); while (sp != NULL) { if (spdk_conf_section_match_prefix(sp, "InitiatorGroup")) { - if (sp->num == 0) { + if (spdk_conf_section_get_num(sp) == 0) { SPDK_ERRLOG("Group 0 is invalid\n"); return -1; } diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 9318508ef..f10fe3730 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -700,15 +700,17 @@ spdk_iscsi_chap_get_authinfo(struct iscsi_chap_auth *auth, const char *authfile, } //spdk_conf_print(config); - sp = config->section; + sp = spdk_conf_first_section(config); while (sp != NULL) { if (spdk_conf_section_match_prefix(sp, "AuthGroup")) { - if (sp->num == 0) { + int group = spdk_conf_section_get_num(sp); + + if (group == 0) { SPDK_ERRLOG("Group 0 is invalid\n"); spdk_conf_free(config); return -1; } - if (ag_tag != sp->num) { + if (ag_tag != group) { goto skip_ag_tag; } @@ -742,7 +744,7 @@ spdk_iscsi_chap_get_authinfo(struct iscsi_chap_auth *auth, const char *authfile, } } skip_ag_tag: - sp = sp->next; + sp = spdk_conf_next_section(sp); } spdk_conf_free(config); diff --git a/lib/iscsi/portal_grp.c b/lib/iscsi/portal_grp.c index e5f3be3a8..249664a78 100644 --- a/lib/iscsi/portal_grp.c +++ b/lib/iscsi/portal_grp.c @@ -366,9 +366,10 @@ spdk_iscsi_portal_grp_create_from_configfile(struct spdk_conf_section *sp) const char *val; char *label, *portal; int portals = 0, i = 0, rc = 0; + int tag = spdk_conf_section_get_num(sp); SPDK_TRACELOG(SPDK_TRACE_DEBUG, "add portal group (from config file) %d\n", - sp->num); + tag); val = spdk_conf_section_get_val(sp, "Comment"); if (val != NULL) { @@ -399,9 +400,9 @@ spdk_iscsi_portal_grp_create_from_configfile(struct spdk_conf_section *sp) goto error_out; } - pg = spdk_iscsi_portal_grp_create(sp->num); + pg = spdk_iscsi_portal_grp_create(spdk_conf_section_get_num(sp)); if (!pg) { - SPDK_ERRLOG("portal group malloc error (%s)\n", sp->name); + SPDK_ERRLOG("portal group malloc error (%s)\n", spdk_conf_section_get_name(sp)); goto error_out; } @@ -423,7 +424,7 @@ spdk_iscsi_portal_grp_create_from_configfile(struct spdk_conf_section *sp) SPDK_TRACELOG(SPDK_TRACE_DEBUG, "RIndex=%d, Host=%s, Port=%s, Tag=%d\n", - i, p->host, p->port, sp->num); + i, p->host, p->port, tag); spdk_iscsi_portal_grp_add_portal(pg, p); } @@ -472,7 +473,7 @@ spdk_iscsi_portal_grp_array_create(void) sp = spdk_conf_first_section(NULL); while (sp != NULL) { if (spdk_conf_section_match_prefix(sp, "PortalGroup")) { - if (sp->num == 0) { + if (spdk_conf_section_get_num(sp) == 0) { SPDK_ERRLOG("Group 0 is invalid\n"); return -1; } diff --git a/lib/iscsi/tgt_node.c b/lib/iscsi/tgt_node.c index b945c4ef1..6ee24187e 100644 --- a/lib/iscsi/tgt_node.c +++ b/lib/iscsi/tgt_node.c @@ -793,13 +793,13 @@ spdk_cf_add_iscsi_tgt_node(struct spdk_conf_section *sp) char *lun_name_list[SPDK_SCSI_DEV_MAX_LUN]; int num_luns, queue_depth; - SPDK_TRACELOG(SPDK_TRACE_DEBUG, "add unit %d\n", sp->num); + target_num = spdk_conf_section_get_num(sp); + + SPDK_TRACELOG(SPDK_TRACE_DEBUG, "add unit %d\n", target_num); data_digest = 0; header_digest = 0; - target_num = sp->num; - name = spdk_conf_section_get_val(sp, "TargetName"); if (name == NULL) { @@ -997,8 +997,10 @@ int spdk_iscsi_init_tgt_nodes(void) sp = spdk_conf_first_section(NULL); while (sp != NULL) { if (spdk_conf_section_match_prefix(sp, "TargetNode")) { - if (sp->num > SPDK_TN_TAG_MAX) { - SPDK_ERRLOG("tag %d is invalid\n", sp->num); + int tag = spdk_conf_section_get_num(sp); + + if (tag > SPDK_TN_TAG_MAX) { + SPDK_ERRLOG("tag %d is invalid\n", tag); return -1; } rc = spdk_cf_add_iscsi_tgt_node(sp);