diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index a4ffc8eeee..cd16e07c57 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -973,7 +973,8 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes, return 0; } else { spdk_strerror_r(errno, errbuf, sizeof(errbuf)); - SPDK_ERRLOG("Socket read error(%d): %s\n", errno, errbuf); + SPDK_ERRLOG("spdk_sock_recv() failed (fd=%d), errno %d: %s\n", + conn->sock, errno, errbuf); } return SPDK_ISCSI_CONNECTION_FATAL; } @@ -1181,6 +1182,7 @@ spdk_iscsi_conn_flush_pdus_internal(struct spdk_iscsi_conn *conn) uint32_t writev_offset; struct spdk_iscsi_pdu *pdu; int pdu_length; + char buf[64]; pdu = TAILQ_FIRST(&conn->write_pdu_list); @@ -1229,7 +1231,9 @@ spdk_iscsi_conn_flush_pdus_internal(struct spdk_iscsi_conn *conn) if (errno == EWOULDBLOCK || errno == EAGAIN) { return 0; } else { - perror("writev"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("spdk_sock_writev() failed (fd=%d), errno %d: %s\n", + conn->sock, errno, buf); return -1; } } diff --git a/lib/iscsi/init_grp.c b/lib/iscsi/init_grp.c index cf5a9c51e0..34cad2ef1a 100644 --- a/lib/iscsi/init_grp.c +++ b/lib/iscsi/init_grp.c @@ -35,6 +35,7 @@ #include "spdk/stdinc.h" #include "spdk/conf.h" +#include "spdk/string.h" #include "spdk_internal/log.h" @@ -45,6 +46,7 @@ static struct spdk_iscsi_init_grp * spdk_iscsi_init_grp_create(int tag) { struct spdk_iscsi_init_grp *ig; + char buf[64]; if (spdk_iscsi_init_grp_find_by_tag(tag)) { SPDK_ERRLOG("duplicate initiator group tag (%d)\n", tag); @@ -53,7 +55,9 @@ spdk_iscsi_init_grp_create(int tag) ig = calloc(1, sizeof(*ig)); if (ig == NULL) { - SPDK_ERRLOG("initiator group malloc error (tag=%d)\n", tag); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("calloc() failed for initiator group (tag=%d), errno %d: %s\n", + tag, errno, buf); return NULL; } @@ -81,6 +85,7 @@ spdk_iscsi_init_grp_add_initiator(struct spdk_iscsi_init_grp *ig, char *name) { struct spdk_iscsi_initiator_name *iname; char *p; + char buf[64]; if (ig->ninitiators >= MAX_INITIATOR) { SPDK_ERRLOG("> MAX_INITIATOR(=%d) is not allowed\n", MAX_INITIATOR); @@ -94,11 +99,17 @@ spdk_iscsi_init_grp_add_initiator(struct spdk_iscsi_init_grp *ig, char *name) iname = malloc(sizeof(*iname)); if (iname == NULL) { + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for initiator name str, errno %d: %s\n", + errno, buf); return -ENOMEM; } iname->name = strdup(name); if (iname->name == NULL) { + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("strdup() failed for initiator name, errno %d: %s\n", + errno, buf); free(iname); return -ENOMEM; } @@ -187,6 +198,7 @@ spdk_iscsi_init_grp_add_netmask(struct spdk_iscsi_init_grp *ig, char *mask) { struct spdk_iscsi_initiator_netmask *imask; char *p; + char buf[64]; if (ig->nnetmasks >= MAX_NETMASK) { SPDK_ERRLOG("> MAX_NETMASK(=%d) is not allowed\n", MAX_NETMASK); @@ -200,11 +212,17 @@ spdk_iscsi_init_grp_add_netmask(struct spdk_iscsi_init_grp *ig, char *mask) imask = malloc(sizeof(*imask)); if (imask == NULL) { + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for inititator mask str, errno %d: %s\n", + errno, buf); return -ENOMEM; } imask->mask = strdup(mask); if (imask->mask == NULL) { + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("strdup() failed for initiator mask, errno %d: %s\n", + errno, buf); free(imask); return -ENOMEM; } @@ -286,6 +304,7 @@ spdk_iscsi_init_grp_create_from_configfile(struct spdk_conf_section *sp) int num_initiator_masks; char **initiators = NULL, **netmasks = NULL; int tag = spdk_conf_section_get_num(sp); + char buf[64]; SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "add initiator group %d\n", tag); @@ -328,7 +347,9 @@ spdk_iscsi_init_grp_create_from_configfile(struct spdk_conf_section *sp) initiators = calloc(num_initiator_names, sizeof(char *)); if (!initiators) { - perror("initiators"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("calloc() failed for temp initiator name array, errno %d: %s\n", + errno, buf); return -ENOMEM; } for (i = 0; i < num_initiator_names; i++) { @@ -341,14 +362,18 @@ spdk_iscsi_init_grp_create_from_configfile(struct spdk_conf_section *sp) SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "InitiatorName %s\n", val); initiators[i] = strdup(val); if (!initiators[i]) { - perror("initiator name copy"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("strdup() failed for temp initiator name, errno %d: %s\n", + errno, buf); rc = -ENOMEM; goto cleanup; } } netmasks = calloc(num_initiator_masks, sizeof(char *)); if (!netmasks) { - perror("netmasks"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for portal group (tag=%d), errno %d: %s\n", + tag, errno, buf); rc = -ENOMEM; goto cleanup; } @@ -362,7 +387,9 @@ spdk_iscsi_init_grp_create_from_configfile(struct spdk_conf_section *sp) SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "Netmask %s\n", val); netmasks[i] = strdup(val); if (!netmasks[i]) { - perror("initiator netmask copy"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("strdup() failed for temp initiator mask, errno %d: %s\n", + errno, buf); rc = -ENOMEM; goto cleanup; } diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 915ed7a97a..4ffc1673e1 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -774,6 +774,7 @@ spdk_iscsi_get_authinfo(struct spdk_iscsi_conn *conn, const char *authuser) char *authfile = NULL; int ag_tag; int rc; + char buf[64]; if (conn->sess->target != NULL) { ag_tag = conn->sess->target->auth_group; @@ -791,7 +792,9 @@ spdk_iscsi_get_authinfo(struct spdk_iscsi_conn *conn, const char *authuser) authfile = strdup(g_spdk_iscsi.authfile); pthread_mutex_unlock(&g_spdk_iscsi.mutex); if (!authfile) { - perror("authfile"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("strdup() failed from %s to authfile, errno %d: %s\n", + g_spdk_iscsi.authfile, errno, buf); return -ENOMEM; } @@ -819,6 +822,7 @@ spdk_iscsi_auth_params(struct spdk_iscsi_conn *conn, const char *challenge; int total; int rc; + char buf[64]; if (conn == NULL || params == NULL || method == NULL) { return -1; @@ -843,7 +847,9 @@ spdk_iscsi_auth_params(struct spdk_iscsi_conn *conn, /* for temporary store */ in_val = malloc(ISCSI_TEXT_MAX_VAL_LEN + 1); if (!in_val) { - perror("in_val"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for temporary store, errno %d: %s\n", + errno, buf); return -ENOMEM; } @@ -1043,6 +1049,7 @@ spdk_iscsi_reject(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu, int total_ahs_len; int data_len; int alloc_len; + char buf[64]; total_ahs_len = pdu->bhs.total_ahs_len; data_len = 0; @@ -1054,7 +1061,9 @@ spdk_iscsi_reject(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu, data = malloc(alloc_len); if (!data) { - perror("data"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for data segment, errno %d: %s\n", + errno, buf); return -ENOMEM; } @@ -1830,6 +1839,7 @@ spdk_iscsi_op_login_rsp_init(struct spdk_iscsi_conn *conn, struct iscsi_bhs_login_req *reqh; struct iscsi_bhs_login_rsp *rsph; int rc; + char buf[64]; rsph = (struct iscsi_bhs_login_rsp *)&rsp_pdu->bhs; rsph->opcode = ISCSI_OP_LOGIN_RSP; @@ -1846,7 +1856,9 @@ spdk_iscsi_op_login_rsp_init(struct spdk_iscsi_conn *conn, rsp_pdu->data = malloc(*alloc_len); if (!rsp_pdu->data) { - perror("data"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for data segment, errno %d: %s\n", + errno, buf); return -ENOMEM; } @@ -2265,6 +2277,7 @@ spdk_iscsi_op_text(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) int rc; struct iscsi_bhs_text_req *reqh; struct iscsi_bhs_text_resp *rsph; + char buf[64]; data_len = 0; alloc_len = conn->MaxRecvDataSegmentLength; @@ -2328,7 +2341,8 @@ spdk_iscsi_op_text(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) data = malloc(alloc_len); if (!data) { - perror("data"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for data segment, errno %d: %s\n", errno, buf); spdk_iscsi_param_free(params); return -ENOMEM; } @@ -3436,6 +3450,7 @@ spdk_iscsi_op_nopout(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) uint32_t CmdSN; int I_bit; int data_len; + char buf[64]; if (conn->sess->session_type == SESSION_TYPE_DISCOVERY) { SPDK_ERRLOG("ISCSI_OP_NOPOUT not allowed in discovery session\n"); @@ -3493,7 +3508,9 @@ spdk_iscsi_op_nopout(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) data = malloc(data_len); if (!data) { - perror("could not allocate ping buffer"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for ping data, errno %d: %s\n", + errno, buf); return SPDK_ISCSI_CONNECTION_FATAL; } memset(data, 0, data_len); @@ -4532,6 +4549,7 @@ spdk_create_iscsi_sess(struct spdk_iscsi_conn *conn, { struct spdk_iscsi_sess *sess; int rc; + char buf[64]; sess = spdk_mempool_get(g_spdk_iscsi.session_pool); if (!sess) { @@ -4570,7 +4588,9 @@ spdk_create_iscsi_sess(struct spdk_iscsi_conn *conn, sess->conns = malloc(sizeof(*sess->conns) * sess->MaxConnections); if (!sess->conns) { - perror("conns"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for connection array, errno %d: %s\n", + errno, buf); return -ENOMEM; } diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index c4c2fc52ab..2898e0009c 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -34,6 +34,7 @@ #include "spdk/stdinc.h" #include "spdk/env.h" +#include "spdk/string.h" #include "iscsi/iscsi.h" #include "iscsi/init_grp.h" @@ -741,6 +742,7 @@ spdk_iscsi_app_read_parameters(void) { struct spdk_conf_section *sp; int rc; + char buf[64]; g_spdk_iscsi.MaxSessions = DEFAULT_MAX_SESSIONS; g_spdk_iscsi.MaxConnectionsPerSession = DEFAULT_MAX_CONNECTIONS_PER_SESSION; @@ -777,7 +779,9 @@ spdk_iscsi_app_read_parameters(void) g_spdk_iscsi.session = spdk_dma_zmalloc(sizeof(void *) * g_spdk_iscsi.MaxSessions, 0, NULL); if (!g_spdk_iscsi.session) { - SPDK_ERRLOG("could not allocate session array\n"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("spdk_dma_zmalloc() failed for session array, errno %d: %s\n", + errno, buf); return -1; } diff --git a/lib/iscsi/param.c b/lib/iscsi/param.c index 89e5727ab7..96c07c6ebb 100644 --- a/lib/iscsi/param.c +++ b/lib/iscsi/param.c @@ -131,6 +131,7 @@ spdk_iscsi_param_add(struct iscsi_param **params, const char *key, const char *val, const char *list, int type) { struct iscsi_param *param, *last_param; + char buf[64]; SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "add %s=%s, list=[%s], type=%d\n", key, val, list, type); @@ -145,7 +146,8 @@ spdk_iscsi_param_add(struct iscsi_param **params, const char *key, param = malloc(sizeof * param); if (!param) { - perror("param"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for parameter, errno %d: %s\n", errno, buf); return -ENOMEM; } @@ -223,6 +225,7 @@ spdk_iscsi_parse_param(struct iscsi_param **params, const uint8_t *data) const uint8_t *key_end, *val; int key_len, val_len; int max_len; + char buf[64]; key_end = strchr(data, '='); if (!key_end) { @@ -245,7 +248,8 @@ spdk_iscsi_parse_param(struct iscsi_param **params, const uint8_t *data) key_copy = malloc(key_len + 1); if (!key_copy) { - perror("key_copy"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for key_copy, errno %d: %s\n", errno, buf); return -ENOMEM; } @@ -520,10 +524,12 @@ spdk_iscsi_special_param_construction(struct spdk_iscsi_conn *conn, uint32_t FirstBurstLength; uint32_t MaxBurstLength; char *val; + char buf[64]; val = malloc(ISCSI_TEXT_MAX_VAL_LEN + 1); if (!val) { - perror("val"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for temporary buffer, errno %d: %s\n", errno, buf); return -ENOMEM; } @@ -885,6 +891,8 @@ spdk_iscsi_negotiate_params(struct spdk_iscsi_conn *conn, uint32_t MaxBurstLength; bool FirstBurstLength_flag = false; int type; + char buf[64]; + total = data_len; if (alloc_len < 1) { return 0; @@ -921,20 +929,23 @@ spdk_iscsi_negotiate_params(struct spdk_iscsi_conn *conn, /* for temporary store */ valid_list = malloc(ISCSI_TEXT_MAX_VAL_LEN + 1); if (!valid_list) { - perror("valid_list"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for valid_list, errno %d: %s\n", errno, buf); return -ENOMEM; } in_val = malloc(ISCSI_TEXT_MAX_VAL_LEN + 1); if (!in_val) { - perror("in_val"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for in_val, errno %d: %s\n", errno, buf); free(valid_list); return -ENOMEM; } cur_val = malloc(ISCSI_TEXT_MAX_VAL_LEN + 1); if (!cur_val) { - perror("cur_val"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for cur_val, errno %d: %s\n", errno, buf); free(valid_list); free(in_val); return -ENOMEM; diff --git a/lib/iscsi/portal_grp.c b/lib/iscsi/portal_grp.c index 79cbd61870..5aef413555 100644 --- a/lib/iscsi/portal_grp.c +++ b/lib/iscsi/portal_grp.c @@ -37,6 +37,7 @@ #include "spdk/conf.h" #include "spdk/net.h" #include "spdk/event.h" +#include "spdk/string.h" #include "spdk_internal/log.h" @@ -69,6 +70,7 @@ struct spdk_iscsi_portal * spdk_iscsi_portal_create(const char *host, const char *port, uint64_t cpumask) { struct spdk_iscsi_portal *p = NULL; + char buf[64]; assert(host != NULL); assert(port != NULL); @@ -81,7 +83,9 @@ spdk_iscsi_portal_create(const char *host, const char *port, uint64_t cpumask) p = malloc(sizeof(*p)); if (!p) { - SPDK_ERRLOG("portal malloc error (%s, %s)\n", host, port); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for portal (%s, %s), errno %d: %s\n", + host, port, errno, buf); return NULL; } @@ -168,9 +172,9 @@ spdk_iscsi_portal_create_from_configline(const char *portalstring, char *host = NULL, *port = NULL; const char *cpumask_str; uint64_t cpumask = 0; - int n, len, rc = -1; const char *p, *q; + char buf[64]; if (portalstring == NULL) { SPDK_ERRLOG("portal error\n"); @@ -189,7 +193,9 @@ spdk_iscsi_portal_create_from_configline(const char *portalstring, if (!dry_run) { host = malloc(n + 1); if (!host) { - perror("host"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for host, errno %d: %s\n", + errno, buf); goto error_out; } memcpy(host, portalstring, n); @@ -199,7 +205,9 @@ spdk_iscsi_portal_create_from_configline(const char *portalstring, if (!dry_run) { port = malloc(PORTNUMSTRLEN); if (!port) { - perror("port"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for port, errno %d: %s\n", + errno, buf); goto error_out; } snprintf(port, PORTNUMSTRLEN, "%d", DEFAULT_PORT); @@ -218,7 +226,9 @@ spdk_iscsi_portal_create_from_configline(const char *portalstring, port = malloc(len + 1); if (!port) { - perror("port"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for port, errno %d: %s\n", + errno, buf); goto error_out; } memset(port, 0, len + 1); @@ -235,7 +245,9 @@ spdk_iscsi_portal_create_from_configline(const char *portalstring, if (!dry_run) { host = malloc(n + 1); if (!host) { - perror("host"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for host, errno %d: %s\n", + errno, buf); goto error_out; } memcpy(host, portalstring, n); @@ -245,7 +257,9 @@ spdk_iscsi_portal_create_from_configline(const char *portalstring, if (!dry_run) { port = malloc(PORTNUMSTRLEN); if (!port) { - perror("port"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for port, errno %d: %s\n", + errno, buf); goto error_out; } snprintf(port, PORTNUMSTRLEN, "%d", DEFAULT_PORT); @@ -269,7 +283,9 @@ spdk_iscsi_portal_create_from_configline(const char *portalstring, len = q - p - 1; port = malloc(len + 1); if (!port) { - perror("port"); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for port, errno %d: %s\n", + errno, buf); goto error_out; } memset(port, 0, len + 1); @@ -305,8 +321,12 @@ spdk_iscsi_portal_create_from_configline(const char *portalstring, rc = 0; error_out: - free(host); - free(port); + if (host) { + free(host); + } + if (port) { + free(port); + } return rc; } @@ -314,10 +334,13 @@ error_out: struct spdk_iscsi_portal_grp * spdk_iscsi_portal_grp_create(int tag) { + char buf[64]; struct spdk_iscsi_portal_grp *pg = malloc(sizeof(*pg)); if (!pg) { - SPDK_ERRLOG("portal group malloc error (%d)\n", tag); + spdk_strerror_r(errno, buf, sizeof(buf)); + SPDK_ERRLOG("malloc() failed for portal group (tag=%d), errno %d: %s\n", + tag, errno, buf); return NULL; }