Lines Matching defs:vsocket
70 struct vhost_user_socket *vsocket;
89 static int create_unix_socket(struct vhost_user_socket *vsocket);
90 static int vhost_user_start_client(struct vhost_user_socket *vsocket);
206 vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
214 if (vsocket == NULL)
228 size = strnlen(vsocket->path, PATH_MAX);
229 vhost_set_ifname(vid, vsocket->path, size);
231 vhost_setup_virtio_net(vid, vsocket->use_builtin_virtio_net,
232 vsocket->net_compliant_ol_flags, vsocket->stats_enabled,
233 vsocket->iommu_support);
235 vhost_attach_vdpa_device(vid, vsocket->vdpa_dev);
237 if (vsocket->extbuf)
240 if (vsocket->linearbuf)
243 if (vsocket->async_copy) {
250 VHOST_CONFIG_LOG(vsocket->path, INFO, "new device, handle is %d", vid);
252 if (vsocket->notify_ops->new_connection) {
253 ret = vsocket->notify_ops->new_connection(vid);
255 VHOST_CONFIG_LOG(vsocket->path, ERR,
263 conn->vsocket = vsocket;
268 VHOST_CONFIG_LOG(vsocket->path, ERR,
272 if (vsocket->notify_ops->destroy_connection)
273 vsocket->notify_ops->destroy_connection(conn->vid);
278 pthread_mutex_lock(&vsocket->conn_mutex);
279 TAILQ_INSERT_TAIL(&vsocket->conn_list, conn, next);
280 pthread_mutex_unlock(&vsocket->conn_mutex);
295 struct vhost_user_socket *vsocket = dat;
301 VHOST_CONFIG_LOG(vsocket->path, INFO, "new vhost user connection is %d", fd);
302 vhost_user_add_connection(fd, vsocket);
309 struct vhost_user_socket *vsocket = conn->vsocket;
322 if (vsocket->notify_ops->destroy_connection)
323 vsocket->notify_ops->destroy_connection(conn->vid);
327 if (vsocket->reconnect) {
328 create_unix_socket(vsocket);
329 vhost_user_start_client(vsocket);
332 pthread_mutex_lock(&vsocket->conn_mutex);
333 TAILQ_REMOVE(&vsocket->conn_list, conn, next);
334 pthread_mutex_unlock(&vsocket->conn_mutex);
341 create_unix_socket(struct vhost_user_socket *vsocket)
344 struct sockaddr_un *un = &vsocket->un;
349 VHOST_CONFIG_LOG(vsocket->path, INFO, "vhost-user %s: socket created, fd: %d",
350 vsocket->is_server ? "server" : "client", fd);
352 if (!vsocket->is_server && fcntl(fd, F_SETFL, O_NONBLOCK)) {
353 VHOST_CONFIG_LOG(vsocket->path, ERR,
362 strlcpy(un->sun_path, vsocket->path, sizeof(un->sun_path));
364 vsocket->socket_fd = fd;
369 vhost_user_start_server(struct vhost_user_socket *vsocket)
372 int fd = vsocket->socket_fd;
373 const char *path = vsocket->path;
385 ret = bind(fd, (struct sockaddr *)&vsocket->un, sizeof(vsocket->un));
398 NULL, vsocket);
415 struct vhost_user_socket *vsocket;
468 ret = vhost_user_connect_nonblock(reconn->vsocket->path, reconn->fd,
473 VHOST_CONFIG_LOG(reconn->vsocket->path, ERR,
481 VHOST_CONFIG_LOG(reconn->vsocket->path, INFO, "connected");
482 vhost_user_add_connection(reconn->fd, reconn->vsocket);
517 vhost_user_start_client(struct vhost_user_socket *vsocket)
520 int fd = vsocket->socket_fd;
521 const char *path = vsocket->path;
524 if (!vsocket->async_connect || !vsocket->reconnect) {
525 ret = vhost_user_connect_nonblock(vsocket->path, fd,
526 (struct sockaddr *)&vsocket->un, sizeof(vsocket->un));
528 vhost_user_add_connection(fd, vsocket);
534 if (ret == -2 || !vsocket->reconnect) {
547 reconn->un = vsocket->un;
549 reconn->vsocket = vsocket;
566 struct vhost_user_socket *vsocket = vhost_user.vsockets[i];
568 if (!strcmp(vsocket->path, path))
569 return vsocket;
579 struct vhost_user_socket *vsocket;
585 vsocket = find_vhost_user_socket(path);
586 if (vsocket)
587 vsocket->vdpa_dev = dev;
590 return vsocket ? 0 : -1;
596 struct vhost_user_socket *vsocket;
599 vsocket = find_vhost_user_socket(path);
600 if (vsocket)
601 vsocket->vdpa_dev = NULL;
604 return vsocket ? 0 : -1;
610 struct vhost_user_socket *vsocket;
614 vsocket = find_vhost_user_socket(path);
615 if (vsocket)
616 dev = vsocket->vdpa_dev;
625 struct vhost_user_socket *vsocket;
630 vsocket = find_vhost_user_socket(path);
631 if (!vsocket) {
637 vdpa_dev = vsocket->vdpa_dev;
653 struct vhost_user_socket *vsocket;
656 vsocket = find_vhost_user_socket(path);
663 if (vsocket)
664 vsocket->features &= ~features;
667 return vsocket ? 0 : -1;
673 struct vhost_user_socket *vsocket;
676 vsocket = find_vhost_user_socket(path);
677 if (vsocket) {
678 if ((vsocket->supported_features & features) != features) {
686 vsocket->features |= features;
690 return vsocket ? 0 : -1;
696 struct vhost_user_socket *vsocket;
699 vsocket = find_vhost_user_socket(path);
700 if (vsocket) {
701 vsocket->supported_features = features;
702 vsocket->features = features;
707 vsocket->use_builtin_virtio_net = false;
711 return vsocket ? 0 : -1;
717 struct vhost_user_socket *vsocket;
723 vsocket = find_vhost_user_socket(path);
724 if (!vsocket) {
730 vdpa_dev = vsocket->vdpa_dev;
732 *features = vsocket->features;
742 *features = vsocket->features & vdpa_features;
753 struct vhost_user_socket *vsocket;
756 vsocket = find_vhost_user_socket(path);
757 if (vsocket)
758 vsocket->protocol_features = protocol_features;
760 return vsocket ? 0 : -1;
767 struct vhost_user_socket *vsocket;
773 vsocket = find_vhost_user_socket(path);
774 if (!vsocket) {
780 vdpa_dev = vsocket->vdpa_dev;
782 *protocol_features = vsocket->protocol_features;
793 *protocol_features = vsocket->protocol_features
804 struct vhost_user_socket *vsocket;
810 vsocket = find_vhost_user_socket(path);
811 if (!vsocket) {
817 vdpa_dev = vsocket->vdpa_dev;
819 *queue_num = vsocket->max_queue_pairs;
829 *queue_num = RTE_MIN(vsocket->max_queue_pairs, vdpa_queue_num);
839 struct vhost_user_socket *vsocket;
843 vsocket = find_vhost_user_socket(path);
844 if (!vsocket) {
855 if (!vsocket->is_vduse) {
871 vsocket->max_queue_pairs = max_queue_pairs;
879 vhost_user_socket_mem_free(struct vhost_user_socket *vsocket)
881 if (vsocket == NULL)
884 free(vsocket->path);
885 free(vsocket);
897 struct vhost_user_socket *vsocket;
909 vsocket = malloc(sizeof(struct vhost_user_socket));
910 if (!vsocket)
912 memset(vsocket, 0, sizeof(struct vhost_user_socket));
913 vsocket->path = strdup(path);
914 if (vsocket->path == NULL) {
916 vhost_user_socket_mem_free(vsocket);
919 TAILQ_INIT(&vsocket->conn_list);
920 pthread_mutex_init(&vsocket->conn_mutex, NULL);
923 vsocket->is_vduse = true;
925 vsocket->vdpa_dev = NULL;
926 vsocket->max_queue_pairs = VHOST_MAX_QUEUE_PAIRS;
927 vsocket->extbuf = flags & RTE_VHOST_USER_EXTBUF_SUPPORT;
928 vsocket->linearbuf = flags & RTE_VHOST_USER_LINEARBUF_SUPPORT;
929 vsocket->async_copy = flags & RTE_VHOST_USER_ASYNC_COPY;
930 vsocket->net_compliant_ol_flags = flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS;
931 vsocket->stats_enabled = flags & RTE_VHOST_USER_NET_STATS_ENABLE;
932 vsocket->async_connect = flags & RTE_VHOST_USER_ASYNC_CONNECT;
933 if (vsocket->is_vduse)
934 vsocket->iommu_support = true;
936 vsocket->iommu_support = flags & RTE_VHOST_USER_IOMMU_SUPPORT;
938 if (vsocket->async_copy && (vsocket->iommu_support ||
956 vsocket->use_builtin_virtio_net = true;
957 if (vsocket->is_vduse) {
958 vsocket->supported_features = VDUSE_NET_SUPPORTED_FEATURES;
959 vsocket->features = VDUSE_NET_SUPPORTED_FEATURES;
961 vsocket->supported_features = VHOST_USER_NET_SUPPORTED_FEATURES;
962 vsocket->features = VHOST_USER_NET_SUPPORTED_FEATURES;
963 vsocket->protocol_features = VHOST_USER_PROTOCOL_FEATURES;
966 if (vsocket->async_copy) {
967 vsocket->supported_features &= ~(1ULL << VHOST_F_LOG_ALL);
968 vsocket->features &= ~(1ULL << VHOST_F_LOG_ALL);
977 if (vsocket->linearbuf && !vsocket->extbuf) {
985 vsocket->supported_features &= ~seg_offload_features;
986 vsocket->features &= ~seg_offload_features;
989 if (!vsocket->iommu_support) {
990 vsocket->supported_features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
991 vsocket->features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
995 vsocket->protocol_features &=
1005 if (!vsocket->is_vduse) {
1007 vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
1008 if (vsocket->reconnect && reconn_tid.opaque_id == 0) {
1013 vsocket->is_server = true;
1015 ret = create_unix_socket(vsocket);
1020 vhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket;
1026 if (pthread_mutex_destroy(&vsocket->conn_mutex)) {
1036 vhost_user_remove_reconnect(struct vhost_user_socket *vsocket)
1047 if (reconn->vsocket == vsocket) {
1076 struct vhost_user_socket *vsocket = vhost_user.vsockets[i];
1077 if (strcmp(vsocket->path, path))
1080 if (vsocket->is_vduse) {
1082 } else if (vsocket->is_server) {
1088 if (fdset_try_del(vhost_user.fdset, vsocket->socket_fd) == -1) {
1092 } else if (vsocket->reconnect) {
1093 vhost_user_remove_reconnect(vsocket);
1096 pthread_mutex_lock(&vsocket->conn_mutex);
1097 for (conn = TAILQ_FIRST(&vsocket->conn_list);
1103 * If r/wcb is executing, release vsocket's
1110 pthread_mutex_unlock(&vsocket->conn_mutex);
1118 TAILQ_REMOVE(&vsocket->conn_list, conn, next);
1121 pthread_mutex_unlock(&vsocket->conn_mutex);
1123 if (vsocket->is_server) {
1124 close(vsocket->socket_fd);
1128 pthread_mutex_destroy(&vsocket->conn_mutex);
1129 vhost_user_socket_mem_free(vsocket);
1149 struct vhost_user_socket *vsocket;
1152 vsocket = find_vhost_user_socket(path);
1153 if (vsocket)
1154 vsocket->notify_ops = ops;
1157 return vsocket ? 0 : -1;
1163 struct vhost_user_socket *vsocket;
1166 vsocket = find_vhost_user_socket(path);
1169 return vsocket ? vsocket->notify_ops : NULL;
1175 struct vhost_user_socket *vsocket;
1178 vsocket = find_vhost_user_socket(path);
1181 if (!vsocket)
1184 if (vsocket->is_vduse)
1185 return vduse_device_create(path, vsocket->net_compliant_ol_flags);
1195 if (vsocket->is_server)
1196 return vhost_user_start_server(vsocket);
1198 return vhost_user_start_client(vsocket);