| 209 | } |
| 210 | |
| 211 | static void |
| 212 | vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) |
| 213 | { |
| 214 | int vid; |
| 215 | size_t size; |
| 216 | struct vhost_user_connection *conn; |
| 217 | int ret; |
| 218 | struct virtio_net *dev; |
| 219 | |
| 220 | if (vsocket == NULL) |
| 221 | return; |
| 222 | |
| 223 | conn = malloc(sizeof(*conn)); |
| 224 | if (conn == NULL) { |
| 225 | close(fd); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | vid = vhost_user_new_device(); |
| 230 | if (vid == -1) { |
| 231 | goto err; |
| 232 | } |
| 233 | |
| 234 | size = strnlen(vsocket->path, PATH_MAX); |
| 235 | vhost_set_ifname(vid, vsocket->path, size); |
| 236 | |
| 237 | vhost_setup_virtio_net(vid, vsocket->use_builtin_virtio_net, |
| 238 | vsocket->net_compliant_ol_flags, vsocket->stats_enabled, |
| 239 | vsocket->iommu_support); |
| 240 | |
| 241 | vhost_attach_vdpa_device(vid, vsocket->vdpa_dev); |
| 242 | |
| 243 | if (vsocket->extbuf) |
| 244 | vhost_enable_extbuf(vid); |
| 245 | |
| 246 | if (vsocket->linearbuf) |
| 247 | vhost_enable_linearbuf(vid); |
| 248 | |
| 249 | if (vsocket->async_copy) { |
| 250 | dev = get_device(vid); |
| 251 | |
| 252 | if (dev) |
| 253 | dev->async_copy = 1; |
| 254 | } |
| 255 | |
| 256 | VHOST_LOG_CONFIG(vsocket->path, INFO, "new device, handle is %d\n", vid); |
| 257 | |
| 258 | if (vsocket->notify_ops->new_connection) { |
| 259 | ret = vsocket->notify_ops->new_connection(vid); |
| 260 | if (ret < 0) { |
| 261 | VHOST_LOG_CONFIG(vsocket->path, ERR, |
| 262 | "failed to add vhost user connection with fd %d\n", |
| 263 | fd); |
| 264 | goto err_cleanup; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | conn->connfd = fd; |
no test coverage detected