rte_vhost: replace strerror() with spdk_strerror_r()

strerror() is potentially not thread safe; use the thread-safe SPDK
wrapper instead.

Change-Id: I5f6f4b0b19a0298b07f71f05aee4574e8b21f5fa
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/382732
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2017-10-16 14:46:01 -07:00 committed by Jim Harris
parent 69a0f437db
commit bd273d4789
3 changed files with 34 additions and 12 deletions

View File

@ -49,6 +49,8 @@
#include "virtio_pci.h"
#include "virtio_user/virtio_user_dev.h"
#include "spdk/string.h"
#define virtio_dev_get_user_dev(dev) \
((struct virtio_user_dev *)((uintptr_t)(dev) - offsetof(struct virtio_user_dev, vdev)))
@ -92,10 +94,12 @@ static uint64_t
virtio_user_get_features(struct virtio_dev *vdev)
{
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
char err_str[64];
uint64_t features;
if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES, &features) < 0) {
SPDK_ERRLOG("get_features failed: %s\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("get_features failed: %s\n", err_str);
return 0;
}
@ -163,6 +167,7 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
uint16_t queue_idx = vq->vq_queue_index;
uint64_t desc_addr, avail_addr, used_addr;
char err_str[64];
int callfd;
int kickfd;
@ -177,13 +182,15 @@ virtio_user_setup_queue(struct virtio_dev *vdev, struct virtqueue *vq)
*/
callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (callfd < 0) {
SPDK_ERRLOG("callfd error, %s\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("callfd error, %s\n", err_str);
return -1;
}
kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (kickfd < 0) {
SPDK_ERRLOG("kickfd error, %s\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("kickfd error, %s\n", err_str);
close(callfd);
return -1;
}
@ -230,9 +237,11 @@ virtio_user_notify_queue(struct virtio_dev *vdev, struct virtqueue *vq)
{
uint64_t buf = 1;
struct virtio_user_dev *dev = virtio_dev_get_user_dev(vdev);
char err_str[64];
if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0)
SPDK_ERRLOG("failed to kick backend: %s.\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("failed to kick backend: %s.\n", err_str);
}
static void

View File

@ -43,6 +43,8 @@
#include "vhost.h"
#include "virtio_user_dev.h"
#include "spdk/string.h"
/* The version of the protocol we support */
#define VHOST_USER_VERSION 0x1
@ -282,6 +284,7 @@ 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;
@ -362,8 +365,9 @@ 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], strerror(errno));
vhost_msg_strings[req], err_str);
return -1;
}
@ -373,8 +377,8 @@ vhost_user_sock(struct virtio_user_dev *dev,
if (need_reply) {
if (vhost_user_read(vhostfd, &msg) < 0) {
SPDK_WARNLOG("Received msg failed: %s\n",
strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_WARNLOG("Received msg failed: %s\n", err_str);
return -1;
}
@ -423,16 +427,19 @@ 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_ERRLOG("socket() error, %s\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("socket() error, %s\n", err_str);
return -1;
}
flag = fcntl(fd, F_GETFD);
if (fcntl(fd, F_SETFD, flag | FD_CLOEXEC) < 0)
SPDK_ERRLOG("fcntl failed, %s\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("fcntl failed, %s\n", err_str);
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
@ -443,7 +450,8 @@ vhost_user_setup(struct virtio_user_dev *dev)
return -1;
}
if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
SPDK_ERRLOG("connect error, %s\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("connect error, %s\n", err_str);
close(fd);
return -1;
}

View File

@ -47,6 +47,8 @@
#include "virtio_user_dev.h"
#include "../virtio_dev.h"
#include "spdk/string.h"
static int
virtio_user_create_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
{
@ -179,6 +181,7 @@ virtio_user_dev_init(char *path, uint16_t requested_queues, uint32_t queue_size)
struct virtio_dev *vdev;
struct virtio_user_dev *dev;
uint64_t max_queues;
char err_str[64];
dev = calloc(1, sizeof(*dev));
if (dev == NULL) {
@ -202,7 +205,8 @@ virtio_user_dev_init(char *path, uint16_t requested_queues, uint32_t queue_size)
}
if (dev->ops->send_request(dev, VHOST_USER_GET_QUEUE_NUM, &max_queues) < 0) {
SPDK_ERRLOG("get_queue_num fails: %s\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("get_queue_num fails: %s\n", err_str);
goto err;
}
@ -215,7 +219,8 @@ virtio_user_dev_init(char *path, uint16_t requested_queues, uint32_t queue_size)
vdev->max_queues = requested_queues;
if (dev->ops->send_request(dev, VHOST_USER_SET_OWNER, NULL) < 0) {
SPDK_ERRLOG("set_owner fails: %s\n", strerror(errno));
spdk_strerror_r(errno, err_str, sizeof(err_str));
SPDK_ERRLOG("set_owner fails: %s\n", err_str);
goto err;
}