Commit 4d43844f authored by Seth Howell's avatar Seth Howell Committed by Daniel Verkamp
Browse files

lib: replace strerror with strerror_r



replaces all references to strerror in the spdk lib directory with
references to the thread safe strerror_r

Change-Id: I80d946cce3299007ee10500b93f7e1c8e503ee41
Signed-off-by: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/374012


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent dcbbaa3c
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -89,6 +89,17 @@ char *spdk_strsepq(char **stringp, const char *delim);
 */
char *spdk_str_trim(char *s);

/**
 * Copy the string version of an error into the user supplied buffer
 *
 * \param errnum Error code
 * \param buf Pointer to a buffer in which to place the error message
 * \param buflen the size of the buffer in bytes
 *
 * \return 0 upon success, a positive error number or -1 upon failure.
 */
int spdk_strerror_r(int errnum, char *buf, size_t buflen);

/**
 * Remove trailing newlines from the end of a string in place.
 *
+4 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "spdk/event.h"
#include "spdk/log.h"
#include "spdk/net.h"
#include "spdk/string.h"
#include "iscsi/acceptor.h"
#include "iscsi/conn.h"
#include "iscsi/portal_grp.h"
@@ -50,6 +51,7 @@ static void
spdk_iscsi_portal_accept(struct spdk_iscsi_portal *portal)
{
	int				rc, sock;
	char buf[64];

	if (portal->sock < 0) {
		return;
@@ -67,7 +69,8 @@ spdk_iscsi_portal_accept(struct spdk_iscsi_portal *portal)
			}
		} else {
			if (errno != EAGAIN && errno != EWOULDBLOCK) {
				SPDK_ERRLOG("accept error(%d): %s\n", errno, strerror(errno));
				spdk_strerror_r(errno, buf, sizeof(buf));
				SPDK_ERRLOG("accept error(%d): %s\n", errno, buf);
			}
			break;
		}
+7 −3
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@
#include "spdk/queue.h"
#include "spdk/trace.h"
#include "spdk/net.h"
#include "spdk/string.h"

#include "spdk_internal/log.h"

@@ -186,7 +187,7 @@ del_idle_conn(struct spdk_iscsi_conn *conn)
		return -1;
	}
	if (event.flags & EV_ERROR) {
		strerror_r(event.data, buf, sizeof(buf));
		spdk_strerror_r(event.data, buf, sizeof(buf));
		SPDK_ERRLOG("kevent(EV_DELETE) failed: %s\n", buf);
		return -1;
	}
@@ -928,6 +929,7 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
			  void *buf)
{
	int ret;
	char errbuf[64];

	if (bytes == 0) {
		return 0;
@@ -942,8 +944,10 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
	if (ret < 0) {
		if (errno == EAGAIN || errno == EWOULDBLOCK) {
			return 0;
		} else
			SPDK_ERRLOG("Socket read error(%d): %s\n", errno, strerror(errno));
		} else {
			spdk_strerror_r(errno, errbuf, sizeof(errbuf));
			SPDK_ERRLOG("Socket read error(%d): %s\n", errno, errbuf);
		}
		return SPDK_ISCSI_CONNECTION_FATAL;
	}

+10 −4
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
 */

#include "jsonrpc_internal.h"
#include "spdk/string.h"

