@@ -19,7 +19,6 @@
#include <rte_ether.h>
#include <rte_rwlock.h>
-#include "fd_man.h"
#include "rte_vhost.h"
/* Used to indicate that the device is running on a data core */
@@ -302,10 +301,6 @@ struct virtio_net {
int slave_req_fd;
} __rte_cache_aligned;
-/* The vhost_user and vhost_user_socket declarations are temporary measures for
- * moving AF_UNIX code into trans_af_unix.c. They will be cleaned up as
- * socket.c is untangled from trans_af_unix.c.
- */
/*
* Every time rte_vhost_driver_register() is invoked, an associated
* vhost_user_socket struct will be created.
@@ -336,16 +331,6 @@ struct vhost_user_socket {
struct vhost_transport_ops const *trans_ops;
};
-#define MAX_VHOST_SOCKET 1024
-struct vhost_user {
- struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET];
- struct fdset fdset;
- int vsocket_cnt;
- pthread_mutex_t mutex;
-};
-
-extern struct vhost_user vhost_user;
-
#define VHOST_LOG_PAGE 4096
/*
@@ -20,12 +20,14 @@
#include "vhost.h"
#include "vhost_user.h"
+#define MAX_VHOST_SOCKET 1024
+struct vhost_user {
+ struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET];
+ int vsocket_cnt;
+ pthread_mutex_t mutex;
+};
+
struct vhost_user vhost_user = {
- .fdset = {
- .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
- .fd_mutex = PTHREAD_MUTEX_INITIALIZER,
- .num = 0
- },
.vsocket_cnt = 0,
.mutex = PTHREAD_MUTEX_INITIALIZER,
};
@@ -265,7 +267,6 @@ int
rte_vhost_driver_start(const char *path)
{
struct vhost_user_socket *vsocket;
- static pthread_t fdset_tid;
pthread_mutex_lock(&vhost_user.mutex);
vsocket = find_vhost_user_socket(path);
@@ -274,13 +275,5 @@ rte_vhost_driver_start(const char *path)
if (!vsocket)
return -1;
- if (fdset_tid == 0) {
- int ret = pthread_create(&fdset_tid, NULL, fdset_event_dispatch,
- &vhost_user.fdset);
- if (ret != 0)
- RTE_LOG(ERR, VHOST_CONFIG,
- "failed to create fdset handling thread");
- }
-
return vsocket->trans_ops->socket_start(vsocket);
}
@@ -39,11 +39,18 @@
#include <rte_log.h>
+#include "fd_man.h"
#include "vhost.h"
#include "vhost_user.h"
#define MAX_VIRTIO_BACKLOG 128
+static struct fdset af_unix_fdset = {
+ .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
+ .fd_mutex = PTHREAD_MUTEX_INITIALIZER,
+ .num = 0
+};
+
TAILQ_HEAD(vhost_user_connection_list, vhost_user_connection);
struct vhost_user_connection {
@@ -195,7 +202,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
conn->connfd = fd;
conn->vsocket = vsocket;
conn->vid = vid;
- ret = fdset_add(&vhost_user.fdset, fd, vhost_user_read_cb,
+ ret = fdset_add(&af_unix_fdset, fd, vhost_user_read_cb,
NULL, conn);
if (ret < 0) {
RTE_LOG(ERR, VHOST_CONFIG,
@@ -316,7 +323,7 @@ vhost_user_start_server(struct vhost_user_socket *vsocket)
if (ret < 0)
goto err;
- ret = fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection,
+ ret = fdset_add(&af_unix_fdset, fd, vhost_user_server_new_connection,
NULL, vsocket);
if (ret < 0) {
RTE_LOG(ERR, VHOST_CONFIG,
@@ -551,7 +558,7 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket)
struct vhost_user_connection *conn, *next;
if (vsocket->is_server) {
- fdset_del(&vhost_user.fdset, s->socket_fd);
+ fdset_del(&af_unix_fdset, s->socket_fd);
close(s->socket_fd);
unlink(vsocket->path);
} else if (vsocket->reconnect) {
@@ -564,7 +571,7 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket)
conn = next) {
next = TAILQ_NEXT(conn, next);
- fdset_del(&vhost_user.fdset, conn->connfd);
+ fdset_del(&af_unix_fdset, conn->connfd);
RTE_LOG(INFO, VHOST_CONFIG,
"free connfd = %d for device '%s'\n",
conn->connfd, vsocket->path);
@@ -581,6 +588,16 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket)
static int
af_unix_socket_start(struct vhost_user_socket *vsocket)
{
+ static pthread_t fdset_tid;
+
+ if (fdset_tid == 0) {
+ int ret = pthread_create(&fdset_tid, NULL, fdset_event_dispatch,
+ &af_unix_fdset);
+ if (ret != 0)
+ RTE_LOG(ERR, VHOST_CONFIG,
+ "failed to create fdset handling thread");
+ }
+
if (vsocket->is_server)
return vhost_user_start_server(vsocket);
else