Commit 81673d0c authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

iscsi: Remove use of perror for malloc, strdup, and writev failure



All SPDK libraries should use the spdk/log.h family of functions
for logging.

Change-Id: I2b8ac30f2901b325784552f0016f1058ae2cd577
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/391687


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent a652471c
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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;
		}
	}
+32 −5
Original line number Diff line number Diff line
@@ -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;
		}
+27 −7
Original line number Diff line number Diff line
@@ -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;
	}

+5 −1
Original line number Diff line number Diff line
@@ -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;
	}

+17 −6
Original line number Diff line number Diff line
@@ -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;
Loading