struct spdk_jsonrpc_server *
spdk_jsonrpc_server_listen(int domain, int protocol,
@@ -40,6 +41,7 @@ spdk_jsonrpc_server_listen(int domain, int protocol,
{
	struct spdk_jsonrpc_server *server;
	int rc, val;
	char buf[64];

	server = calloc(1, sizeof(struct spdk_jsonrpc_server));
	if (server == NULL) {
@@ -72,7 +74,8 @@ spdk_jsonrpc_server_listen(int domain, int protocol,

	rc = bind(server->sockfd, listen_addr, addrlen);
	if (rc != 0) {
		SPDK_ERRLOG("could not bind JSON-RPC server: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_ERRLOG("could not bind JSON-RPC server: %s\n", buf);
		close(server->sockfd);
		free(server);
		return NULL;
@@ -219,14 +222,15 @@ spdk_jsonrpc_server_conn_recv(struct spdk_jsonrpc_server_conn *conn)
{
	ssize_t rc;
	size_t recv_avail = SPDK_JSONRPC_RECV_BUF_SIZE - conn->recv_len;
	char buf[64];

	rc = recv(conn->sockfd, conn->recv_buf + conn->recv_len, recv_avail, 0);
	if (rc == -1) {
		if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
			return 0;
		}

		SPDK_TRACELOG(SPDK_TRACE_RPC, "recv() failed: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_TRACELOG(SPDK_TRACE_RPC, "recv() failed: %s\n", buf);
		return -1;
	}

@@ -269,6 +273,7 @@ spdk_jsonrpc_server_conn_send(struct spdk_jsonrpc_server_conn *conn)
{
	struct spdk_jsonrpc_request *request;
	ssize_t rc;
	char buf[64];

more:
	if (conn->outstanding_requests == 0) {
@@ -294,7 +299,8 @@ more:
			return 0;
		}

		SPDK_TRACELOG(SPDK_TRACE_RPC, "send() failed: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_TRACELOG(SPDK_TRACE_RPC, "send() failed: %s\n", buf);
		return -1;
	}

+17 −7
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
 */

#include "spdk/stdinc.h"
#include "spdk/string.h"

#include <linux/nbd.h>

@@ -323,19 +324,22 @@ static void
nbd_start_kernel(int nbd_fd, int *sp)
{
	int rc;
	char buf[64];

	close(sp[0]);

	rc = ioctl(nbd_fd, NBD_SET_SOCK, sp[1]);
	if (rc == -1) {
		SPDK_ERRLOG("ioctl(NBD_SET_SOCK) failed: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_ERRLOG("ioctl(NBD_SET_SOCK) failed: %s\n", buf);
		exit(-1);
	}

#ifdef NBD_FLAG_SEND_TRIM
	rc = ioctl(nbd_fd, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM);
	if (rc == -1) {
		SPDK_ERRLOG("ioctl(NBD_SET_FLAGS) failed: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_ERRLOG("ioctl(NBD_SET_FLAGS) failed: %s\n", buf);
		exit(-1);
	}
#endif
@@ -355,6 +359,7 @@ spdk_nbd_start(struct spdk_bdev *bdev, const char *nbd_path)
	struct spdk_nbd_disk	*nbd;
	int			rc;
	int			sp[2] = { -1, -1 }, nbd_fd = -1;
	char buf[64];

	nbd = calloc(1, sizeof(*nbd));
	if (nbd == NULL) {
@@ -380,25 +385,29 @@ spdk_nbd_start(struct spdk_bdev *bdev, const char *nbd_path)

	nbd_fd = open(nbd_path, O_RDWR);
	if (nbd_fd == -1) {
		SPDK_ERRLOG("open(\"%s\") failed: %s\n", nbd_path, strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_ERRLOG("open(\"%s\") failed: %s\n", nbd_path, buf);
		goto err;
	}

	rc = ioctl(nbd_fd, NBD_SET_BLKSIZE, spdk_bdev_get_block_size(bdev));
	if (rc == -1) {
		SPDK_ERRLOG("ioctl(NBD_SET_BLKSIZE) failed: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_ERRLOG("ioctl(NBD_SET_BLKSIZE) failed: %s\n", buf);
		goto err;
	}

	rc = ioctl(nbd_fd, NBD_SET_SIZE_BLOCKS, spdk_bdev_get_num_blocks(bdev));
	if (rc == -1) {
		SPDK_ERRLOG("ioctl(NBD_SET_SIZE_BLOCKS) failed: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_ERRLOG("ioctl(NBD_SET_SIZE_BLOCKS) failed: %s\n", buf);
		goto err;
	}

	rc = ioctl(nbd_fd, NBD_CLEAR_SOCK);
	if (rc == -1) {
		SPDK_ERRLOG("ioctl(NBD_CLEAR_SOCK) failed: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_ERRLOG("ioctl(NBD_CLEAR_SOCK) failed: %s\n", buf);
		goto err;
	}

@@ -411,7 +420,8 @@ spdk_nbd_start(struct spdk_bdev *bdev, const char *nbd_path)
		nbd_start_kernel(nbd_fd, sp);
		break;
	case -1:
		SPDK_ERRLOG("could not fork: %s\n", strerror(errno));
		spdk_strerror_r(errno, buf, sizeof(buf));
		SPDK_ERRLOG("could not fork: %s\n", buf);
		goto err;
	default:
		close(nbd_fd);
Loading