* with number of fds read.
*/
int
-read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,
+read_fd_message(char *ifname, int sockfd, char *buf, int buflen, int *fds, int max_fds,
int *fd_num)
{
struct iovec iov;
ret = recvmsg(sockfd, &msgh, 0);
if (ret <= 0) {
if (ret)
- VHOST_LOG_CONFIG(ERR, "recvmsg failed\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) recvmsg failed on fd %d (%s)\n",
+ ifname, sockfd, strerror(errno));
return ret;
}
if (msgh.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
- VHOST_LOG_CONFIG(ERR, "truncated msg\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) truncated msg (fd %d)\n", ifname, sockfd);
return -1;
}
}
int
-send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)
+send_fd_message(char *ifname, int sockfd, char *buf, int buflen, int *fds, int fd_num)
{
struct iovec iov;
msgh.msg_controllen = sizeof(control);
cmsg = CMSG_FIRSTHDR(&msgh);
if (cmsg == NULL) {
- VHOST_LOG_CONFIG(ERR, "cmsg == NULL\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) cmsg == NULL\n", ifname);
errno = EINVAL;
return -1;
}
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
- VHOST_LOG_CONFIG(ERR, "sendmsg error\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) sendmsg error on fd %d (%s)\n",
+ ifname, sockfd, strerror(errno));
return ret;
}
dev->async_copy = 1;
}
- VHOST_LOG_CONFIG(INFO, "new device, handle is %d, path is %s\n", vid, vsocket->path);
+ VHOST_LOG_CONFIG(INFO, "(%s) new device, handle is %d\n", vsocket->path, vid);
if (vsocket->notify_ops->new_connection) {
ret = vsocket->notify_ops->new_connection(vid);
if (ret < 0) {
VHOST_LOG_CONFIG(ERR,
- "failed to add vhost user connection with fd %d\n",
- fd);
+ "(%s) failed to add vhost user connection with fd %d\n",
+ vsocket->path, fd);
goto err_cleanup;
}
}
ret = fdset_add(&vhost_user.fdset, fd, vhost_user_read_cb,
NULL, conn);
if (ret < 0) {
- VHOST_LOG_CONFIG(ERR,
- "failed to add fd %d into vhost server fdset\n",
- fd);
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to add fd %d into vhost server fdset\n",
+ vsocket->path, fd);
if (vsocket->notify_ops->destroy_connection)
vsocket->notify_ops->destroy_connection(conn->vid);
if (fd < 0)
return;
- VHOST_LOG_CONFIG(INFO, "new vhost user connection is %d\n", fd);
+ VHOST_LOG_CONFIG(INFO, "(%s) new vhost user connection is %d\n",
+ vsocket->path, fd);
vhost_user_add_connection(fd, vsocket);
}
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
return -1;
- VHOST_LOG_CONFIG(INFO, "vhost-user %s: socket created, fd: %d\n",
- vsocket->is_server ? "server" : "client", fd);
+ VHOST_LOG_CONFIG(INFO, "(%s) vhost-user %s: socket created, fd: %d\n",
+ vsocket->path, vsocket->is_server ? "server" : "client", fd);
if (!vsocket->is_server && fcntl(fd, F_SETFL, O_NONBLOCK)) {
VHOST_LOG_CONFIG(ERR,
- "vhost-user: can't set nonblocking mode for socket, fd: "
- "%d (%s)\n", fd, strerror(errno));
+ "(%s) vhost-user: can't set nonblocking mode for socket, fd: %d (%s)\n",
+ vsocket->path, fd, strerror(errno));
close(fd);
return -1;
}
*/
ret = bind(fd, (struct sockaddr *)&vsocket->un, sizeof(vsocket->un));
if (ret < 0) {
- VHOST_LOG_CONFIG(ERR,
- "failed to bind to %s: %s; remove it and try again\n",
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to bind: %s; remove it and try again\n",
path, strerror(errno));
goto err;
}
- VHOST_LOG_CONFIG(INFO, "bind to %s\n", path);
+ VHOST_LOG_CONFIG(INFO, "(%s) binding succeeded\n", path);
ret = listen(fd, MAX_VIRTIO_BACKLOG);
if (ret < 0)
NULL, vsocket);
if (ret < 0) {
VHOST_LOG_CONFIG(ERR,
- "failed to add listen fd %d to vhost server fdset\n",
- fd);
+ "(%s) failed to add listen fd %d to vhost server fdset\n",
+ path, fd);
goto err;
}
static pthread_t reconn_tid;
static int
-vhost_user_connect_nonblock(int fd, struct sockaddr *un, size_t sz)
+vhost_user_connect_nonblock(char *path, int fd, struct sockaddr *un, size_t sz)
{
int ret, flags;
flags = fcntl(fd, F_GETFL, 0);
if (flags < 0) {
- VHOST_LOG_CONFIG(ERR,
- "can't get flags for connfd %d\n", fd);
+ VHOST_LOG_CONFIG(ERR, "(%s) can't get flags for connfd %d (%s)\n",
+ path, fd, strerror(errno));
return -2;
}
if ((flags & O_NONBLOCK) && fcntl(fd, F_SETFL, flags & ~O_NONBLOCK)) {
- VHOST_LOG_CONFIG(ERR,
- "can't disable nonblocking on fd %d\n", fd);
+ VHOST_LOG_CONFIG(ERR, "(%s) can't disable nonblocking on fd %d\n", path, fd);
return -2;
}
return 0;
reconn != NULL; reconn = next) {
next = TAILQ_NEXT(reconn, next);
- ret = vhost_user_connect_nonblock(reconn->fd,
+ ret = vhost_user_connect_nonblock(reconn->vsocket->path, reconn->fd,
(struct sockaddr *)&reconn->un,
sizeof(reconn->un));
if (ret == -2) {
close(reconn->fd);
- VHOST_LOG_CONFIG(ERR,
- "reconnection for fd %d failed\n",
- reconn->fd);
+ VHOST_LOG_CONFIG(ERR, "(%s) reconnection for fd %d failed\n",
+ reconn->vsocket->path, reconn->fd);
goto remove_fd;
}
if (ret == -1)
continue;
- VHOST_LOG_CONFIG(INFO,
- "%s: connected\n", reconn->vsocket->path);
+ VHOST_LOG_CONFIG(INFO, "(%s) connected\n", reconn->vsocket->path);
vhost_user_add_connection(reconn->fd, reconn->vsocket);
remove_fd:
TAILQ_REMOVE(&reconn_list.head, reconn, next);
ret = pthread_mutex_init(&reconn_list.mutex, NULL);
if (ret < 0) {
- VHOST_LOG_CONFIG(ERR, "failed to initialize mutex");
+ VHOST_LOG_CONFIG(ERR, "%s: failed to initialize mutex", __func__);
return ret;
}
TAILQ_INIT(&reconn_list.head);
vhost_user_client_reconnect, NULL);
if (ret != 0) {
VHOST_LOG_CONFIG(ERR, "failed to create reconnect thread");
- if (pthread_mutex_destroy(&reconn_list.mutex)) {
- VHOST_LOG_CONFIG(ERR,
- "failed to destroy reconnect mutex");
- }
+ if (pthread_mutex_destroy(&reconn_list.mutex))
+ VHOST_LOG_CONFIG(ERR, "%s: failed to destroy reconnect mutex", __func__);
}
return ret;
const char *path = vsocket->path;
struct vhost_user_reconnect *reconn;
- ret = vhost_user_connect_nonblock(fd, (struct sockaddr *)&vsocket->un,
+ ret = vhost_user_connect_nonblock(vsocket->path, fd, (struct sockaddr *)&vsocket->un,
sizeof(vsocket->un));
if (ret == 0) {
vhost_user_add_connection(fd, vsocket);
return 0;
}
- VHOST_LOG_CONFIG(WARNING,
- "failed to connect to %s: %s\n",
- path, strerror(errno));
+ VHOST_LOG_CONFIG(WARNING, "(%s) failed to connect: %s\n", path, strerror(errno));
if (ret == -2 || !vsocket->reconnect) {
close(fd);
return -1;
}
- VHOST_LOG_CONFIG(INFO, "%s: reconnecting...\n", path);
+ VHOST_LOG_CONFIG(INFO, "(%s) reconnecting...\n", path);
reconn = malloc(sizeof(*reconn));
if (reconn == NULL) {
- VHOST_LOG_CONFIG(ERR,
- "failed to allocate memory for reconnect\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to allocate memory for reconnect\n", path);
close(fd);
return -1;
}
pthread_mutex_lock(&vhost_user.mutex);
vsocket = find_vhost_user_socket(path);
if (!vsocket) {
- VHOST_LOG_CONFIG(ERR,
- "socket file %s is not registered yet.\n", path);
+ VHOST_LOG_CONFIG(ERR, "(%s) socket file is not registered yet.\n", path);
ret = -1;
goto unlock_exit;
}
}
if (vdpa_dev->ops->get_features(vdpa_dev, &vdpa_features) < 0) {
- VHOST_LOG_CONFIG(ERR,
- "failed to get vdpa features "
- "for socket file %s.\n", path);
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to get vdpa features for socket file.\n", path);
ret = -1;
goto unlock_exit;
}
pthread_mutex_lock(&vhost_user.mutex);
vsocket = find_vhost_user_socket(path);
if (!vsocket) {
- VHOST_LOG_CONFIG(ERR,
- "socket file %s is not registered yet.\n", path);
+ VHOST_LOG_CONFIG(ERR, "(%s) socket file is not registered yet.\n", path);
ret = -1;
goto unlock_exit;
}
if (vdpa_dev->ops->get_protocol_features(vdpa_dev,
&vdpa_protocol_features) < 0) {
- VHOST_LOG_CONFIG(ERR,
- "failed to get vdpa protocol features "
- "for socket file %s.\n", path);
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to get vdpa protocol features.\n",
+ path);
ret = -1;
goto unlock_exit;
}
pthread_mutex_lock(&vhost_user.mutex);
vsocket = find_vhost_user_socket(path);
if (!vsocket) {
- VHOST_LOG_CONFIG(ERR,
- "socket file %s is not registered yet.\n", path);
+ VHOST_LOG_CONFIG(ERR, "(%s) socket file is not registered yet.\n", path);
ret = -1;
goto unlock_exit;
}
}
if (vdpa_dev->ops->get_queue_num(vdpa_dev, &vdpa_queue_num) < 0) {
- VHOST_LOG_CONFIG(ERR,
- "failed to get vdpa queue number "
- "for socket file %s.\n", path);
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to get vdpa queue number.\n",
+ path);
ret = -1;
goto unlock_exit;
}
pthread_mutex_lock(&vhost_user.mutex);
if (vhost_user.vsocket_cnt == MAX_VHOST_SOCKET) {
- VHOST_LOG_CONFIG(ERR,
- "error: the number of vhost sockets reaches maximum\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) the number of vhost sockets reaches maximum\n",
+ path);
goto out;
}
memset(vsocket, 0, sizeof(struct vhost_user_socket));
vsocket->path = strdup(path);
if (vsocket->path == NULL) {
- VHOST_LOG_CONFIG(ERR,
- "error: failed to copy socket path string\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to copy socket path string\n", path);
vhost_user_socket_mem_free(vsocket);
goto out;
}
TAILQ_INIT(&vsocket->conn_list);
ret = pthread_mutex_init(&vsocket->conn_mutex, NULL);
if (ret) {
- VHOST_LOG_CONFIG(ERR,
- "error: failed to init connection mutex\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to init connection mutex\n", path);
goto out_free;
}
vsocket->vdpa_dev = NULL;
if (vsocket->async_copy &&
(flags & (RTE_VHOST_USER_IOMMU_SUPPORT |
RTE_VHOST_USER_POSTCOPY_SUPPORT))) {
- VHOST_LOG_CONFIG(ERR, "error: enabling async copy and IOMMU "
- "or post-copy feature simultaneously is not "
- "supported\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) enabling async copy and IOMMU "
+ "or post-copy feature simultaneously is not supported\n", path);
goto out_mutex;
}
if (vsocket->async_copy) {
vsocket->supported_features &= ~(1ULL << VHOST_F_LOG_ALL);
vsocket->features &= ~(1ULL << VHOST_F_LOG_ALL);
- VHOST_LOG_CONFIG(INFO,
- "Logging feature is disabled in async copy mode\n");
+ VHOST_LOG_CONFIG(INFO, "(%s) logging feature is disabled in async copy mode\n",
+ path);
}
/*
(1ULL << VIRTIO_NET_F_HOST_TSO6) |
(1ULL << VIRTIO_NET_F_HOST_UFO);
- VHOST_LOG_CONFIG(INFO,
- "Linear buffers requested without external buffers, "
- "disabling host segmentation offloading support\n");
+ VHOST_LOG_CONFIG(INFO, "(%s) Linear buffers requested without external buffers, "
+ "disabling host segmentation offloading support\n", path);
vsocket->supported_features &= ~seg_offload_features;
vsocket->features &= ~seg_offload_features;
}
~(1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT);
} else {
#ifndef RTE_LIBRTE_VHOST_POSTCOPY
- VHOST_LOG_CONFIG(ERR,
- "Postcopy requested but not compiled\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) Postcopy requested but not compiled\n", path);
ret = -1;
goto out_mutex;
#endif
out_mutex:
if (pthread_mutex_destroy(&vsocket->conn_mutex)) {
- VHOST_LOG_CONFIG(ERR,
- "error: failed to destroy connection mutex\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to destroy connection mutex\n", path);
}
out_free:
vhost_user_socket_mem_free(vsocket);
goto again;
}
- VHOST_LOG_CONFIG(INFO,
- "free connfd = %d for device '%s'\n",
- conn->connfd, path);
+ VHOST_LOG_CONFIG(INFO, "(%s) free connfd %d\n", path, conn->connfd);
close(conn->connfd);
vhost_destroy_device(conn->vid);
TAILQ_REMOVE(&vsocket->conn_list, conn, next);
* rebuild the wait list of poll.
*/
if (fdset_pipe_init(&vhost_user.fdset) < 0) {
- VHOST_LOG_CONFIG(ERR,
- "failed to create pipe for vhost fdset\n");
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to create pipe for vhost fdset\n", path);
return -1;
}
"vhost-events", NULL, fdset_event_dispatch,
&vhost_user.fdset);
if (ret != 0) {
- VHOST_LOG_CONFIG(ERR,
- "failed to create fdset handling thread");
+ VHOST_LOG_CONFIG(ERR, "(%s) failed to create fdset handling thread", path);
fdset_pipe_uninit(&vhost_user.fdset);
return -1;
[VHOST_USER_GET_STATUS] = "VHOST_USER_GET_STATUS",
};
-static int send_vhost_reply(int sockfd, struct VhostUserMsg *msg);
+static int send_vhost_reply(struct virtio_net *dev, int sockfd, struct VhostUserMsg *msg);
static int read_vhost_message(struct virtio_net *dev, int sockfd, struct VhostUserMsg *msg);
static void
/* Send the addresses back to qemu */
msg->fd_num = 0;
- send_vhost_reply(main_fd, msg);
+ send_vhost_reply(dev, main_fd, msg);
/* Wait for qemu to acknowledge it got the addresses
* we've got to wait before we're allowed to generate faults.
{
int ret;
- ret = read_fd_message(sockfd, (char *)msg, VHOST_USER_HDR_SIZE,
+ ret = read_fd_message(dev->ifname, sockfd, (char *)msg, VHOST_USER_HDR_SIZE,
msg->fds, VHOST_MEMORY_MAX_NREGIONS, &msg->fd_num);
if (ret <= 0) {
return ret;
}
static int
-send_vhost_message(int sockfd, struct VhostUserMsg *msg)
+send_vhost_message(struct virtio_net *dev, int sockfd, struct VhostUserMsg *msg)
{
if (!msg)
return 0;
- return send_fd_message(sockfd, (char *)msg,
+ return send_fd_message(dev->ifname, sockfd, (char *)msg,
VHOST_USER_HDR_SIZE + msg->size, msg->fds, msg->fd_num);
}
static int
-send_vhost_reply(int sockfd, struct VhostUserMsg *msg)
+send_vhost_reply(struct virtio_net *dev, int sockfd, struct VhostUserMsg *msg)
{
if (!msg)
return 0;
msg->flags |= VHOST_USER_VERSION;
msg->flags |= VHOST_USER_REPLY_MASK;
- return send_vhost_message(sockfd, msg);
+ return send_vhost_message(dev, sockfd, msg);
}
static int
if (msg->flags & VHOST_USER_NEED_REPLY)
rte_spinlock_lock(&dev->slave_req_lock);
- ret = send_vhost_message(dev->slave_req_fd, msg);
+ ret = send_vhost_message(dev, dev->slave_req_fd, msg);
if (ret < 0 && (msg->flags & VHOST_USER_NEED_REPLY))
rte_spinlock_unlock(&dev->slave_req_lock);
(void *)&msg);
switch (ret) {
case RTE_VHOST_MSG_RESULT_REPLY:
- send_vhost_reply(fd, &msg);
+ send_vhost_reply(dev, fd, &msg);
/* Fall-through */
case RTE_VHOST_MSG_RESULT_ERR:
case RTE_VHOST_MSG_RESULT_OK:
case RTE_VHOST_MSG_RESULT_REPLY:
VHOST_LOG_CONFIG(DEBUG, "(%s) processing %s succeeded and needs reply.\n",
dev->ifname, vhost_message_str[request]);
- send_vhost_reply(fd, &msg);
+ send_vhost_reply(dev, fd, &msg);
handled = true;
break;
default:
(void *)&msg);
switch (ret) {
case RTE_VHOST_MSG_RESULT_REPLY:
- send_vhost_reply(fd, &msg);
+ send_vhost_reply(dev, fd, &msg);
/* Fall-through */
case RTE_VHOST_MSG_RESULT_ERR:
case RTE_VHOST_MSG_RESULT_OK:
msg.payload.u64 = ret == RTE_VHOST_MSG_RESULT_ERR;
msg.size = sizeof(msg.payload.u64);
msg.fd_num = 0;
- send_vhost_reply(fd, &msg);
+ send_vhost_reply(dev, fd, &msg);
} else if (ret == RTE_VHOST_MSG_RESULT_ERR) {
VHOST_LOG_CONFIG(ERR, "(%s) vhost message handling failed.\n", dev->ifname);
return -1;
},
};
- ret = send_vhost_message(dev->slave_req_fd, &msg);
+ ret = send_vhost_message(dev, dev->slave_req_fd, &msg);
if (ret < 0) {
VHOST_LOG_CONFIG(ERR, "(%s) failed to send IOTLB miss message (%d)\n",
dev->ifname, ret);