vhost: add reconnect ability
[dpdk.git] / lib / librte_vhost / vhost_user / vhost-net-user.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdint.h>
35 #include <stdio.h>
36 #include <stdbool.h>
37 #include <limits.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <string.h>
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <sys/un.h>
44 #include <sys/queue.h>
45 #include <errno.h>
46 #include <pthread.h>
47
48 #include <rte_log.h>
49 #include <rte_virtio_net.h>
50
51 #include "fd_man.h"
52 #include "vhost-net-user.h"
53 #include "vhost-net.h"
54 #include "virtio-net-user.h"
55
56 /*
57  * Every time rte_vhost_driver_register() is invoked, an associated
58  * vhost_user_socket struct will be created.
59  */
60 struct vhost_user_socket {
61         char *path;
62         int listenfd;
63         bool is_server;
64         bool reconnect;
65 };
66
67 struct vhost_user_connection {
68         struct vhost_user_socket *vsocket;
69         int vid;
70 };
71
72 #define MAX_VHOST_SOCKET 1024
73 struct vhost_user {
74         struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET];
75         struct fdset fdset;
76         int vsocket_cnt;
77         pthread_mutex_t mutex;
78 };
79
80 #define MAX_VIRTIO_BACKLOG 128
81
82 static void vhost_user_server_new_connection(int fd, void *data, int *remove);
83 static void vhost_user_msg_handler(int fd, void *dat, int *remove);
84 static int vhost_user_create_client(struct vhost_user_socket *vsocket);
85
86 static struct vhost_user vhost_user = {
87         .fdset = {
88                 .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
89                 .fd_mutex = PTHREAD_MUTEX_INITIALIZER,
90                 .num = 0
91         },
92         .vsocket_cnt = 0,
93         .mutex = PTHREAD_MUTEX_INITIALIZER,
94 };
95
96 static const char *vhost_message_str[VHOST_USER_MAX] = {
97         [VHOST_USER_NONE] = "VHOST_USER_NONE",
98         [VHOST_USER_GET_FEATURES] = "VHOST_USER_GET_FEATURES",
99         [VHOST_USER_SET_FEATURES] = "VHOST_USER_SET_FEATURES",
100         [VHOST_USER_SET_OWNER] = "VHOST_USER_SET_OWNER",
101         [VHOST_USER_RESET_OWNER] = "VHOST_USER_RESET_OWNER",
102         [VHOST_USER_SET_MEM_TABLE] = "VHOST_USER_SET_MEM_TABLE",
103         [VHOST_USER_SET_LOG_BASE] = "VHOST_USER_SET_LOG_BASE",
104         [VHOST_USER_SET_LOG_FD] = "VHOST_USER_SET_LOG_FD",
105         [VHOST_USER_SET_VRING_NUM] = "VHOST_USER_SET_VRING_NUM",
106         [VHOST_USER_SET_VRING_ADDR] = "VHOST_USER_SET_VRING_ADDR",
107         [VHOST_USER_SET_VRING_BASE] = "VHOST_USER_SET_VRING_BASE",
108         [VHOST_USER_GET_VRING_BASE] = "VHOST_USER_GET_VRING_BASE",
109         [VHOST_USER_SET_VRING_KICK] = "VHOST_USER_SET_VRING_KICK",
110         [VHOST_USER_SET_VRING_CALL] = "VHOST_USER_SET_VRING_CALL",
111         [VHOST_USER_SET_VRING_ERR]  = "VHOST_USER_SET_VRING_ERR",
112         [VHOST_USER_GET_PROTOCOL_FEATURES]  = "VHOST_USER_GET_PROTOCOL_FEATURES",
113         [VHOST_USER_SET_PROTOCOL_FEATURES]  = "VHOST_USER_SET_PROTOCOL_FEATURES",
114         [VHOST_USER_GET_QUEUE_NUM]  = "VHOST_USER_GET_QUEUE_NUM",
115         [VHOST_USER_SET_VRING_ENABLE]  = "VHOST_USER_SET_VRING_ENABLE",
116         [VHOST_USER_SEND_RARP]  = "VHOST_USER_SEND_RARP",
117 };
118
119 /* return bytes# of read on success or negative val on failure. */
120 static int
121 read_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)
122 {
123         struct iovec iov;
124         struct msghdr msgh;
125         size_t fdsize = fd_num * sizeof(int);
126         char control[CMSG_SPACE(fdsize)];
127         struct cmsghdr *cmsg;
128         int ret;
129
130         memset(&msgh, 0, sizeof(msgh));
131         iov.iov_base = buf;
132         iov.iov_len  = buflen;
133
134         msgh.msg_iov = &iov;
135         msgh.msg_iovlen = 1;
136         msgh.msg_control = control;
137         msgh.msg_controllen = sizeof(control);
138
139         ret = recvmsg(sockfd, &msgh, 0);
140         if (ret <= 0) {
141                 RTE_LOG(ERR, VHOST_CONFIG, "recvmsg failed\n");
142                 return ret;
143         }
144
145         if (msgh.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
146                 RTE_LOG(ERR, VHOST_CONFIG, "truncted msg\n");
147                 return -1;
148         }
149
150         for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
151                 cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
152                 if ((cmsg->cmsg_level == SOL_SOCKET) &&
153                         (cmsg->cmsg_type == SCM_RIGHTS)) {
154                         memcpy(fds, CMSG_DATA(cmsg), fdsize);
155                         break;
156                 }
157         }
158
159         return ret;
160 }
161
162 /* return bytes# of read on success or negative val on failure. */
163 static int
164 read_vhost_message(int sockfd, struct VhostUserMsg *msg)
165 {
166         int ret;
167
168         ret = read_fd_message(sockfd, (char *)msg, VHOST_USER_HDR_SIZE,
169                 msg->fds, VHOST_MEMORY_MAX_NREGIONS);
170         if (ret <= 0)
171                 return ret;
172
173         if (msg && msg->size) {
174                 if (msg->size > sizeof(msg->payload)) {
175                         RTE_LOG(ERR, VHOST_CONFIG,
176                                 "invalid msg size: %d\n", msg->size);
177                         return -1;
178                 }
179                 ret = read(sockfd, &msg->payload, msg->size);
180                 if (ret <= 0)
181                         return ret;
182                 if (ret != (int)msg->size) {
183                         RTE_LOG(ERR, VHOST_CONFIG,
184                                 "read control message failed\n");
185                         return -1;
186                 }
187         }
188
189         return ret;
190 }
191
192 static int
193 send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)
194 {
195
196         struct iovec iov;
197         struct msghdr msgh;
198         size_t fdsize = fd_num * sizeof(int);
199         char control[CMSG_SPACE(fdsize)];
200         struct cmsghdr *cmsg;
201         int ret;
202
203         memset(&msgh, 0, sizeof(msgh));
204         iov.iov_base = buf;
205         iov.iov_len = buflen;
206
207         msgh.msg_iov = &iov;
208         msgh.msg_iovlen = 1;
209
210         if (fds && fd_num > 0) {
211                 msgh.msg_control = control;
212                 msgh.msg_controllen = sizeof(control);
213                 cmsg = CMSG_FIRSTHDR(&msgh);
214                 cmsg->cmsg_len = CMSG_LEN(fdsize);
215                 cmsg->cmsg_level = SOL_SOCKET;
216                 cmsg->cmsg_type = SCM_RIGHTS;
217                 memcpy(CMSG_DATA(cmsg), fds, fdsize);
218         } else {
219                 msgh.msg_control = NULL;
220                 msgh.msg_controllen = 0;
221         }
222
223         do {
224                 ret = sendmsg(sockfd, &msgh, 0);
225         } while (ret < 0 && errno == EINTR);
226
227         if (ret < 0) {
228                 RTE_LOG(ERR, VHOST_CONFIG,  "sendmsg error\n");
229                 return ret;
230         }
231
232         return ret;
233 }
234
235 static int
236 send_vhost_message(int sockfd, struct VhostUserMsg *msg)
237 {
238         int ret;
239
240         if (!msg)
241                 return 0;
242
243         msg->flags &= ~VHOST_USER_VERSION_MASK;
244         msg->flags |= VHOST_USER_VERSION;
245         msg->flags |= VHOST_USER_REPLY_MASK;
246
247         ret = send_fd_message(sockfd, (char *)msg,
248                 VHOST_USER_HDR_SIZE + msg->size, NULL, 0);
249
250         return ret;
251 }
252
253
254 static void
255 vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
256 {
257         int vid;
258         size_t size;
259         struct vhost_user_connection *conn;
260
261         conn = malloc(sizeof(*conn));
262         if (conn == NULL) {
263                 close(fd);
264                 return;
265         }
266
267         vid = vhost_new_device();
268         if (vid == -1) {
269                 close(fd);
270                 free(conn);
271                 return;
272         }
273
274         size = strnlen(vsocket->path, PATH_MAX);
275         vhost_set_ifname(vid, vsocket->path, size);
276
277         RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
278
279         conn->vsocket = vsocket;
280         conn->vid = vid;
281         fdset_add(&vhost_user.fdset, fd, vhost_user_msg_handler, NULL, conn);
282 }
283
284 /* call back when there is new vhost-user connection from client  */
285 static void
286 vhost_user_server_new_connection(int fd, void *dat, int *remove __rte_unused)
287 {
288         struct vhost_user_socket *vsocket = dat;
289
290         fd = accept(fd, NULL, NULL);
291         if (fd < 0)
292                 return;
293
294         RTE_LOG(INFO, VHOST_CONFIG, "new vhost user connection is %d\n", fd);
295         vhost_user_add_connection(fd, vsocket);
296 }
297
298 /* callback when there is message on the connfd */
299 static void
300 vhost_user_msg_handler(int connfd, void *dat, int *remove)
301 {
302         int vid;
303         struct vhost_user_connection *conn = dat;
304         struct VhostUserMsg msg;
305         uint64_t features;
306         int ret;
307
308         vid = conn->vid;
309         ret = read_vhost_message(connfd, &msg);
310         if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
311                 struct vhost_user_socket *vsocket = conn->vsocket;
312
313                 if (ret < 0)
314                         RTE_LOG(ERR, VHOST_CONFIG,
315                                 "vhost read message failed\n");
316                 else if (ret == 0)
317                         RTE_LOG(INFO, VHOST_CONFIG,
318                                 "vhost peer closed\n");
319                 else
320                         RTE_LOG(ERR, VHOST_CONFIG,
321                                 "vhost read incorrect message\n");
322
323                 close(connfd);
324                 *remove = 1;
325                 free(conn);
326                 vhost_destroy_device(vid);
327
328                 if (vsocket->reconnect)
329                         vhost_user_create_client(vsocket);
330
331                 return;
332         }
333
334         RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n",
335                 vhost_message_str[msg.request]);
336         switch (msg.request) {
337         case VHOST_USER_GET_FEATURES:
338                 ret = vhost_get_features(vid, &features);
339                 msg.payload.u64 = features;
340                 msg.size = sizeof(msg.payload.u64);
341                 send_vhost_message(connfd, &msg);
342                 break;
343         case VHOST_USER_SET_FEATURES:
344                 features = msg.payload.u64;
345                 vhost_set_features(vid, &features);
346                 break;
347
348         case VHOST_USER_GET_PROTOCOL_FEATURES:
349                 msg.payload.u64 = VHOST_USER_PROTOCOL_FEATURES;
350                 msg.size = sizeof(msg.payload.u64);
351                 send_vhost_message(connfd, &msg);
352                 break;
353         case VHOST_USER_SET_PROTOCOL_FEATURES:
354                 user_set_protocol_features(vid, msg.payload.u64);
355                 break;
356
357         case VHOST_USER_SET_OWNER:
358                 vhost_set_owner(vid);
359                 break;
360         case VHOST_USER_RESET_OWNER:
361                 vhost_reset_owner(vid);
362                 break;
363
364         case VHOST_USER_SET_MEM_TABLE:
365                 user_set_mem_table(vid, &msg);
366                 break;
367
368         case VHOST_USER_SET_LOG_BASE:
369                 user_set_log_base(vid, &msg);
370
371                 /* it needs a reply */
372                 msg.size = sizeof(msg.payload.u64);
373                 send_vhost_message(connfd, &msg);
374                 break;
375         case VHOST_USER_SET_LOG_FD:
376                 close(msg.fds[0]);
377                 RTE_LOG(INFO, VHOST_CONFIG, "not implemented.\n");
378                 break;
379
380         case VHOST_USER_SET_VRING_NUM:
381                 vhost_set_vring_num(vid, &msg.payload.state);
382                 break;
383         case VHOST_USER_SET_VRING_ADDR:
384                 vhost_set_vring_addr(vid, &msg.payload.addr);
385                 break;
386         case VHOST_USER_SET_VRING_BASE:
387                 vhost_set_vring_base(vid, &msg.payload.state);
388                 break;
389
390         case VHOST_USER_GET_VRING_BASE:
391                 ret = user_get_vring_base(vid, &msg.payload.state);
392                 msg.size = sizeof(msg.payload.state);
393                 send_vhost_message(connfd, &msg);
394                 break;
395
396         case VHOST_USER_SET_VRING_KICK:
397                 user_set_vring_kick(vid, &msg);
398                 break;
399         case VHOST_USER_SET_VRING_CALL:
400                 user_set_vring_call(vid, &msg);
401                 break;
402
403         case VHOST_USER_SET_VRING_ERR:
404                 if (!(msg.payload.u64 & VHOST_USER_VRING_NOFD_MASK))
405                         close(msg.fds[0]);
406                 RTE_LOG(INFO, VHOST_CONFIG, "not implemented\n");
407                 break;
408
409         case VHOST_USER_GET_QUEUE_NUM:
410                 msg.payload.u64 = VHOST_MAX_QUEUE_PAIRS;
411                 msg.size = sizeof(msg.payload.u64);
412                 send_vhost_message(connfd, &msg);
413                 break;
414
415         case VHOST_USER_SET_VRING_ENABLE:
416                 user_set_vring_enable(vid, &msg.payload.state);
417                 break;
418         case VHOST_USER_SEND_RARP:
419                 user_send_rarp(vid, &msg);
420                 break;
421
422         default:
423                 break;
424
425         }
426 }
427
428 static int
429 create_unix_socket(const char *path, struct sockaddr_un *un, bool is_server)
430 {
431         int fd;
432
433         fd = socket(AF_UNIX, SOCK_STREAM, 0);
434         if (fd < 0)
435                 return -1;
436         RTE_LOG(INFO, VHOST_CONFIG, "vhost-user %s: socket created, fd: %d\n",
437                 is_server ? "server" : "client", fd);
438
439         memset(un, 0, sizeof(*un));
440         un->sun_family = AF_UNIX;
441         strncpy(un->sun_path, path, sizeof(un->sun_path));
442
443         return fd;
444 }
445
446 static int
447 vhost_user_create_server(struct vhost_user_socket *vsocket)
448 {
449         int fd;
450         int ret;
451         struct sockaddr_un un;
452         const char *path = vsocket->path;
453
454         fd = create_unix_socket(path, &un, vsocket->is_server);
455         if (fd < 0)
456                 return -1;
457
458         ret = bind(fd, (struct sockaddr *)&un, sizeof(un));
459         if (ret < 0) {
460                 RTE_LOG(ERR, VHOST_CONFIG,
461                         "failed to bind to %s: %s; remove it and try again\n",
462                         path, strerror(errno));
463                 goto err;
464         }
465         RTE_LOG(INFO, VHOST_CONFIG, "bind to %s\n", path);
466
467         ret = listen(fd, MAX_VIRTIO_BACKLOG);
468         if (ret < 0)
469                 goto err;
470
471         vsocket->listenfd = fd;
472         fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection,
473                   NULL, vsocket);
474
475         return 0;
476
477 err:
478         close(fd);
479         return -1;
480 }
481
482 struct vhost_user_reconnect {
483         struct sockaddr_un un;
484         int fd;
485         struct vhost_user_socket *vsocket;
486
487         TAILQ_ENTRY(vhost_user_reconnect) next;
488 };
489
490 TAILQ_HEAD(vhost_user_reconnect_tailq_list, vhost_user_reconnect);
491 struct vhost_user_reconnect_list {
492         struct vhost_user_reconnect_tailq_list head;
493         pthread_mutex_t mutex;
494 };
495
496 static struct vhost_user_reconnect_list reconn_list;
497 static pthread_t reconn_tid;
498
499 static void *
500 vhost_user_client_reconnect(void *arg __rte_unused)
501 {
502         struct vhost_user_reconnect *reconn, *next;
503
504         while (1) {
505                 pthread_mutex_lock(&reconn_list.mutex);
506
507                 /*
508                  * An equal implementation of TAILQ_FOREACH_SAFE,
509                  * which does not exist on all platforms.
510                  */
511                 for (reconn = TAILQ_FIRST(&reconn_list.head);
512                      reconn != NULL; reconn = next) {
513                         next = TAILQ_NEXT(reconn, next);
514
515                         if (connect(reconn->fd, (struct sockaddr *)&reconn->un,
516                                     sizeof(reconn->un)) < 0)
517                                 continue;
518
519                         RTE_LOG(INFO, VHOST_CONFIG,
520                                 "%s: connected\n", reconn->vsocket->path);
521                         vhost_user_add_connection(reconn->fd, reconn->vsocket);
522                         TAILQ_REMOVE(&reconn_list.head, reconn, next);
523                         free(reconn);
524                 }
525
526                 pthread_mutex_unlock(&reconn_list.mutex);
527                 sleep(1);
528         }
529
530         return NULL;
531 }
532
533 static int
534 vhost_user_reconnect_init(void)
535 {
536         int ret;
537
538         pthread_mutex_init(&reconn_list.mutex, NULL);
539         TAILQ_INIT(&reconn_list.head);
540
541         ret = pthread_create(&reconn_tid, NULL,
542                              vhost_user_client_reconnect, NULL);
543         if (ret < 0)
544                 RTE_LOG(ERR, VHOST_CONFIG, "failed to create reconnect thread");
545
546         return ret;
547 }
548
549 static int
550 vhost_user_create_client(struct vhost_user_socket *vsocket)
551 {
552         int fd;
553         int ret;
554         struct sockaddr_un un;
555         const char *path = vsocket->path;
556         struct vhost_user_reconnect *reconn;
557
558         fd = create_unix_socket(path, &un, vsocket->is_server);
559         if (fd < 0)
560                 return -1;
561
562         ret = connect(fd, (struct sockaddr *)&un, sizeof(un));
563         if (ret == 0) {
564                 vhost_user_add_connection(fd, vsocket);
565                 return 0;
566         }
567
568         RTE_LOG(ERR, VHOST_CONFIG,
569                 "failed to connect to %s: %s\n",
570                 path, strerror(errno));
571
572         if (!vsocket->reconnect) {
573                 close(fd);
574                 return -1;
575         }
576
577         RTE_LOG(ERR, VHOST_CONFIG, "%s: reconnecting...\n", path);
578         reconn = malloc(sizeof(*reconn));
579         reconn->un = un;
580         reconn->fd = fd;
581         reconn->vsocket = vsocket;
582         pthread_mutex_lock(&reconn_list.mutex);
583         TAILQ_INSERT_TAIL(&reconn_list.head, reconn, next);
584         pthread_mutex_unlock(&reconn_list.mutex);
585
586         return 0;
587 }
588
589 /*
590  * Register a new vhost-user socket; here we could act as server
591  * (the default case), or client (when RTE_VHOST_USER_CLIENT) flag
592  * is set.
593  */
594 int
595 rte_vhost_driver_register(const char *path, uint64_t flags)
596 {
597         int ret = -1;
598         struct vhost_user_socket *vsocket;
599
600         if (!path)
601                 return -1;
602
603         pthread_mutex_lock(&vhost_user.mutex);
604
605         if (vhost_user.vsocket_cnt == MAX_VHOST_SOCKET) {
606                 RTE_LOG(ERR, VHOST_CONFIG,
607                         "error: the number of vhost sockets reaches maximum\n");
608                 goto out;
609         }
610
611         vsocket = malloc(sizeof(struct vhost_user_socket));
612         if (!vsocket)
613                 goto out;
614         memset(vsocket, 0, sizeof(struct vhost_user_socket));
615         vsocket->path = strdup(path);
616
617         if ((flags & RTE_VHOST_USER_CLIENT) != 0) {
618                 vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
619                 if (vsocket->reconnect && reconn_tid == 0) {
620                         if (vhost_user_reconnect_init() < 0)
621                                 goto out;
622                 }
623                 ret = vhost_user_create_client(vsocket);
624         } else {
625                 vsocket->is_server = true;
626                 ret = vhost_user_create_server(vsocket);
627         }
628         if (ret < 0) {
629                 free(vsocket->path);
630                 free(vsocket);
631                 goto out;
632         }
633
634         vhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket;
635
636 out:
637         pthread_mutex_unlock(&vhost_user.mutex);
638
639         return ret;
640 }
641
642 /**
643  * Unregister the specified vhost socket
644  */
645 int
646 rte_vhost_driver_unregister(const char *path)
647 {
648         int i;
649         int count;
650
651         pthread_mutex_lock(&vhost_user.mutex);
652
653         for (i = 0; i < vhost_user.vsocket_cnt; i++) {
654                 if (!strcmp(vhost_user.vsockets[i]->path, path)) {
655                         if (vhost_user.vsockets[i]->is_server) {
656                                 fdset_del(&vhost_user.fdset,
657                                         vhost_user.vsockets[i]->listenfd);
658                                 close(vhost_user.vsockets[i]->listenfd);
659                                 unlink(path);
660                         }
661
662                         free(vhost_user.vsockets[i]->path);
663                         free(vhost_user.vsockets[i]);
664
665                         count = --vhost_user.vsocket_cnt;
666                         vhost_user.vsockets[i] = vhost_user.vsockets[count];
667                         vhost_user.vsockets[count] = NULL;
668                         pthread_mutex_unlock(&vhost_user.mutex);
669
670                         return 0;
671                 }
672         }
673         pthread_mutex_unlock(&vhost_user.mutex);
674
675         return -1;
676 }
677
678 int
679 rte_vhost_driver_session_start(void)
680 {
681         fdset_event_dispatch(&vhost_user.fdset);
682         return 0;
683 }