| 350 | } |
| 351 | |
| 352 | static void |
| 353 | vduse_events_handler(int fd, void *arg, int *remove __rte_unused) |
| 354 | { |
| 355 | struct virtio_net *dev = arg; |
| 356 | struct vduse_dev_request req; |
| 357 | struct vduse_dev_response resp; |
| 358 | struct vhost_virtqueue *vq; |
| 359 | uint8_t old_status = dev->status; |
| 360 | int ret; |
| 361 | |
| 362 | memset(&resp, 0, sizeof(resp)); |
| 363 | |
| 364 | ret = read(fd, &req, sizeof(req)); |
| 365 | if (ret < 0) { |
| 366 | VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to read request: %s\n", |
| 367 | strerror(errno)); |
| 368 | return; |
| 369 | } else if (ret < (int)sizeof(req)) { |
| 370 | VHOST_LOG_CONFIG(dev->ifname, ERR, "Incomplete to read request %d\n", ret); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | VHOST_LOG_CONFIG(dev->ifname, INFO, "New request: %s (%u)\n", |
| 375 | vduse_req_id_to_str(req.type), req.type); |
| 376 | |
| 377 | switch (req.type) { |
| 378 | case VDUSE_GET_VQ_STATE: |
| 379 | vq = dev->virtqueue[req.vq_state.index]; |
| 380 | VHOST_LOG_CONFIG(dev->ifname, INFO, "\tvq index: %u, avail_index: %u\n", |
| 381 | req.vq_state.index, vq->last_avail_idx); |
| 382 | resp.vq_state.split.avail_index = vq->last_avail_idx; |
| 383 | resp.result = VDUSE_REQ_RESULT_OK; |
| 384 | break; |
| 385 | case VDUSE_SET_STATUS: |
| 386 | VHOST_LOG_CONFIG(dev->ifname, INFO, "\tnew status: 0x%08x\n", |
| 387 | req.s.status); |
| 388 | old_status = dev->status; |
| 389 | dev->status = req.s.status; |
| 390 | resp.result = VDUSE_REQ_RESULT_OK; |
| 391 | break; |
| 392 | case VDUSE_UPDATE_IOTLB: |
| 393 | VHOST_LOG_CONFIG(dev->ifname, INFO, "\tIOVA range: %" PRIx64 " - %" PRIx64 "\n", |
| 394 | (uint64_t)req.iova.start, (uint64_t)req.iova.last); |
| 395 | vhost_user_iotlb_cache_remove(dev, req.iova.start, |
| 396 | req.iova.last - req.iova.start + 1); |
| 397 | resp.result = VDUSE_REQ_RESULT_OK; |
| 398 | break; |
| 399 | default: |
| 400 | resp.result = VDUSE_REQ_RESULT_FAILED; |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | resp.request_id = req.request_id; |
| 405 | |
| 406 | ret = write(dev->vduse_dev_fd, &resp, sizeof(resp)); |
| 407 | if (ret != sizeof(resp)) { |
| 408 | VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to write response %s\n", |
| 409 | strerror(errno)); |
nothing calls this directly
no test coverage detected