* Register a new vhost-user socket; here we could act as server * (the default case), or client (when RTE_VHOST_USER_CLIENT) flag * is set. */
| 900 | * is set. |
| 901 | */ |
| 902 | int |
| 903 | rte_vhost_driver_register(const char *path, uint64_t flags) |
| 904 | { |
| 905 | int ret = -1; |
| 906 | struct vhost_user_socket *vsocket; |
| 907 | |
| 908 | if (!path) |
| 909 | return -1; |
| 910 | |
| 911 | pthread_mutex_lock(&vhost_user.mutex); |
| 912 | |
| 913 | if (vhost_user.vsocket_cnt == MAX_VHOST_SOCKET) { |
| 914 | VHOST_LOG_CONFIG(path, ERR, "the number of vhost sockets reaches maximum\n"); |
| 915 | goto out; |
| 916 | } |
| 917 | |
| 918 | vsocket = malloc(sizeof(struct vhost_user_socket)); |
| 919 | if (!vsocket) |
| 920 | goto out; |
| 921 | memset(vsocket, 0, sizeof(struct vhost_user_socket)); |
| 922 | vsocket->path = strdup(path); |
| 923 | if (vsocket->path == NULL) { |
| 924 | VHOST_LOG_CONFIG(path, ERR, "failed to copy socket path string\n"); |
| 925 | vhost_user_socket_mem_free(vsocket); |
| 926 | goto out; |
| 927 | } |
| 928 | TAILQ_INIT(&vsocket->conn_list); |
| 929 | ret = pthread_mutex_init(&vsocket->conn_mutex, NULL); |
| 930 | if (ret) { |
| 931 | VHOST_LOG_CONFIG(path, ERR, "failed to init connection mutex\n"); |
| 932 | goto out_free; |
| 933 | } |
| 934 | |
| 935 | if (!strncmp("/dev/vduse/", path, strlen("/dev/vduse/"))) |
| 936 | vsocket->is_vduse = true; |
| 937 | |
| 938 | vsocket->vdpa_dev = NULL; |
| 939 | vsocket->max_queue_pairs = VHOST_MAX_QUEUE_PAIRS; |
| 940 | vsocket->extbuf = flags & RTE_VHOST_USER_EXTBUF_SUPPORT; |
| 941 | vsocket->linearbuf = flags & RTE_VHOST_USER_LINEARBUF_SUPPORT; |
| 942 | vsocket->async_copy = flags & RTE_VHOST_USER_ASYNC_COPY; |
| 943 | vsocket->net_compliant_ol_flags = flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS; |
| 944 | vsocket->stats_enabled = flags & RTE_VHOST_USER_NET_STATS_ENABLE; |
| 945 | if (vsocket->is_vduse) |
| 946 | vsocket->iommu_support = true; |
| 947 | else |
| 948 | vsocket->iommu_support = flags & RTE_VHOST_USER_IOMMU_SUPPORT; |
| 949 | |
| 950 | if (vsocket->async_copy && (vsocket->iommu_support || |
| 951 | (flags & RTE_VHOST_USER_POSTCOPY_SUPPORT))) { |
| 952 | VHOST_LOG_CONFIG(path, ERR, "async copy with IOMMU or post-copy not supported\n"); |
| 953 | goto out_mutex; |
| 954 | } |
| 955 | |
| 956 | /* |
| 957 | * Set the supported features correctly for the builtin vhost-user |
| 958 | * net driver. |
| 959 | * |
no test coverage detected