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: Seth Howell <seth.howell@intel.com> Reviewed-on: https://review.gerrithub.io/374012 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
dcbbaa3c34
commit
4d43844f4d
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -32,6 +32,7 @@
|
||||
*/
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/string.h"
|
||||
|
||||
#include "spdk/log.h"
|
||||
#include "spdk/net.h"
|
||||
@ -50,6 +51,7 @@ static uint32_t spdk_get_ifc_ipv4(void)
|
||||
int ret;
|
||||
int rtattrlen;
|
||||
int netlink_fd;
|
||||
char errbuf[64];
|
||||
uint32_t ipv4_addr;
|
||||
|
||||
struct {
|
||||
@ -89,14 +91,16 @@ static uint32_t spdk_get_ifc_ipv4(void)
|
||||
/* Send and recv the message from kernel */
|
||||
ret = send(netlink_fd, &req, req.n.nlmsg_len, 0);
|
||||
if (ret < 0) {
|
||||
SPDK_ERRLOG("netlink send failed: %s\n", strerror(errno));
|
||||
spdk_strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
SPDK_ERRLOG("netlink send failed: %s\n", errbuf);
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = recv(netlink_fd, buf, sizeof(buf), 0);
|
||||
if (ret <= 0) {
|
||||
SPDK_ERRLOG("netlink recv failed: %s\n", strerror(errno));
|
||||
spdk_strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
SPDK_ERRLOG("netlink recv failed: %s\n", errbuf);
|
||||
ret = 1;
|
||||
goto exit;
|
||||
}
|
||||
|
@ -171,11 +171,13 @@ nvme_rdma_get_event(struct rdma_event_channel *channel,
|
||||
{
|
||||
struct rdma_cm_event *event;
|
||||
int rc;
|
||||
char buf[64];
|
||||
|
||||
rc = rdma_get_cm_event(channel, &event);
|
||||
if (rc < 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Failed to get event from CM event channel. Error %d (%s)\n",
|
||||
errno, strerror(errno));
|
||||
errno, buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -194,11 +196,13 @@ nvme_rdma_qpair_init(struct nvme_rdma_qpair *rqpair)
|
||||
{
|
||||
int rc;
|
||||
struct ibv_qp_init_attr attr;
|
||||
char buf[64];
|
||||
|
||||
rqpair->cq = ibv_create_cq(rqpair->cm_id->verbs, rqpair->num_entries * 2, rqpair, NULL, 0);
|
||||
if (!rqpair->cq) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Unable to create completion queue\n");
|
||||
SPDK_ERRLOG("Errno %d: %s\n", errno, strerror(errno));
|
||||
SPDK_ERRLOG("Errno %d: %s\n", errno, buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1350,6 +1354,7 @@ nvme_rdma_qpair_submit_request(struct spdk_nvme_qpair *qpair,
|
||||
struct spdk_nvme_rdma_req *rdma_req;
|
||||
struct ibv_send_wr *wr, *bad_wr = NULL;
|
||||
int rc;
|
||||
char buf[64];
|
||||
|
||||
rqpair = nvme_rdma_qpair(qpair);
|
||||
assert(rqpair != NULL);
|
||||
@ -1376,7 +1381,8 @@ nvme_rdma_qpair_submit_request(struct spdk_nvme_qpair *qpair,
|
||||
|
||||
rc = ibv_post_send(rqpair->cm_id->qp, wr, &bad_wr);
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("Failure posting rdma send for NVMf completion: %d (%s)\n", rc, strerror(rc));
|
||||
spdk_strerror_r(rc, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Failure posting rdma send for NVMf completion: %d (%s)\n", rc, buf);
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -1433,6 +1439,7 @@ nvme_rdma_qpair_process_completions(struct spdk_nvme_qpair *qpair,
|
||||
int i, rc, batch_size;
|
||||
uint32_t reaped;
|
||||
struct ibv_cq *cq;
|
||||
char buf[64];
|
||||
|
||||
if (max_completions == 0) {
|
||||
max_completions = rqpair->num_entries;
|
||||
@ -1448,8 +1455,9 @@ nvme_rdma_qpair_process_completions(struct spdk_nvme_qpair *qpair,
|
||||
MAX_COMPLETIONS_PER_POLL);
|
||||
rc = ibv_poll_cq(cq, batch_size, wc);
|
||||
if (rc < 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Error polling CQ! (%d): %s\n",
|
||||
errno, strerror(errno));
|
||||
errno, buf);
|
||||
return -1;
|
||||
} else if (rc == 0) {
|
||||
/* Ran out of completions */
|
||||
|
@ -32,6 +32,7 @@
|
||||
*/
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/string.h"
|
||||
|
||||
#include "spdk/log.h"
|
||||
#include "spdk/event.h"
|
||||
@ -143,6 +144,7 @@ spdk_get_uevent(int fd, struct spdk_uevent *uevent)
|
||||
{
|
||||
int ret;
|
||||
char buf[SPDK_UEVENT_MSG_LEN];
|
||||
char errbuf[64];
|
||||
|
||||
memset(uevent, 0, sizeof(struct spdk_uevent));
|
||||
memset(buf, 0, SPDK_UEVENT_MSG_LEN);
|
||||
@ -156,7 +158,8 @@ spdk_get_uevent(int fd, struct spdk_uevent *uevent)
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
return 0;
|
||||
} else {
|
||||
SPDK_ERRLOG("Socket read error(%d): %s\n", errno, strerror(errno));
|
||||
spdk_strerror_r(errno, errbuf, sizeof(errbuf));
|
||||
SPDK_ERRLOG("Socket read error(%d): %s\n", errno, errbuf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -255,6 +255,7 @@ spdk_nvmf_rdma_qpair_create(struct spdk_nvmf_transport *transport,
|
||||
struct ibv_qp_init_attr attr;
|
||||
struct spdk_nvmf_rdma_recv *rdma_recv;
|
||||
struct spdk_nvmf_rdma_request *rdma_req;
|
||||
char buf[64];
|
||||
|
||||
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
||||
|
||||
@ -274,8 +275,9 @@ spdk_nvmf_rdma_qpair_create(struct spdk_nvmf_transport *transport,
|
||||
|
||||
rdma_qpair->cq = ibv_create_cq(id->verbs, max_queue_depth * 3, rdma_qpair, NULL, 0);
|
||||
if (!rdma_qpair->cq) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Unable to create completion queue\n");
|
||||
SPDK_ERRLOG("Errno %d: %s\n", errno, strerror(errno));
|
||||
SPDK_ERRLOG("Errno %d: %s\n", errno, buf);
|
||||
rdma_destroy_id(id);
|
||||
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
||||
return NULL;
|
||||
@ -292,8 +294,9 @@ spdk_nvmf_rdma_qpair_create(struct spdk_nvmf_transport *transport,
|
||||
|
||||
rc = rdma_create_qp(id, NULL, &attr);
|
||||
if (rc) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("rdma_create_qp failed\n");
|
||||
SPDK_ERRLOG("Errno %d: %s\n", errno, strerror(errno));
|
||||
SPDK_ERRLOG("Errno %d: %s\n", errno, buf);
|
||||
rdma_destroy_id(id);
|
||||
spdk_nvmf_rdma_qpair_destroy(rdma_qpair);
|
||||
return NULL;
|
||||
@ -935,6 +938,7 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_tgt *tgt)
|
||||
struct spdk_nvmf_rdma_device *device, *tmp;
|
||||
struct ibv_context **contexts;
|
||||
uint32_t i;
|
||||
char buf[64];
|
||||
|
||||
rtransport = calloc(1, sizeof(*rtransport));
|
||||
if (!rtransport) {
|
||||
@ -956,7 +960,8 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_tgt *tgt)
|
||||
|
||||
rtransport->event_channel = rdma_create_event_channel();
|
||||
if (rtransport->event_channel == NULL) {
|
||||
SPDK_ERRLOG("rdma_create_event_channel() failed, %s\n", strerror(errno));
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("rdma_create_event_channel() failed, %s\n", buf);
|
||||
free(rtransport);
|
||||
return NULL;
|
||||
}
|
||||
@ -1168,6 +1173,7 @@ spdk_nvmf_rdma_accept(struct spdk_nvmf_transport *transport)
|
||||
struct rdma_cm_event *event;
|
||||
int rc;
|
||||
struct spdk_nvmf_rdma_qpair *rdma_qpair, *tmp;
|
||||
char buf[64];
|
||||
|
||||
rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport);
|
||||
|
||||
@ -1222,7 +1228,8 @@ spdk_nvmf_rdma_accept(struct spdk_nvmf_transport *transport)
|
||||
rdma_ack_cm_event(event);
|
||||
} else {
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
SPDK_ERRLOG("Acceptor Event Error: %s\n", strerror(errno));
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Acceptor Event Error: %s\n", buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1514,14 +1521,16 @@ spdk_nvmf_rdma_poll(struct spdk_nvmf_qpair *qpair)
|
||||
int reaped, i, rc;
|
||||
int count = 0;
|
||||
bool error = false;
|
||||
char buf[64];
|
||||
|
||||
rdma_qpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair);
|
||||
|
||||
/* Poll for completing operations. */
|
||||
rc = ibv_poll_cq(rdma_qpair->cq, 32, wc);
|
||||
if (rc < 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Error polling CQ! (%d): %s\n",
|
||||
errno, strerror(errno));
|
||||
errno, buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "spdk/stdinc.h"
|
||||
|
||||
#include "spdk/env.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/trace.h"
|
||||
|
||||
#include <rte_config.h>
|
||||
@ -152,13 +153,15 @@ spdk_trace_init(const char *shm_name)
|
||||
struct spdk_trace_register_fn *reg_fn;
|
||||
int trace_fd;
|
||||
int i = 0;
|
||||
char buf[64];
|
||||
|
||||
snprintf(g_shm_name, sizeof(g_shm_name), "%s", shm_name);
|
||||
|
||||
trace_fd = shm_open(shm_name, O_RDWR | O_CREAT, 0600);
|
||||
if (trace_fd == -1) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
fprintf(stderr, "could not shm_open spdk_trace\n");
|
||||
fprintf(stderr, "errno=%d %s\n", errno, strerror(errno));
|
||||
fprintf(stderr, "errno=%d %s\n", errno, buf);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -326,3 +326,19 @@ spdk_str_chomp(char *s)
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_strerror_r(int errnum, char *buf, size_t buflen)
|
||||
{
|
||||
#if defined(__USE_GNU)
|
||||
char *new_buffer;
|
||||
new_buffer = strerror_r(errnum, buf, buflen);
|
||||
if (new_buffer != NULL) {
|
||||
snprintf(buf, buflen, "%s", new_buffer);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
return strerror_r(errnum, buf, buflen);
|
||||
#endif
|
||||
}
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
#include "spdk/env.h"
|
||||
#include "spdk/likely.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
#include "spdk/vhost.h"
|
||||
@ -292,6 +293,7 @@ spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, uint64_t
|
||||
unsigned ctrlr_num;
|
||||
char path[PATH_MAX];
|
||||
struct stat file_stat;
|
||||
char buf[64];
|
||||
|
||||
assert(vdev);
|
||||
|
||||
@ -369,8 +371,9 @@ spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, uint64_t
|
||||
g_spdk_vhost_devices[ctrlr_num] = vdev;
|
||||
|
||||
if (rte_vhost_driver_start(path) != 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Failed to start vhost driver for controller %s (%d): %s", name, errno,
|
||||
strerror(errno));
|
||||
buf);
|
||||
rte_vhost_driver_unregister(path);
|
||||
return -EIO;
|
||||
}
|
||||
@ -652,8 +655,11 @@ void
|
||||
spdk_vhost_shutdown_cb(void)
|
||||
{
|
||||
pthread_t tid;
|
||||
char buf[64];
|
||||
|
||||
if (pthread_create(&tid, NULL, &session_shutdown, NULL) < 0) {
|
||||
SPDK_ERRLOG("Failed to start session shutdown thread (%d): %s", errno, strerror(errno));
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Failed to start session shutdown thread (%d): %s", errno, buf);
|
||||
abort();
|
||||
}
|
||||
pthread_detach(tid);
|
||||
|
@ -32,6 +32,7 @@
|
||||
*/
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/string.h"
|
||||
|
||||
#include "vhost_iommu.h"
|
||||
|
||||
@ -125,6 +126,7 @@ vfio_pci_memory_region_map(int vfio_container_fd, uint64_t vaddr, uint64_t phys_
|
||||
{
|
||||
struct vfio_iommu_type1_dma_map dma_map;
|
||||
int ret;
|
||||
char buf[64];
|
||||
|
||||
dma_map.argsz = sizeof(dma_map);
|
||||
dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
|
||||
@ -137,7 +139,8 @@ vfio_pci_memory_region_map(int vfio_container_fd, uint64_t vaddr, uint64_t phys_
|
||||
ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);
|
||||
|
||||
if (ret) {
|
||||
SPDK_ERRLOG("Cannot set up DMA mapping, error %d (%s)\n", errno, strerror(errno));
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Cannot set up DMA mapping, error %d (%s)\n", errno, buf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -148,6 +151,7 @@ vfio_pci_memory_region_unmap(int vfio_container_fd, uint64_t phys_addr, uint64_t
|
||||
{
|
||||
struct vfio_iommu_type1_dma_unmap dma_unmap;
|
||||
int ret;
|
||||
char buf[64];
|
||||
|
||||
dma_unmap.argsz = sizeof(dma_unmap);
|
||||
dma_unmap.flags = 0;
|
||||
@ -158,7 +162,8 @@ vfio_pci_memory_region_unmap(int vfio_container_fd, uint64_t phys_addr, uint64_t
|
||||
ret = ioctl(vfio_container_fd, VFIO_IOMMU_UNMAP_DMA, &dma_unmap);
|
||||
|
||||
if (ret) {
|
||||
SPDK_ERRLOG("Cannot clear DMA mapping, error %d (%s)\n", errno, strerror(errno));
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("Cannot clear DMA mapping, error %d (%s)\n", errno, buf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "spdk_internal/log.h"
|
||||
#include "spdk/rpc.h"
|
||||
#include "spdk/util.h"
|
||||
#include "spdk/string.h"
|
||||
|
||||
#include "spdk/scsi.h"
|
||||
#include "spdk/vhost.h"
|
||||
@ -66,6 +67,7 @@ spdk_rpc_construct_vhost_scsi_controller(struct spdk_jsonrpc_request *request,
|
||||
struct rpc_vhost_scsi_ctrlr req = {0};
|
||||
struct spdk_json_write_ctx *w;
|
||||
int rc;
|
||||
char buf[64];
|
||||
uint64_t cpumask;
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_construct_vhost_ctrlr,
|
||||
@ -99,8 +101,9 @@ spdk_rpc_construct_vhost_scsi_controller(struct spdk_jsonrpc_request *request,
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_strerror_r(-rc, buf, sizeof(buf));
|
||||
free_rpc_vhost_scsi_ctrlr(&req);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_vhost_scsi_controller", spdk_rpc_construct_vhost_scsi_controller)
|
||||
|
||||
@ -126,6 +129,7 @@ spdk_rpc_remove_vhost_scsi_controller(struct spdk_jsonrpc_request *request,
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_vhost_dev *vdev;
|
||||
int rc;
|
||||
char buf[64];
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_remove_vhost_ctrlr,
|
||||
SPDK_COUNTOF(rpc_remove_vhost_ctrlr),
|
||||
@ -157,8 +161,9 @@ spdk_rpc_remove_vhost_scsi_controller(struct spdk_jsonrpc_request *request,
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_strerror_r(-rc, buf, sizeof(buf));
|
||||
free_rpc_remove_vhost_scsi_ctrlr(&req);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
|
||||
}
|
||||
SPDK_RPC_REGISTER("remove_vhost_scsi_controller", spdk_rpc_remove_vhost_scsi_controller)
|
||||
|
||||
@ -189,6 +194,7 @@ spdk_rpc_add_vhost_scsi_lun(struct spdk_jsonrpc_request *request,
|
||||
struct rpc_add_vhost_scsi_ctrlr_lun req = {0};
|
||||
struct spdk_json_write_ctx *w;
|
||||
int rc;
|
||||
char buf[64];
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_vhost_add_lun,
|
||||
SPDK_COUNTOF(rpc_vhost_add_lun),
|
||||
@ -215,8 +221,9 @@ spdk_rpc_add_vhost_scsi_lun(struct spdk_jsonrpc_request *request,
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_strerror_r(-rc, buf, sizeof(buf));
|
||||
free_rpc_add_vhost_scsi_ctrlr_lun(&req);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
|
||||
}
|
||||
SPDK_RPC_REGISTER("add_vhost_scsi_lun", spdk_rpc_add_vhost_scsi_lun)
|
||||
|
||||
@ -244,6 +251,7 @@ spdk_rpc_remove_vhost_scsi_dev(struct spdk_jsonrpc_request *request,
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_vhost_dev *vdev;
|
||||
int rc;
|
||||
char buf[64];
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_vhost_remove_dev,
|
||||
SPDK_COUNTOF(rpc_vhost_remove_dev),
|
||||
@ -275,8 +283,9 @@ spdk_rpc_remove_vhost_scsi_dev(struct spdk_jsonrpc_request *request,
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_strerror_r(-rc, buf, sizeof(buf));
|
||||
free_rpc_remove_vhost_scsi_ctrlr_dev(&req);
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
|
||||
}
|
||||
SPDK_RPC_REGISTER("remove_vhost_scsi_dev", spdk_rpc_remove_vhost_scsi_dev)
|
||||
|
||||
@ -309,6 +318,7 @@ spdk_rpc_construct_vhost_blk_controller(struct spdk_jsonrpc_request *request,
|
||||
struct rpc_vhost_blk_ctrlr req = {0};
|
||||
struct spdk_json_write_ctx *w;
|
||||
int rc;
|
||||
char buf[64];
|
||||
uint64_t cpumask;
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_construct_vhost_blk_ctrlr,
|
||||
@ -342,9 +352,10 @@ spdk_rpc_construct_vhost_blk_controller(struct spdk_jsonrpc_request *request,
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_strerror_r(-rc, buf, sizeof(buf));
|
||||
free_rpc_vhost_blk_ctrlr(&req);
|
||||
spdk_jsonrpc_send_error_response(request,
|
||||
SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
|
||||
|
||||
}
|
||||
SPDK_RPC_REGISTER("construct_vhost_blk_controller", spdk_rpc_construct_vhost_blk_controller)
|
||||
@ -371,6 +382,7 @@ spdk_rpc_remove_vhost_blk_controller(struct spdk_jsonrpc_request *request,
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_vhost_dev *vdev;
|
||||
int rc;
|
||||
char buf[64];
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_remove_vhost_blk_ctrlr,
|
||||
SPDK_COUNTOF(rpc_remove_vhost_blk_ctrlr), &req)) {
|
||||
@ -401,9 +413,10 @@ spdk_rpc_remove_vhost_blk_controller(struct spdk_jsonrpc_request *request,
|
||||
return;
|
||||
|
||||
invalid:
|
||||
spdk_strerror_r(-rc, buf, sizeof(buf));
|
||||
free_rpc_remove_vhost_blk_ctrlr(&req);
|
||||
spdk_jsonrpc_send_error_response(request,
|
||||
SPDK_JSONRPC_ERROR_INVALID_PARAMS, strerror(-rc));
|
||||
SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf);
|
||||
|
||||
}
|
||||
SPDK_RPC_REGISTER("remove_vhost_blk_controller", spdk_rpc_remove_vhost_blk_controller)
|
||||
|
@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.app.mk
|
||||
|
||||
SPDK_LIB_LIST = log
|
||||
SPDK_LIB_LIST = log util
|
||||
|
||||
CFLAGS += -I$(SPDK_ROOT_DIR)/test
|
||||
CFLAGS += -I$(SPDK_ROOT_DIR)/lib/vhost
|
||||
|
Loading…
x
Reference in New Issue
Block a user