vhost: introduce driver features related APIs
[dpdk.git] / lib / librte_vhost / socket.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 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 <fcntl.h>
47 #include <pthread.h>
48
49 #include <rte_log.h>
50
51 #include "fd_man.h"
52 #include "vhost.h"
53 #include "vhost_user.h"
54
55
56 TAILQ_HEAD(vhost_user_connection_list, vhost_user_connection);
57
58 /*
59  * Every time rte_vhost_driver_register() is invoked, an associated
60  * vhost_user_socket struct will be created.
61  */
62 struct vhost_user_socket {
63         struct vhost_user_connection_list conn_list;
64         pthread_mutex_t conn_mutex;
65         char *path;
66         int listenfd;
67         bool is_server;
68         bool reconnect;
69         bool dequeue_zero_copy;
70
71         /*
72          * The "supported_features" indicates the feature bits the
73          * vhost driver supports. The "features" indicates the feature
74          * bits after the rte_vhost_driver_features_disable/enable().
75          * It is also the final feature bits used for vhost-user
76          * features negotiation.
77          */
78         uint64_t supported_features;
79         uint64_t features;
80 };
81
82 struct vhost_user_connection {
83         struct vhost_user_socket *vsocket;
84         int connfd;
85         int vid;
86
87         TAILQ_ENTRY(vhost_user_connection) next;
88 };
89
90 #define MAX_VHOST_SOCKET 1024
91 struct vhost_user {
92         struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET];
93         struct fdset fdset;
94         int vsocket_cnt;
95         pthread_mutex_t mutex;
96 };
97
98 #define MAX_VIRTIO_BACKLOG 128
99
100 static void vhost_user_server_new_connection(int fd, void *data, int *remove);
101 static void vhost_user_read_cb(int fd, void *dat, int *remove);
102 static int vhost_user_create_client(struct vhost_user_socket *vsocket);
103
104 static struct vhost_user vhost_user = {
105         .fdset = {
106                 .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
107                 .fd_mutex = PTHREAD_MUTEX_INITIALIZER,
108                 .num = 0
109         },
110         .vsocket_cnt = 0,
111         .mutex = PTHREAD_MUTEX_INITIALIZER,
112 };
113
114 /* return bytes# of read on success or negative val on failure. */
115 int
116 read_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)
117 {
118         struct iovec iov;
119         struct msghdr msgh;
120         size_t fdsize = fd_num * sizeof(int);
121         char control[CMSG_SPACE(fdsize)];
122         struct cmsghdr *cmsg;
123         int ret;
124
125         memset(&msgh, 0, sizeof(msgh));
126         iov.iov_base = buf;
127         iov.iov_len  = buflen;
128
129         msgh.msg_iov = &iov;
130         msgh.msg_iovlen = 1;
131         msgh.msg_control = control;
132         msgh.msg_controllen = sizeof(control);
133
134         ret = recvmsg(sockfd, &msgh, 0);
135         if (ret <= 0) {
136                 RTE_LOG(ERR, VHOST_CONFIG, "recvmsg failed\n");
137                 return ret;
138         }
139
140         if (msgh.msg_flags & (MSG_TRUNC | MSG_CTRUNC)) {
141                 RTE_LOG(ERR, VHOST_CONFIG, "truncted msg\n");
142                 return -1;
143         }
144
145         for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
146                 cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
147                 if ((cmsg->cmsg_level == SOL_SOCKET) &&
148                         (cmsg->cmsg_type == SCM_RIGHTS)) {
149                         memcpy(fds, CMSG_DATA(cmsg), fdsize);
150                         break;
151                 }
152         }
153
154         return ret;
155 }
156
157 int
158 send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num)
159 {
160
161         struct iovec iov;
162         struct msghdr msgh;
163         size_t fdsize = fd_num * sizeof(int);
164         char control[CMSG_SPACE(fdsize)];
165         struct cmsghdr *cmsg;
166         int ret;
167
168         memset(&msgh, 0, sizeof(msgh));
169         iov.iov_base = buf;
170         iov.iov_len = buflen;
171
172         msgh.msg_iov = &iov;
173         msgh.msg_iovlen = 1;
174
175         if (fds && fd_num > 0) {
176                 msgh.msg_control = control;
177                 msgh.msg_controllen = sizeof(control);
178                 cmsg = CMSG_FIRSTHDR(&msgh);
179                 cmsg->cmsg_len = CMSG_LEN(fdsize);
180                 cmsg->cmsg_level = SOL_SOCKET;
181                 cmsg->cmsg_type = SCM_RIGHTS;
182                 memcpy(CMSG_DATA(cmsg), fds, fdsize);
183         } else {
184                 msgh.msg_control = NULL;
185                 msgh.msg_controllen = 0;
186         }
187
188         do {
189                 ret = sendmsg(sockfd, &msgh, 0);
190         } while (ret < 0 && errno == EINTR);
191
192         if (ret < 0) {
193                 RTE_LOG(ERR, VHOST_CONFIG,  "sendmsg error\n");
194                 return ret;
195         }
196
197         return ret;
198 }
199
200 static void
201 vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
202 {
203         int vid;
204         size_t size;
205         struct vhost_user_connection *conn;
206         int ret;
207
208         conn = malloc(sizeof(*conn));
209         if (conn == NULL) {
210                 close(fd);
211                 return;
212         }
213
214         vid = vhost_new_device();
215         if (vid == -1) {
216                 close(fd);
217                 free(conn);
218                 return;
219         }
220
221         size = strnlen(vsocket->path, PATH_MAX);
222         vhost_set_ifname(vid, vsocket->path, size);
223
224         if (vsocket->dequeue_zero_copy)
225                 vhost_enable_dequeue_zero_copy(vid);
226
227         RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
228
229         conn->connfd = fd;
230         conn->vsocket = vsocket;
231         conn->vid = vid;
232         ret = fdset_add(&vhost_user.fdset, fd, vhost_user_read_cb,
233                         NULL, conn);
234         if (ret < 0) {
235                 conn->connfd = -1;
236                 free(conn);
237                 close(fd);
238                 RTE_LOG(ERR, VHOST_CONFIG,
239                         "failed to add fd %d into vhost server fdset\n",
240                         fd);
241         }
242
243         pthread_mutex_lock(&vsocket->conn_mutex);
244         TAILQ_INSERT_TAIL(&vsocket->conn_list, conn, next);
245         pthread_mutex_unlock(&vsocket->conn_mutex);
246 }
247
248 /* call back when there is new vhost-user connection from client  */
249 static void
250 vhost_user_server_new_connection(int fd, void *dat, int *remove __rte_unused)
251 {
252         struct vhost_user_socket *vsocket = dat;
253
254         fd = accept(fd, NULL, NULL);
255         if (fd < 0)
256                 return;
257
258         RTE_LOG(INFO, VHOST_CONFIG, "new vhost user connection is %d\n", fd);
259         vhost_user_add_connection(fd, vsocket);
260 }
261
262 static void
263 vhost_user_read_cb(int connfd, void *dat, int *remove)
264 {
265         struct vhost_user_connection *conn = dat;
266         struct vhost_user_socket *vsocket = conn->vsocket;
267         int ret;
268
269         ret = vhost_user_msg_handler(conn->vid, connfd);
270         if (ret < 0) {
271                 close(connfd);
272                 *remove = 1;
273                 vhost_destroy_device(conn->vid);
274
275                 pthread_mutex_lock(&vsocket->conn_mutex);
276                 TAILQ_REMOVE(&vsocket->conn_list, conn, next);
277                 pthread_mutex_unlock(&vsocket->conn_mutex);
278
279                 free(conn);
280
281                 if (vsocket->reconnect)
282                         vhost_user_create_client(vsocket);
283         }
284 }
285
286 static int
287 create_unix_socket(const char *path, struct sockaddr_un *un, bool is_server)
288 {
289         int fd;
290
291         fd = socket(AF_UNIX, SOCK_STREAM, 0);
292         if (fd < 0)
293                 return -1;
294         RTE_LOG(INFO, VHOST_CONFIG, "vhost-user %s: socket created, fd: %d\n",
295                 is_server ? "server" : "client", fd);
296
297         if (!is_server && fcntl(fd, F_SETFL, O_NONBLOCK)) {
298                 RTE_LOG(ERR, VHOST_CONFIG,
299                         "vhost-user: can't set nonblocking mode for socket, fd: "
300                         "%d (%s)\n", fd, strerror(errno));
301                 close(fd);
302                 return -1;
303         }
304
305         memset(un, 0, sizeof(*un));
306         un->sun_family = AF_UNIX;
307         strncpy(un->sun_path, path, sizeof(un->sun_path));
308         un->sun_path[sizeof(un->sun_path) - 1] = '\0';
309
310         return fd;
311 }
312
313 static int
314 vhost_user_create_server(struct vhost_user_socket *vsocket)
315 {
316         int fd;
317         int ret;
318         struct sockaddr_un un;
319         const char *path = vsocket->path;
320
321         fd = create_unix_socket(path, &un, vsocket->is_server);
322         if (fd < 0)
323                 return -1;
324
325         ret = bind(fd, (struct sockaddr *)&un, sizeof(un));
326         if (ret < 0) {
327                 RTE_LOG(ERR, VHOST_CONFIG,
328                         "failed to bind to %s: %s; remove it and try again\n",
329                         path, strerror(errno));
330                 goto err;
331         }
332         RTE_LOG(INFO, VHOST_CONFIG, "bind to %s\n", path);
333
334         ret = listen(fd, MAX_VIRTIO_BACKLOG);
335         if (ret < 0)
336                 goto err;
337
338         vsocket->listenfd = fd;
339         ret = fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection,
340                   NULL, vsocket);
341         if (ret < 0) {
342                 RTE_LOG(ERR, VHOST_CONFIG,
343                         "failed to add listen fd %d to vhost server fdset\n",
344                         fd);
345                 goto err;
346         }
347
348         return 0;
349
350 err:
351         close(fd);
352         return -1;
353 }
354
355 struct vhost_user_reconnect {
356         struct sockaddr_un un;
357         int fd;
358         struct vhost_user_socket *vsocket;
359
360         TAILQ_ENTRY(vhost_user_reconnect) next;
361 };
362
363 TAILQ_HEAD(vhost_user_reconnect_tailq_list, vhost_user_reconnect);
364 struct vhost_user_reconnect_list {
365         struct vhost_user_reconnect_tailq_list head;
366         pthread_mutex_t mutex;
367 };
368
369 static struct vhost_user_reconnect_list reconn_list;
370 static pthread_t reconn_tid;
371
372 static int
373 vhost_user_connect_nonblock(int fd, struct sockaddr *un, size_t sz)
374 {
375         int ret, flags;
376
377         ret = connect(fd, un, sz);
378         if (ret < 0 && errno != EISCONN)
379                 return -1;
380
381         flags = fcntl(fd, F_GETFL, 0);
382         if (flags < 0) {
383                 RTE_LOG(ERR, VHOST_CONFIG,
384                         "can't get flags for connfd %d\n", fd);
385                 return -2;
386         }
387         if ((flags & O_NONBLOCK) && fcntl(fd, F_SETFL, flags & ~O_NONBLOCK)) {
388                 RTE_LOG(ERR, VHOST_CONFIG,
389                                 "can't disable nonblocking on fd %d\n", fd);
390                 return -2;
391         }
392         return 0;
393 }
394
395 static void *
396 vhost_user_client_reconnect(void *arg __rte_unused)
397 {
398         int ret;
399         struct vhost_user_reconnect *reconn, *next;
400
401         while (1) {
402                 pthread_mutex_lock(&reconn_list.mutex);
403
404                 /*
405                  * An equal implementation of TAILQ_FOREACH_SAFE,
406                  * which does not exist on all platforms.
407                  */
408                 for (reconn = TAILQ_FIRST(&reconn_list.head);
409                      reconn != NULL; reconn = next) {
410                         next = TAILQ_NEXT(reconn, next);
411
412                         ret = vhost_user_connect_nonblock(reconn->fd,
413                                                 (struct sockaddr *)&reconn->un,
414                                                 sizeof(reconn->un));
415                         if (ret == -2) {
416                                 close(reconn->fd);
417                                 RTE_LOG(ERR, VHOST_CONFIG,
418                                         "reconnection for fd %d failed\n",
419                                         reconn->fd);
420                                 goto remove_fd;
421                         }
422                         if (ret == -1)
423                                 continue;
424
425                         RTE_LOG(INFO, VHOST_CONFIG,
426                                 "%s: connected\n", reconn->vsocket->path);
427                         vhost_user_add_connection(reconn->fd, reconn->vsocket);
428 remove_fd:
429                         TAILQ_REMOVE(&reconn_list.head, reconn, next);
430                         free(reconn);
431                 }
432
433                 pthread_mutex_unlock(&reconn_list.mutex);
434                 sleep(1);
435         }
436
437         return NULL;
438 }
439
440 static int
441 vhost_user_reconnect_init(void)
442 {
443         int ret;
444
445         pthread_mutex_init(&reconn_list.mutex, NULL);
446         TAILQ_INIT(&reconn_list.head);
447
448         ret = pthread_create(&reconn_tid, NULL,
449                              vhost_user_client_reconnect, NULL);
450         if (ret < 0)
451                 RTE_LOG(ERR, VHOST_CONFIG, "failed to create reconnect thread");
452
453         return ret;
454 }
455
456 static int
457 vhost_user_create_client(struct vhost_user_socket *vsocket)
458 {
459         int fd;
460         int ret;
461         struct sockaddr_un un;
462         const char *path = vsocket->path;
463         struct vhost_user_reconnect *reconn;
464
465         fd = create_unix_socket(path, &un, vsocket->is_server);
466         if (fd < 0)
467                 return -1;
468
469         ret = vhost_user_connect_nonblock(fd, (struct sockaddr *)&un,
470                                           sizeof(un));
471         if (ret == 0) {
472                 vhost_user_add_connection(fd, vsocket);
473                 return 0;
474         }
475
476         RTE_LOG(WARNING, VHOST_CONFIG,
477                 "failed to connect to %s: %s\n",
478                 path, strerror(errno));
479
480         if (ret == -2 || !vsocket->reconnect) {
481                 close(fd);
482                 return -1;
483         }
484
485         RTE_LOG(INFO, VHOST_CONFIG, "%s: reconnecting...\n", path);
486         reconn = malloc(sizeof(*reconn));
487         if (reconn == NULL) {
488                 RTE_LOG(ERR, VHOST_CONFIG,
489                         "failed to allocate memory for reconnect\n");
490                 close(fd);
491                 return -1;
492         }
493         reconn->un = un;
494         reconn->fd = fd;
495         reconn->vsocket = vsocket;
496         pthread_mutex_lock(&reconn_list.mutex);
497         TAILQ_INSERT_TAIL(&reconn_list.head, reconn, next);
498         pthread_mutex_unlock(&reconn_list.mutex);
499
500         return 0;
501 }
502
503 static struct vhost_user_socket *
504 find_vhost_user_socket(const char *path)
505 {
506         int i;
507
508         for (i = 0; i < vhost_user.vsocket_cnt; i++) {
509                 struct vhost_user_socket *vsocket = vhost_user.vsockets[i];
510
511                 if (!strcmp(vsocket->path, path))
512                         return vsocket;
513         }
514
515         return NULL;
516 }
517
518 int
519 rte_vhost_driver_disable_features(const char *path, uint64_t features)
520 {
521         struct vhost_user_socket *vsocket;
522
523         pthread_mutex_lock(&vhost_user.mutex);
524         vsocket = find_vhost_user_socket(path);
525         if (vsocket)
526                 vsocket->features &= ~features;
527         pthread_mutex_unlock(&vhost_user.mutex);
528
529         return vsocket ? 0 : -1;
530 }
531
532 int
533 rte_vhost_driver_enable_features(const char *path, uint64_t features)
534 {
535         struct vhost_user_socket *vsocket;
536
537         pthread_mutex_lock(&vhost_user.mutex);
538         vsocket = find_vhost_user_socket(path);
539         if (vsocket) {
540                 if ((vsocket->supported_features & features) != features) {
541                         /*
542                          * trying to enable features the driver doesn't
543                          * support.
544                          */
545                         pthread_mutex_unlock(&vhost_user.mutex);
546                         return -1;
547                 }
548                 vsocket->features |= features;
549         }
550         pthread_mutex_unlock(&vhost_user.mutex);
551
552         return vsocket ? 0 : -1;
553 }
554
555 int
556 rte_vhost_driver_set_features(const char *path, uint64_t features)
557 {
558         struct vhost_user_socket *vsocket;
559
560         pthread_mutex_lock(&vhost_user.mutex);
561         vsocket = find_vhost_user_socket(path);
562         if (vsocket) {
563                 vsocket->supported_features = features;
564                 vsocket->features = features;
565         }
566         pthread_mutex_unlock(&vhost_user.mutex);
567
568         return vsocket ? 0 : -1;
569 }
570
571 int
572 rte_vhost_driver_get_features(const char *path, uint64_t *features)
573 {
574         struct vhost_user_socket *vsocket;
575
576         pthread_mutex_lock(&vhost_user.mutex);
577         vsocket = find_vhost_user_socket(path);
578         if (vsocket)
579                 *features = vsocket->features;
580         pthread_mutex_unlock(&vhost_user.mutex);
581
582         return vsocket ? 0 : -1;
583 }
584
585 /*
586  * Register a new vhost-user socket; here we could act as server
587  * (the default case), or client (when RTE_VHOST_USER_CLIENT) flag
588  * is set.
589  */
590 int
591 rte_vhost_driver_register(const char *path, uint64_t flags)
592 {
593         int ret = -1;
594         struct vhost_user_socket *vsocket;
595
596         if (!path)
597                 return -1;
598
599         pthread_mutex_lock(&vhost_user.mutex);
600
601         if (vhost_user.vsocket_cnt == MAX_VHOST_SOCKET) {
602                 RTE_LOG(ERR, VHOST_CONFIG,
603                         "error: the number of vhost sockets reaches maximum\n");
604                 goto out;
605         }
606
607         vsocket = malloc(sizeof(struct vhost_user_socket));
608         if (!vsocket)
609                 goto out;
610         memset(vsocket, 0, sizeof(struct vhost_user_socket));
611         vsocket->path = strdup(path);
612         TAILQ_INIT(&vsocket->conn_list);
613         pthread_mutex_init(&vsocket->conn_mutex, NULL);
614         vsocket->dequeue_zero_copy = flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY;
615
616         if ((flags & RTE_VHOST_USER_CLIENT) != 0) {
617                 vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
618                 if (vsocket->reconnect && reconn_tid == 0) {
619                         if (vhost_user_reconnect_init() < 0) {
620                                 free(vsocket->path);
621                                 free(vsocket);
622                                 goto out;
623                         }
624                 }
625                 ret = vhost_user_create_client(vsocket);
626         } else {
627                 vsocket->is_server = true;
628                 ret = vhost_user_create_server(vsocket);
629         }
630         if (ret < 0) {
631                 free(vsocket->path);
632                 free(vsocket);
633                 goto out;
634         }
635
636         vhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket;
637
638 out:
639         pthread_mutex_unlock(&vhost_user.mutex);
640
641         return ret;
642 }
643
644 static bool
645 vhost_user_remove_reconnect(struct vhost_user_socket *vsocket)
646 {
647         int found = false;
648         struct vhost_user_reconnect *reconn, *next;
649
650         pthread_mutex_lock(&reconn_list.mutex);
651
652         for (reconn = TAILQ_FIRST(&reconn_list.head);
653              reconn != NULL; reconn = next) {
654                 next = TAILQ_NEXT(reconn, next);
655
656                 if (reconn->vsocket == vsocket) {
657                         TAILQ_REMOVE(&reconn_list.head, reconn, next);
658                         close(reconn->fd);
659                         free(reconn);
660                         found = true;
661                         break;
662                 }
663         }
664         pthread_mutex_unlock(&reconn_list.mutex);
665         return found;
666 }
667
668 /**
669  * Unregister the specified vhost socket
670  */
671 int
672 rte_vhost_driver_unregister(const char *path)
673 {
674         int i;
675         int count;
676         struct vhost_user_connection *conn, *next;
677
678         pthread_mutex_lock(&vhost_user.mutex);
679
680         for (i = 0; i < vhost_user.vsocket_cnt; i++) {
681                 struct vhost_user_socket *vsocket = vhost_user.vsockets[i];
682
683                 if (!strcmp(vsocket->path, path)) {
684                         if (vsocket->is_server) {
685                                 fdset_del(&vhost_user.fdset, vsocket->listenfd);
686                                 close(vsocket->listenfd);
687                                 unlink(path);
688                         } else if (vsocket->reconnect) {
689                                 vhost_user_remove_reconnect(vsocket);
690                         }
691
692                         pthread_mutex_lock(&vsocket->conn_mutex);
693                         for (conn = TAILQ_FIRST(&vsocket->conn_list);
694                              conn != NULL;
695                              conn = next) {
696                                 next = TAILQ_NEXT(conn, next);
697
698                                 fdset_del(&vhost_user.fdset, conn->connfd);
699                                 RTE_LOG(INFO, VHOST_CONFIG,
700                                         "free connfd = %d for device '%s'\n",
701                                         conn->connfd, path);
702                                 close(conn->connfd);
703                                 vhost_destroy_device(conn->vid);
704                                 TAILQ_REMOVE(&vsocket->conn_list, conn, next);
705                                 free(conn);
706                         }
707                         pthread_mutex_unlock(&vsocket->conn_mutex);
708
709                         free(vsocket->path);
710                         free(vsocket);
711
712                         count = --vhost_user.vsocket_cnt;
713                         vhost_user.vsockets[i] = vhost_user.vsockets[count];
714                         vhost_user.vsockets[count] = NULL;
715                         pthread_mutex_unlock(&vhost_user.mutex);
716
717                         return 0;
718                 }
719         }
720         pthread_mutex_unlock(&vhost_user.mutex);
721
722         return -1;
723 }
724
725 int
726 rte_vhost_driver_session_start(void)
727 {
728         fdset_event_dispatch(&vhost_user.fdset);
729         return 0;
730 }