diff --git a/include/spdk/string.h b/include/spdk/string.h index dbb78fd76..e6e3f9334 100644 --- a/include/spdk/string.h +++ b/include/spdk/string.h @@ -98,6 +98,16 @@ char *spdk_str_trim(char *s); */ void spdk_strerror_r(int errnum, char *buf, size_t buflen); +/** + * Return the string version of an error from a static, thread-local buffer. + * This function is thread safe. + * + * \param errnum Error code + * + * \return pointer to buffer upon success. + */ +const char *spdk_strerror(int errnum); + /** * Remove trailing newlines from the end of a string in place. * diff --git a/lib/bdev/aio/bdev_aio.c b/lib/bdev/aio/bdev_aio.c index 0c7ba8277..11c8f34ae 100644 --- a/lib/bdev/aio/bdev_aio.c +++ b/lib/bdev/aio/bdev_aio.c @@ -66,16 +66,14 @@ static int bdev_aio_open(struct file_disk *disk) { int fd; - char buf[64]; fd = open(disk->filename, O_RDWR | O_DIRECT); if (fd < 0) { /* Try without O_DIRECT for non-disk files */ fd = open(disk->filename, O_RDWR); if (fd < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); SPDK_ERRLOG("open() failed (file:%s), errno %d: %s\n", - disk->filename, errno, buf); + disk->filename, errno, spdk_strerror(errno)); disk->fd = -1; return -1; } @@ -90,7 +88,6 @@ static int bdev_aio_close(struct file_disk *disk) { int rc; - char buf[64]; if (disk->fd == -1) { return 0; @@ -98,9 +95,8 @@ bdev_aio_close(struct file_disk *disk) rc = close(disk->fd); if (rc < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); SPDK_ERRLOG("close() failed (fd=%d), errno %d: %s\n", - disk->fd, errno, buf); + disk->fd, errno, spdk_strerror(errno)); return -1; } diff --git a/lib/bdev/lvol/vbdev_lvol_rpc.c b/lib/bdev/lvol/vbdev_lvol_rpc.c index dd67e57f1..359cef6fe 100644 --- a/lib/bdev/lvol/vbdev_lvol_rpc.c +++ b/lib/bdev/lvol/vbdev_lvol_rpc.c @@ -95,7 +95,6 @@ _spdk_rpc_lvol_store_construct_cb(void *cb_arg, struct spdk_lvol_store *lvol_sto struct spdk_json_write_ctx *w; char lvol_store_uuid[UUID_STRING_LEN]; struct spdk_jsonrpc_request *request = cb_arg; - char buf[64]; if (lvserrno != 0) { goto invalid; @@ -115,8 +114,8 @@ _spdk_rpc_lvol_store_construct_cb(void *cb_arg, struct spdk_lvol_store *lvol_sto return; invalid: - spdk_strerror_r(-lvserrno, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-lvserrno)); } static void @@ -126,7 +125,6 @@ spdk_rpc_construct_lvol_store(struct spdk_jsonrpc_request *request, struct rpc_construct_lvol_store req = {}; struct spdk_bdev *bdev; int rc; - char buf[64]; if (spdk_json_decode_object(params, rpc_construct_lvol_store_decoders, SPDK_COUNTOF(rpc_construct_lvol_store_decoders), @@ -164,8 +162,8 @@ spdk_rpc_construct_lvol_store(struct spdk_jsonrpc_request *request, return; invalid: - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); free_rpc_construct_lvol_store(&req); } SPDK_RPC_REGISTER("construct_lvol_store", spdk_rpc_construct_lvol_store) @@ -192,7 +190,6 @@ _spdk_rpc_lvol_store_destroy_cb(void *cb_arg, int lvserrno) { struct spdk_json_write_ctx *w; struct spdk_jsonrpc_request *request = cb_arg; - char buf[64]; if (lvserrno != 0) { goto invalid; @@ -208,8 +205,8 @@ _spdk_rpc_lvol_store_destroy_cb(void *cb_arg, int lvserrno) return; invalid: - spdk_strerror_r(-lvserrno, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-lvserrno)); } static void @@ -219,7 +216,6 @@ spdk_rpc_destroy_lvol_store(struct spdk_jsonrpc_request *request, struct rpc_destroy_lvol_store req = {}; struct spdk_lvol_store *lvs = NULL; int rc; - char buf[64]; if (spdk_json_decode_object(params, rpc_destroy_lvol_store_decoders, SPDK_COUNTOF(rpc_destroy_lvol_store_decoders), @@ -241,8 +237,8 @@ spdk_rpc_destroy_lvol_store(struct spdk_jsonrpc_request *request, return; invalid: - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); free_rpc_destroy_lvol_store(&req); } SPDK_RPC_REGISTER("destroy_lvol_store", spdk_rpc_destroy_lvol_store) @@ -274,7 +270,6 @@ _spdk_rpc_construct_lvol_bdev_cb(void *cb_arg, struct spdk_lvol *lvol, int lvole { struct spdk_json_write_ctx *w; struct spdk_jsonrpc_request *request = cb_arg; - char buf[64]; if (lvolerrno != 0) { goto invalid; @@ -292,8 +287,8 @@ _spdk_rpc_construct_lvol_bdev_cb(void *cb_arg, struct spdk_lvol *lvol, int lvole return; invalid: - spdk_strerror_r(-lvolerrno, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-lvolerrno)); } static void @@ -303,7 +298,6 @@ spdk_rpc_construct_lvol_bdev(struct spdk_jsonrpc_request *request, struct rpc_construct_lvol_bdev req = {}; size_t sz; int rc; - char buf[64]; struct spdk_lvol_store *lvs = NULL; SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "Creating blob\n"); @@ -338,8 +332,8 @@ spdk_rpc_construct_lvol_bdev(struct spdk_jsonrpc_request *request, return; invalid: - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); free_rpc_construct_lvol_bdev(&req); } @@ -366,7 +360,6 @@ _spdk_rpc_resize_lvol_bdev_cb(void *cb_arg, int lvolerrno) { struct spdk_json_write_ctx *w; struct spdk_jsonrpc_request *request = cb_arg; - char buf[64]; if (lvolerrno != 0) { goto invalid; @@ -382,8 +375,8 @@ _spdk_rpc_resize_lvol_bdev_cb(void *cb_arg, int lvolerrno) return; invalid: - spdk_strerror_r(-lvolerrno, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-lvolerrno)); } static void __attribute__((unused)) @@ -392,7 +385,6 @@ spdk_rpc_resize_lvol_bdev(struct spdk_jsonrpc_request *request, { struct rpc_resize_lvol_bdev req = {}; int rc = 0; - char buf[64]; SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "Resizing lvol\n"); @@ -419,8 +411,8 @@ spdk_rpc_resize_lvol_bdev(struct spdk_jsonrpc_request *request, return; invalid: - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); free_rpc_resize_lvol_bdev(&req); } diff --git a/lib/bdev/pmem/bdev_pmem_rpc.c b/lib/bdev/pmem/bdev_pmem_rpc.c index e90159e0a..8616ca9eb 100644 --- a/lib/bdev/pmem/bdev_pmem_rpc.c +++ b/lib/bdev/pmem/bdev_pmem_rpc.c @@ -63,7 +63,6 @@ spdk_rpc_construct_pmem_bdev(struct spdk_jsonrpc_request *request, struct rpc_construct_pmem req = {}; struct spdk_json_write_ctx *w; struct spdk_bdev *bdev; - char buf[64]; int rc; if (spdk_json_decode_object(params, rpc_construct_pmem_decoders, @@ -97,8 +96,7 @@ spdk_rpc_construct_pmem_bdev(struct spdk_jsonrpc_request *request, return; invalid: - spdk_strerror_r(rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(rc)); free_rpc_construct_pmem_bdev(&req); } SPDK_RPC_REGISTER("construct_pmem_bdev", spdk_rpc_construct_pmem_bdev) diff --git a/lib/bdev/virtio/bdev_virtio_rpc.c b/lib/bdev/virtio/bdev_virtio_rpc.c index 95c9b9d89..d0b9454fc 100644 --- a/lib/bdev/virtio/bdev_virtio_rpc.c +++ b/lib/bdev/virtio/bdev_virtio_rpc.c @@ -73,12 +73,11 @@ rpc_create_virtio_user_scsi_bdev_cb(void *ctx, int result, struct spdk_bdev **bd { struct rpc_virtio_user_scsi_dev *req = ctx; struct spdk_json_write_ctx *w; - char buf[64]; size_t i; if (result) { - spdk_strerror_r(-result, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(req->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(req->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-result)); free_rpc_connect_virtio_user_scsi_dev(req); return; } @@ -103,7 +102,6 @@ spdk_rpc_create_virtio_user_scsi_bdev(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) { struct rpc_virtio_user_scsi_dev *req; - char buf[64]; int rc; req = calloc(1, sizeof(*req)); @@ -132,8 +130,8 @@ spdk_rpc_create_virtio_user_scsi_bdev(struct spdk_jsonrpc_request *request, return; invalid: - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); free_rpc_connect_virtio_user_scsi_dev(req); } SPDK_RPC_REGISTER("construct_virtio_user_scsi_bdev", spdk_rpc_create_virtio_user_scsi_bdev); diff --git a/lib/iscsi/acceptor.c b/lib/iscsi/acceptor.c index 107f71ade..096d8abb3 100644 --- a/lib/iscsi/acceptor.c +++ b/lib/iscsi/acceptor.c @@ -50,7 +50,6 @@ spdk_iscsi_portal_accept(void *arg) { struct spdk_iscsi_portal *portal = arg; int rc, sock; - char buf[64]; if (portal->sock < 0) { return; @@ -68,8 +67,7 @@ spdk_iscsi_portal_accept(void *arg) } } else { if (errno != EAGAIN && errno != EWOULDBLOCK) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("accept error(%d): %s\n", errno, buf); + SPDK_ERRLOG("accept error(%d): %s\n", errno, spdk_strerror(errno)); } break; } diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index d76e24c83..c36178fff 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -143,13 +143,10 @@ spdk_find_iscsi_connection_by_id(int cid) static int init_idle_conns(void) { - char buf[64]; - assert(g_poll_fd == 0); g_poll_fd = kqueue(); if (g_poll_fd < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("kqueue() failed, errno %d: %s\n", errno, buf); + SPDK_ERRLOG("kqueue() failed, errno %d: %s\n", errno, spdk_strerror(errno)); return -1; } @@ -179,7 +176,6 @@ del_idle_conn(struct spdk_iscsi_conn *conn) { struct kevent event; struct timespec ts = {0}; - char buf[64]; int rc; EV_SET(&event, conn->sock, EVFILT_READ, EV_DELETE, 0, 0, NULL); @@ -190,8 +186,7 @@ del_idle_conn(struct spdk_iscsi_conn *conn) return -1; } if (event.flags & EV_ERROR) { - spdk_strerror_r(event.data, buf, sizeof(buf)); - SPDK_ERRLOG("kevent(EV_DELETE) failed: %s\n", buf); + SPDK_ERRLOG("kevent(EV_DELETE) failed: %s\n", spdk_strerror(event.data)); return -1; } @@ -248,13 +243,10 @@ check_idle_conns(void) static int init_idle_conns(void) { - char buf[64]; - assert(g_poll_fd == 0); g_poll_fd = epoll_create1(0); if (g_poll_fd < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("epoll_create1() failed, errno %d: %s\n", errno, buf); + SPDK_ERRLOG("epoll_create1() failed, errno %d: %s\n", errno, spdk_strerror(errno)); return -1; } @@ -963,7 +955,6 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes, void *buf) { int ret; - char errbuf[64]; if (bytes == 0) { return 0; @@ -979,9 +970,8 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes, if (errno == EAGAIN || errno == EWOULDBLOCK) { return 0; } else { - spdk_strerror_r(errno, errbuf, sizeof(errbuf)); SPDK_ERRLOG("spdk_sock_recv() failed (fd=%d), errno %d: %s\n", - conn->sock, errno, errbuf); + conn->sock, errno, spdk_strerror(errno)); } return SPDK_ISCSI_CONNECTION_FATAL; } @@ -1189,7 +1179,6 @@ 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); @@ -1238,9 +1227,8 @@ spdk_iscsi_conn_flush_pdus_internal(struct spdk_iscsi_conn *conn) if (errno == EWOULDBLOCK || errno == EAGAIN) { return 0; } else { - spdk_strerror_r(errno, buf, sizeof(buf)); SPDK_ERRLOG("spdk_sock_writev() failed (fd=%d), errno %d: %s\n", - conn->sock, errno, buf); + conn->sock, errno, spdk_strerror(errno)); return -1; } } diff --git a/lib/jsonrpc/jsonrpc_server_tcp.c b/lib/jsonrpc/jsonrpc_server_tcp.c index 3a44ec823..18a3ae3e3 100644 --- a/lib/jsonrpc/jsonrpc_server_tcp.c +++ b/lib/jsonrpc/jsonrpc_server_tcp.c @@ -41,7 +41,6 @@ spdk_jsonrpc_server_listen(int domain, int protocol, { struct spdk_jsonrpc_server *server; int rc, val, flag; - char buf[64]; server = calloc(1, sizeof(struct spdk_jsonrpc_server)); if (server == NULL) { @@ -65,8 +64,8 @@ spdk_jsonrpc_server_listen(int domain, int protocol, flag = fcntl(server->sockfd, F_GETFL); if (fcntl(server->sockfd, F_SETFL, flag | O_NONBLOCK) < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", server->sockfd, buf); + SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", + server->sockfd, spdk_strerror(errno)); close(server->sockfd); free(server); return NULL; @@ -74,8 +73,7 @@ spdk_jsonrpc_server_listen(int domain, int protocol, rc = bind(server->sockfd, listen_addr, addrlen); if (rc != 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("could not bind JSON-RPC server: %s\n", buf); + SPDK_ERRLOG("could not bind JSON-RPC server: %s\n", spdk_strerror(errno)); close(server->sockfd); free(server); return NULL; @@ -137,7 +135,6 @@ spdk_jsonrpc_server_accept(struct spdk_jsonrpc_server *server) { struct spdk_jsonrpc_server_conn *conn; int rc, conn_idx, flag; - char buf[64]; rc = accept(server->sockfd, NULL, NULL); if (rc >= 0) { @@ -159,8 +156,8 @@ spdk_jsonrpc_server_accept(struct spdk_jsonrpc_server *server) flag = fcntl(conn->sockfd, F_GETFL); if (fcntl(conn->sockfd, F_SETFL, flag | O_NONBLOCK) < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", conn->sockfd, buf); + SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", + conn->sockfd, spdk_strerror(errno)); close(conn->sockfd); return -1; } @@ -223,15 +220,13 @@ 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_strerror_r(errno, buf, sizeof(buf)); - SPDK_DEBUGLOG(SPDK_LOG_RPC, "recv() failed: %s\n", buf); + SPDK_DEBUGLOG(SPDK_LOG_RPC, "recv() failed: %s\n", spdk_strerror(errno)); return -1; } @@ -274,7 +269,6 @@ 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) { @@ -300,8 +294,7 @@ more: return 0; } - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_DEBUGLOG(SPDK_LOG_RPC, "send() failed: %s\n", buf); + SPDK_DEBUGLOG(SPDK_LOG_RPC, "send() failed: %s\n", spdk_strerror(errno)); return -1; } diff --git a/lib/nbd/nbd.c b/lib/nbd/nbd.c index 57567b21c..f640600b5 100644 --- a/lib/nbd/nbd.c +++ b/lib/nbd/nbd.c @@ -493,14 +493,12 @@ static void spdk_nbd_poll(void *arg) { struct spdk_nbd_disk *nbd = arg; - char buf[64]; int rc; rc = _spdk_nbd_poll(nbd); if (rc < 0) { - spdk_strerror_r(-rc, buf, sizeof(buf)); SPDK_INFOLOG(SPDK_LOG_NBD, "spdk_nbd_poll() returned %s (%d); closing connection\n", - buf, rc); + spdk_strerror(-rc), rc); spdk_nbd_stop(nbd); } } @@ -534,7 +532,6 @@ spdk_nbd_start(const char *bdev_name, const char *nbd_path) pthread_t tid; int rc; int sp[2]; - char buf[64]; int flag; bdev = spdk_bdev_get_by_name(bdev_name); @@ -584,29 +581,25 @@ spdk_nbd_start(const char *bdev_name, const char *nbd_path) nbd->dev_fd = open(nbd_path, O_RDWR); if (nbd->dev_fd == -1) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("open(\"%s\") failed: %s\n", nbd_path, buf); + SPDK_ERRLOG("open(\"%s\") failed: %s\n", nbd_path, spdk_strerror(errno)); goto err; } rc = ioctl(nbd->dev_fd, NBD_SET_BLKSIZE, spdk_bdev_get_block_size(bdev)); if (rc == -1) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("ioctl(NBD_SET_BLKSIZE) failed: %s\n", buf); + SPDK_ERRLOG("ioctl(NBD_SET_BLKSIZE) failed: %s\n", spdk_strerror(errno)); goto err; } rc = ioctl(nbd->dev_fd, NBD_SET_SIZE_BLOCKS, spdk_bdev_get_num_blocks(bdev)); if (rc == -1) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("ioctl(NBD_SET_SIZE_BLOCKS) failed: %s\n", buf); + SPDK_ERRLOG("ioctl(NBD_SET_SIZE_BLOCKS) failed: %s\n", spdk_strerror(errno)); goto err; } rc = ioctl(nbd->dev_fd, NBD_CLEAR_SOCK); if (rc == -1) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("ioctl(NBD_CLEAR_SOCK) failed: %s\n", buf); + SPDK_ERRLOG("ioctl(NBD_CLEAR_SOCK) failed: %s\n", spdk_strerror(errno)); goto err; } @@ -615,38 +608,34 @@ spdk_nbd_start(const char *bdev_name, const char *nbd_path) rc = ioctl(nbd->dev_fd, NBD_SET_SOCK, nbd->kernel_sp_fd); if (rc == -1) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("ioctl(NBD_SET_SOCK) failed: %s\n", buf); + SPDK_ERRLOG("ioctl(NBD_SET_SOCK) failed: %s\n", spdk_strerror(errno)); goto err; } #ifdef NBD_FLAG_SEND_TRIM rc = ioctl(nbd->dev_fd, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM); if (rc == -1) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("ioctl(NBD_SET_FLAGS) failed: %s\n", buf); + SPDK_ERRLOG("ioctl(NBD_SET_FLAGS) failed: %s\n", spdk_strerror(errno)); goto err; } #endif rc = pthread_create(&tid, NULL, nbd_start_kernel, (void *)(intptr_t)nbd->dev_fd); if (rc != 0) { - spdk_strerror_r(rc, buf, sizeof(buf)); - SPDK_ERRLOG("could not create thread: %s\n", buf); + SPDK_ERRLOG("could not create thread: %s\n", spdk_strerror(rc)); goto err; } rc = pthread_detach(tid); if (rc != 0) { - spdk_strerror_r(rc, buf, sizeof(buf)); - SPDK_ERRLOG("could not detach thread for nbd kernel: %s\n", buf); + SPDK_ERRLOG("could not detach thread for nbd kernel: %s\n", spdk_strerror(rc)); goto err; } flag = fcntl(nbd->spdk_sp_fd, F_GETFL); if (fcntl(nbd->spdk_sp_fd, F_SETFL, flag | O_NONBLOCK) < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", nbd->spdk_sp_fd, buf); + SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", + nbd->spdk_sp_fd, spdk_strerror(errno)); goto err; } diff --git a/lib/nbd/nbd_rpc.c b/lib/nbd/nbd_rpc.c index 478b4e5b9..ee63038bd 100644 --- a/lib/nbd/nbd_rpc.c +++ b/lib/nbd/nbd_rpc.c @@ -156,7 +156,6 @@ spdk_rpc_stop_nbd_disk(struct spdk_jsonrpc_request *request, struct spdk_nbd_disk *nbd; pthread_t tid; struct nbd_disconnect_arg *thd_arg = NULL; - char buf[64]; int rc; if (spdk_json_decode_object(params, rpc_stop_nbd_disk_decoders, @@ -188,9 +187,8 @@ spdk_rpc_stop_nbd_disk(struct spdk_jsonrpc_request *request, */ thd_arg = malloc(sizeof(*thd_arg)); if (!thd_arg) { - spdk_strerror_r(-ENOMEM, buf, sizeof(buf)); - SPDK_ERRLOG("could not allocate nbd disconnect thread arg: %s\n", buf); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, buf); + SPDK_ERRLOG("could not allocate nbd disconnect thread arg\n"); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory"); goto out; } @@ -203,17 +201,15 @@ spdk_rpc_stop_nbd_disk(struct spdk_jsonrpc_request *request, */ rc = pthread_create(&tid, NULL, nbd_disconnect_thread, (void *)thd_arg); if (rc != 0) { - spdk_strerror_r(rc, buf, sizeof(buf)); - SPDK_ERRLOG("could not create nbd disconnect thread: %s\n", buf); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, buf); + SPDK_ERRLOG("could not create nbd disconnect thread: %s\n", spdk_strerror(rc)); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, spdk_strerror(rc)); free(thd_arg); goto out; } rc = pthread_detach(tid); if (rc != 0) { - spdk_strerror_r(rc, buf, sizeof(buf)); - SPDK_ERRLOG("could not detach nbd disconnect thread: %s\n", buf); + SPDK_ERRLOG("could not detach nbd disconnect thread: %s\n", spdk_strerror(rc)); goto out; } diff --git a/lib/net/interface.c b/lib/net/interface.c index a9e19d928..806a5577f 100644 --- a/lib/net/interface.c +++ b/lib/net/interface.c @@ -51,7 +51,6 @@ static uint32_t spdk_get_ifc_ipv4(void) int ret; int rtattrlen; int netlink_fd; - char errbuf[64]; uint32_t ipv4_addr; struct { @@ -91,16 +90,14 @@ 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_strerror_r(errno, errbuf, sizeof(errbuf)); - SPDK_ERRLOG("netlink send failed: %s\n", errbuf); + SPDK_ERRLOG("netlink send failed: %s\n", spdk_strerror(errno)); ret = 1; goto exit; } ret = recv(netlink_fd, buf, sizeof(buf), 0); if (ret <= 0) { - spdk_strerror_r(errno, errbuf, sizeof(errbuf)); - SPDK_ERRLOG("netlink recv failed: %s\n", errbuf); + SPDK_ERRLOG("netlink recv failed: %s\n", spdk_strerror(errno)); ret = 1; goto exit; } diff --git a/lib/nvme/nvme_rdma.c b/lib/nvme/nvme_rdma.c index f9b9b18aa..cfa49e74b 100644 --- a/lib/nvme/nvme_rdma.c +++ b/lib/nvme/nvme_rdma.c @@ -197,13 +197,11 @@ 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, buf); + errno, spdk_strerror(errno)); return NULL; } @@ -223,13 +221,10 @@ 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, buf); + SPDK_ERRLOG("Unable to create completion queue: errno %d: %s\n", errno, spdk_strerror(errno)); return -1; } @@ -1410,7 +1405,6 @@ 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); @@ -1437,8 +1431,7 @@ nvme_rdma_qpair_submit_request(struct spdk_nvme_qpair *qpair, rc = ibv_post_send(rqpair->cm_id->qp, wr, &bad_wr); if (rc) { - spdk_strerror_r(rc, buf, sizeof(buf)); - SPDK_ERRLOG("Failure posting rdma send for NVMf completion: %d (%s)\n", rc, buf); + SPDK_ERRLOG("Failure posting rdma send for NVMf completion: %d (%s)\n", rc, spdk_strerror(rc)); } return rc; @@ -1495,7 +1488,6 @@ 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; @@ -1511,9 +1503,8 @@ 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, buf); + errno, spdk_strerror(errno)); return -1; } else if (rc == 0) { /* Ran out of completions */ diff --git a/lib/nvme/nvme_uevent.c b/lib/nvme/nvme_uevent.c index 6be46bb81..724cbc5c0 100644 --- a/lib/nvme/nvme_uevent.c +++ b/lib/nvme/nvme_uevent.c @@ -51,7 +51,6 @@ spdk_uevent_connect(void) struct sockaddr_nl addr; int netlink_fd; int size = 64 * 1024; - char buf[64]; int flag; memset(&addr, 0, sizeof(addr)); @@ -68,8 +67,8 @@ spdk_uevent_connect(void) flag = fcntl(netlink_fd, F_GETFL); if (fcntl(netlink_fd, F_SETFL, flag | O_NONBLOCK) < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", netlink_fd, buf); + SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", netlink_fd, + spdk_strerror(errno)); close(netlink_fd); return -1; } @@ -174,7 +173,6 @@ 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); @@ -188,8 +186,7 @@ spdk_get_uevent(int fd, struct spdk_uevent *uevent) if (errno == EAGAIN || errno == EWOULDBLOCK) { return 0; } else { - spdk_strerror_r(errno, errbuf, sizeof(errbuf)); - SPDK_ERRLOG("Socket read error(%d): %s\n", errno, errbuf); + SPDK_ERRLOG("Socket read error(%d): %s\n", errno, spdk_strerror(errno)); return -1; } } diff --git a/lib/nvmf/rdma.c b/lib/nvmf/rdma.c index c23d2d17c..1f26834d2 100644 --- a/lib/nvmf/rdma.c +++ b/lib/nvmf/rdma.c @@ -336,7 +336,6 @@ spdk_nvmf_rdma_qpair_initialize(struct spdk_nvmf_qpair *qpair) struct ibv_qp_init_attr attr; struct spdk_nvmf_rdma_recv *rdma_recv; struct spdk_nvmf_rdma_request *rdma_req; - char buf[64]; rqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_rdma_qpair, qpair); rtransport = SPDK_CONTAINEROF(qpair->transport, struct spdk_nvmf_rdma_transport, transport); @@ -352,9 +351,7 @@ spdk_nvmf_rdma_qpair_initialize(struct spdk_nvmf_qpair *qpair) rc = rdma_create_qp(rqpair->cm_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, buf); + SPDK_ERRLOG("rdma_create_qp failed: errno %d: %s\n", errno, spdk_strerror(errno)); rdma_destroy_id(rqpair->cm_id); spdk_nvmf_rdma_qpair_destroy(rqpair); return -1; @@ -1122,7 +1119,6 @@ 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]; int flag; rtransport = calloc(1, sizeof(*rtransport)); @@ -1145,17 +1141,15 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_tgt *tgt) rtransport->event_channel = rdma_create_event_channel(); if (rtransport->event_channel == NULL) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("rdma_create_event_channel() failed, %s\n", buf); + SPDK_ERRLOG("rdma_create_event_channel() failed, %s\n", spdk_strerror(errno)); free(rtransport); return NULL; } flag = fcntl(rtransport->event_channel->fd, F_GETFL); if (fcntl(rtransport->event_channel->fd, F_SETFL, flag | O_NONBLOCK) < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", - rtransport->event_channel->fd, buf); + rtransport->event_channel->fd, spdk_strerror(errno)); free(rtransport); return NULL; } @@ -1404,7 +1398,6 @@ spdk_nvmf_rdma_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn) struct spdk_nvmf_rdma_transport *rtransport; struct rdma_cm_event *event; int rc; - char buf[64]; rtransport = SPDK_CONTAINEROF(transport, struct spdk_nvmf_rdma_transport, transport); @@ -1445,8 +1438,7 @@ spdk_nvmf_rdma_accept(struct spdk_nvmf_transport *transport, new_qpair_fn cb_fn) rdma_ack_cm_event(event); } else { if (errno != EAGAIN && errno != EWOULDBLOCK) { - spdk_strerror_r(errno, buf, sizeof(buf)); - SPDK_ERRLOG("Acceptor Event Error: %s\n", buf); + SPDK_ERRLOG("Acceptor Event Error: %s\n", spdk_strerror(errno)); } break; } @@ -1759,14 +1751,12 @@ spdk_nvmf_rdma_poller_poll(struct spdk_nvmf_rdma_transport *rtransport, int reaped, i; int count = 0; bool error = false; - char buf[64]; /* Poll for completing operations. */ reaped = ibv_poll_cq(rpoller->cq, 32, wc); if (reaped < 0) { - spdk_strerror_r(errno, buf, sizeof(buf)); SPDK_ERRLOG("Error polling CQ! (%d): %s\n", - errno, buf); + errno, spdk_strerror(errno)); return -1; } diff --git a/lib/trace/trace.c b/lib/trace/trace.c index fdc0de804..6d48ac5e8 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -89,15 +89,13 @@ spdk_trace_init(const char *shm_name) { 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, buf); + fprintf(stderr, "errno=%d %s\n", errno, spdk_strerror(errno)); exit(EXIT_FAILURE); } diff --git a/lib/util/Makefile b/lib/util/Makefile index cf2379fe2..433f0f060 100644 --- a/lib/util/Makefile +++ b/lib/util/Makefile @@ -34,7 +34,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -C_SRCS = bit_array.c crc16.c crc32.c crc32c.c crc32_ieee.c fd.c io_channel.c string.c +C_SRCS = bit_array.c crc16.c crc32.c crc32c.c crc32_ieee.c fd.c io_channel.c strerror_tls.c string.c LIBNAME = util include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/util/strerror_tls.c b/lib/util/strerror_tls.c new file mode 100644 index 000000000..c9dc8f13f --- /dev/null +++ b/lib/util/strerror_tls.c @@ -0,0 +1,43 @@ +/*- + * BSD LICENSE + * + * Copyright (c) Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "spdk/string.h" + +static __thread char strerror_message[64]; + +const char * +spdk_strerror(int errnum) +{ + spdk_strerror_r(errnum, strerror_message, sizeof(strerror_message)); + return strerror_message; +} diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 0d49f59a0..f07f8933a 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -507,7 +507,6 @@ spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, const ch unsigned ctrlr_num; char path[PATH_MAX]; struct stat file_stat; - char buf[64]; uint64_t cpumask; assert(vdev); @@ -596,9 +595,8 @@ spdk_vhost_dev_construct(struct spdk_vhost_dev *vdev, const char *name, const ch 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\n", name, errno, - buf); + spdk_strerror(errno)); rte_vhost_driver_unregister(path); return -EIO; } @@ -1009,7 +1007,6 @@ void spdk_vhost_shutdown_cb(void) { pthread_t tid; - char buf[64]; int rc; struct spdk_event *vhost_app_stop; @@ -1017,8 +1014,7 @@ spdk_vhost_shutdown_cb(void) rc = pthread_create(&tid, NULL, &session_shutdown, vhost_app_stop); if (rc < 0) { - spdk_strerror_r(rc, buf, sizeof(buf)); - SPDK_ERRLOG("Failed to start session shutdown thread (%d): %s\n", rc, buf); + SPDK_ERRLOG("Failed to start session shutdown thread (%d): %s\n", rc, spdk_strerror(rc)); abort(); } pthread_detach(tid); diff --git a/lib/vhost/vhost_rpc.c b/lib/vhost/vhost_rpc.c index e3f53adee..36c2b6f03 100644 --- a/lib/vhost/vhost_rpc.c +++ b/lib/vhost/vhost_rpc.c @@ -68,7 +68,6 @@ 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]; if (spdk_json_decode_object(params, rpc_construct_vhost_ctrlr, SPDK_COUNTOF(rpc_construct_vhost_ctrlr), @@ -95,9 +94,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, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); } SPDK_RPC_REGISTER("construct_vhost_scsi_controller", spdk_rpc_construct_vhost_scsi_controller) @@ -130,7 +129,6 @@ spdk_rpc_add_vhost_scsi_lun_cb(struct spdk_vhost_dev *vdev, void *arg) struct spdk_jsonrpc_request *request = rpc->request; struct spdk_json_write_ctx *w; int rc; - char buf[64]; if (vdev == NULL) { rc = -ENODEV; @@ -155,8 +153,8 @@ spdk_rpc_add_vhost_scsi_lun_cb(struct spdk_vhost_dev *vdev, void *arg) invalid: free_rpc_add_vhost_scsi_ctrlr_lun(rpc); - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); return rc; } @@ -165,7 +163,6 @@ spdk_rpc_add_vhost_scsi_lun(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) { struct rpc_add_vhost_scsi_ctrlr_lun *req; - char buf[64]; int rc; req = calloc(1, sizeof(*req)); @@ -197,8 +194,8 @@ invalid: if (req) { free_rpc_add_vhost_scsi_ctrlr_lun(req); } - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); } SPDK_RPC_REGISTER("add_vhost_scsi_lun", spdk_rpc_add_vhost_scsi_lun) @@ -245,7 +242,6 @@ spdk_rpc_remove_vhost_scsi_target_cb(struct spdk_vhost_dev *vdev, void *arg) { struct rpc_remove_vhost_scsi_ctrlr_target *rpc = arg; struct spdk_jsonrpc_request *request = rpc->request; - char buf[64]; int rc; if (vdev == NULL) { @@ -263,8 +259,7 @@ spdk_rpc_remove_vhost_scsi_target_cb(struct spdk_vhost_dev *vdev, void *arg) invalid: free_rpc_remove_vhost_scsi_ctrlr_target(rpc); - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_strerror(-rc)); return rc; } @@ -274,7 +269,6 @@ spdk_rpc_remove_vhost_scsi_target(struct spdk_jsonrpc_request *request, { struct rpc_remove_vhost_scsi_ctrlr_target *req; int rc; - char buf[64]; req = calloc(1, sizeof(*req)); if (req == NULL) { @@ -299,8 +293,8 @@ invalid: if (req) { free_rpc_remove_vhost_scsi_ctrlr_target(req); } - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); } SPDK_RPC_REGISTER("remove_vhost_scsi_target", spdk_rpc_remove_vhost_scsi_target) @@ -334,7 +328,6 @@ 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]; if (spdk_json_decode_object(params, rpc_construct_vhost_blk_ctrlr, SPDK_COUNTOF(rpc_construct_vhost_blk_ctrlr), @@ -361,10 +354,9 @@ 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, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); } SPDK_RPC_REGISTER("construct_vhost_blk_controller", spdk_rpc_construct_vhost_blk_controller) @@ -393,7 +385,6 @@ spdk_rpc_remove_vhost_controller_cb(struct spdk_vhost_dev *vdev, void *arg) struct spdk_jsonrpc_request *request = ctx->request; struct spdk_json_write_ctx *w; int rc; - char buf[64]; if (vdev == NULL) { rc = -ENODEV; @@ -418,9 +409,8 @@ spdk_rpc_remove_vhost_controller_cb(struct spdk_vhost_dev *vdev, void *arg) invalid: free_rpc_remove_vhost_ctrlr(ctx); - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, - SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); return -1; } @@ -429,7 +419,6 @@ spdk_rpc_remove_vhost_controller(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) { struct rpc_remove_vhost_ctrlr *req; - char buf[64]; int rc; req = calloc(1, sizeof(*req)); @@ -453,9 +442,8 @@ invalid: if (req) { free_rpc_remove_vhost_ctrlr(req); } - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, - SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); } SPDK_RPC_REGISTER("remove_vhost_controller", spdk_rpc_remove_vhost_controller) @@ -503,7 +491,6 @@ spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request, { struct rpc_get_vhost_ctrlrs *ctx; struct spdk_json_write_ctx *w; - char buf[64]; if (params != NULL) { spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, @@ -520,8 +507,8 @@ spdk_rpc_get_vhost_controllers(struct spdk_jsonrpc_request *request, ctx = calloc(1, sizeof(*ctx)); if (ctx == NULL) { - spdk_strerror_r(-ENOMEM, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, + spdk_strerror(ENOMEM)); return; } @@ -561,7 +548,6 @@ spdk_rpc_set_vhost_controller_coalescing_cb(struct spdk_vhost_dev *vdev, void *a { struct rpc_vhost_ctrlr_coalescing *req = arg; struct spdk_json_write_ctx *w; - char buf[64]; int rc; if (vdev == NULL) { @@ -584,8 +570,8 @@ spdk_rpc_set_vhost_controller_coalescing_cb(struct spdk_vhost_dev *vdev, void *a return 0; invalid: - spdk_strerror_r(-rc, buf, sizeof(buf)); - spdk_jsonrpc_send_error_response(req->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(req->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); free_rpc_set_vhost_controllers_event_coalescing(req); return 0; } @@ -595,7 +581,6 @@ spdk_rpc_set_vhost_controller_coalescing(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) { struct rpc_vhost_ctrlr_coalescing *req; - char buf[64]; int rc; req = calloc(1, sizeof(struct rpc_vhost_ctrlr_coalescing)); @@ -616,9 +601,9 @@ spdk_rpc_set_vhost_controller_coalescing(struct spdk_jsonrpc_request *request, return; invalid: - spdk_strerror_r(-rc, buf, sizeof(buf)); free_rpc_set_vhost_controllers_event_coalescing(req); - spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, + spdk_strerror(-rc)); } SPDK_RPC_REGISTER("set_vhost_controller_coalescing", spdk_rpc_set_vhost_controller_coalescing) diff --git a/lib/virtio/virtio_user.c b/lib/virtio/virtio_user.c index d7010cc42..0d7adf774 100644 --- a/lib/virtio/virtio_user.c +++ b/lib/virtio/virtio_user.c @@ -237,12 +237,10 @@ static uint64_t virtio_user_get_features(struct virtio_dev *vdev) { struct virtio_user_dev *dev = vdev->ctx; - char err_str[64]; uint64_t features; if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES, &features) < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_ERRLOG("get_features failed: %s\n", err_str); + SPDK_ERRLOG("get_features failed: %s\n", spdk_strerror(errno)); return 0; } @@ -285,7 +283,6 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq) struct virtio_user_dev *dev = vdev->ctx; uint16_t queue_idx = vq->vq_queue_index; uint64_t desc_addr, avail_addr, used_addr; - char err_str[64]; int callfd; int kickfd; @@ -300,15 +297,13 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq) */ callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (callfd < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_ERRLOG("callfd error, %s\n", err_str); + SPDK_ERRLOG("callfd error, %s\n", spdk_strerror(errno)); return -1; } kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (kickfd < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_ERRLOG("kickfd error, %s\n", err_str); + SPDK_ERRLOG("kickfd error, %s\n", spdk_strerror(errno)); close(callfd); return -1; } @@ -355,11 +350,9 @@ virtio_user_notify_queue(struct virtio_dev *vdev, struct virtqueue *vq) { uint64_t buf = 1; struct virtio_user_dev *dev = vdev->ctx; - char err_str[64]; if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_ERRLOG("failed to kick backend: %s.\n", err_str); + SPDK_ERRLOG("failed to kick backend: %s.\n", spdk_strerror(errno)); } } @@ -405,7 +398,6 @@ virtio_user_dev_init(struct virtio_dev *vdev, const char *name, const char *path uint32_t queue_size) { struct virtio_user_dev *dev; - char err_str[64]; int rc; if (name == NULL) { @@ -441,8 +433,7 @@ virtio_user_dev_init(struct virtio_dev *vdev, const char *name, const char *path } if (dev->ops->send_request(dev, VHOST_USER_SET_OWNER, NULL) < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_ERRLOG("set_owner fails: %s\n", err_str); + SPDK_ERRLOG("set_owner fails: %s\n", spdk_strerror(errno)); goto err; } diff --git a/lib/virtio/virtio_user/vhost_user.c b/lib/virtio/virtio_user/vhost_user.c index db68dade0..59ea1e075 100644 --- a/lib/virtio/virtio_user/vhost_user.c +++ b/lib/virtio/virtio_user/vhost_user.c @@ -289,7 +289,6 @@ vhost_user_sock(struct virtio_user_dev *dev, { struct vhost_user_msg msg; struct vhost_vring_file *file = 0; - char err_str[64]; int need_reply = 0; int fds[VHOST_MEMORY_MAX_NREGIONS]; int fd_num = 0; @@ -370,9 +369,8 @@ vhost_user_sock(struct virtio_user_dev *dev, len = VHOST_USER_HDR_SIZE + msg.size; if (vhost_user_write(vhostfd, &msg, len, fds, fd_num) < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); SPDK_ERRLOG("%s failed: %s\n", - vhost_msg_strings[req], err_str); + vhost_msg_strings[req], spdk_strerror(errno)); return -1; } @@ -383,8 +381,7 @@ vhost_user_sock(struct virtio_user_dev *dev, if (need_reply) { if (vhost_user_read(vhostfd, &msg) < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_WARNLOG("Received msg failed: %s\n", err_str); + SPDK_WARNLOG("Received msg failed: %s\n", spdk_strerror(errno)); return -1; } @@ -433,19 +430,16 @@ vhost_user_setup(struct virtio_user_dev *dev) int flag; struct sockaddr_un un; ssize_t rc; - char err_str[64]; fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_ERRLOG("socket() error, %s\n", err_str); + SPDK_ERRLOG("socket() error, %s\n", spdk_strerror(errno)); return -1; } flag = fcntl(fd, F_GETFD); if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_ERRLOG("fcntl failed, %s\n", err_str); + SPDK_ERRLOG("fcntl failed, %s\n", spdk_strerror(errno)); } memset(&un, 0, sizeof(un)); @@ -457,8 +451,7 @@ vhost_user_setup(struct virtio_user_dev *dev) return -1; } if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) { - spdk_strerror_r(errno, err_str, sizeof(err_str)); - SPDK_ERRLOG("connect error, %s\n", err_str); + SPDK_ERRLOG("connect error, %s\n", spdk_strerror(errno)); close(fd); return -1; } diff --git a/test/app/stub/Makefile b/test/app/stub/Makefile index 21fcbfa45..b87634123 100644 --- a/test/app/stub/Makefile +++ b/test/app/stub/Makefile @@ -39,7 +39,7 @@ APP = stub C_SRCS := stub.c -SPDK_LIB_LIST = event conf nvme util log trace rpc jsonrpc json +SPDK_LIB_LIST = event conf nvme log trace rpc jsonrpc json util LIBS += $(SPDK_LIB_LINKER_ARGS) LIBS += $(ENV_LINKER_ARGS) diff --git a/test/unit/lib/iscsi/iscsi.c/Makefile b/test/unit/lib/iscsi/iscsi.c/Makefile index 76b095e7a..f0eaf19c6 100644 --- a/test/unit/lib/iscsi/iscsi.c/Makefile +++ b/test/unit/lib/iscsi/iscsi.c/Makefile @@ -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 util cunit trace conf +SPDK_LIB_LIST = log cunit trace conf util CFLAGS += -I$(SPDK_ROOT_DIR)/test CFLAGS += -I$(SPDK_ROOT_DIR)/lib