Instead of statically initialize the fdset, this patch
converts VDUSE and Vhost-user to use fdset_init() function,
which now also initialize the mutexes.
This is preliminary rework to hide FDs manager pipe from
its users.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/vhost/fd_man.c | 10 +++++++---
lib/vhost/fd_man.h | 2 +-
lib/vhost/socket.c | 12 +++++-------
lib/vhost/vduse.c | 15 ++++++---------
4 files changed, 19 insertions(+), 20 deletions(-)
@@ -96,19 +96,23 @@ fdset_add_fd(struct fdset *pfdset, int idx, int fd,
pfd->revents = 0;
}
-void
+int
fdset_init(struct fdset *pfdset)
{
int i;
- if (pfdset == NULL)
- return;
+ pthread_mutex_init(&pfdset->fd_mutex, NULL);
+ pthread_mutex_init(&pfdset->fd_polling_mutex, NULL);
+ pthread_mutex_init(&pfdset->sync_mutex, NULL);
+ pthread_cond_init(&pfdset->sync_cond, NULL);
for (i = 0; i < MAX_FDS; i++) {
pfdset->fd[i].fd = -1;
pfdset->fd[i].dat = NULL;
}
pfdset->num = 0;
+
+ return 0;
}
/**
@@ -43,7 +43,7 @@ struct fdset {
};
-void fdset_init(struct fdset *pfdset);
+int fdset_init(struct fdset *pfdset);
int fdset_add(struct fdset *pfdset, int fd,
fd_cb rcb, fd_cb wcb, void *dat);
@@ -90,13 +90,6 @@ static int create_unix_socket(struct vhost_user_socket *vsocket);
static int vhost_user_start_client(struct vhost_user_socket *vsocket);
static struct vhost_user vhost_user = {
- .fdset = {
- .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
- .fd_mutex = PTHREAD_MUTEX_INITIALIZER,
- .fd_pooling_mutex = PTHREAD_MUTEX_INITIALIZER,
- .sync_mutex = PTHREAD_MUTEX_INITIALIZER,
- .num = 0
- },
.vsocket_cnt = 0,
.mutex = PTHREAD_MUTEX_INITIALIZER,
};
@@ -1192,6 +1185,11 @@ rte_vhost_driver_start(const char *path)
return vduse_device_create(path, vsocket->net_compliant_ol_flags);
if (fdset_tid.opaque_id == 0) {
+ if (fdset_init(&vhost_user.fdset) < 0) {
+ VHOST_CONFIG_LOG(path, ERR, "failed to init Vhost-user fdset");
+ return -1;
+ }
+
/**
* create a pipe which will be waited by poll and notified to
* rebuild the wait list of poll.
@@ -31,15 +31,7 @@ struct vduse {
struct fdset fdset;
};
-static struct vduse vduse = {
- .fdset = {
- .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
- .fd_mutex = PTHREAD_MUTEX_INITIALIZER,
- .fd_pooling_mutex = PTHREAD_MUTEX_INITIALIZER,
- .sync_mutex = PTHREAD_MUTEX_INITIALIZER,
- .num = 0
- },
-};
+static struct vduse vduse;
static bool vduse_events_thread;
@@ -435,6 +427,11 @@ vduse_device_create(const char *path, bool compliant_ol_flags)
/* If first device, create events dispatcher thread */
if (vduse_events_thread == false) {
+ if (fdset_init(&vduse.fdset) < 0) {
+ VHOST_CONFIG_LOG(path, ERR, "failed to init VDUSE fdset");
+ return -1;
+ }
+
/**
* create a pipe which will be waited by poll and notified to
* rebuild the wait list of poll.