void user_set_vring_call(int vid, struct VhostUserMsg *pmsg) { struct vhost_vring_file file; file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) file.fd = VIRTIO_INVALID_EVENTFD; else file.fd = pmsg->fds[0]; RTE_LOG(INFO, VHOST_CONFIG, "vring call idx:%d file:%d\n", file.index, file.fd); vhost_set_vring_call(vid, &file); }
/* * The IOCTLs are handled using CUSE/FUSE in userspace. Depending on the type * of IOCTL a buffer is requested to read or to write. This request is handled * by FUSE and the buffer is then given to CUSE. */ static void vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, struct fuse_file_info *fi, __rte_unused unsigned flags, const void *in_buf, size_t in_bufsz, size_t out_bufsz) { struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi); struct vhost_vring_file file; struct vhost_vring_state state; struct vhost_vring_addr addr; uint64_t features; uint32_t index; int result = 0; switch (cmd) { case VHOST_NET_SET_BACKEND: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh); if (!in_buf) { VHOST_IOCTL_RETRY(sizeof(file), 0); break; } file = *(const struct vhost_vring_file *)in_buf; result = cuse_set_backend(ctx, &file); fuse_reply_ioctl(req, result, NULL, 0); break; case VHOST_GET_FEATURES: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_GET_FEATURES\n", ctx.fh); VHOST_IOCTL_W(uint64_t, features, vhost_get_features); break; case VHOST_SET_FEATURES: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_FEATURES\n", ctx.fh); VHOST_IOCTL_R(uint64_t, features, vhost_set_features); break; case VHOST_RESET_OWNER: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_RESET_OWNER\n", ctx.fh); VHOST_IOCTL(vhost_reset_owner); break; case VHOST_SET_OWNER: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_OWNER\n", ctx.fh); VHOST_IOCTL(vhost_set_owner); break; case VHOST_SET_MEM_TABLE: /*TODO fix race condition.*/ LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_MEM_TABLE\n", ctx.fh); static struct vhost_memory mem_temp; switch (in_bufsz) { case 0: VHOST_IOCTL_RETRY(sizeof(struct vhost_memory), 0); break; case sizeof(struct vhost_memory): mem_temp = *(const struct vhost_memory *) in_buf; if (mem_temp.nregions > 0) { VHOST_IOCTL_RETRY(sizeof(struct vhost_memory) + (sizeof(struct vhost_memory_region) * mem_temp.nregions), 0); } else { result = -1; fuse_reply_ioctl(req, result, NULL, 0); } break; default: result = cuse_set_mem_table(ctx, in_buf, mem_temp.nregions); if (result) fuse_reply_err(req, EINVAL); else fuse_reply_ioctl(req, result, NULL, 0); } break; case VHOST_SET_VRING_NUM: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_num); break; case VHOST_SET_VRING_BASE: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_base); break; case VHOST_GET_VRING_BASE: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh); VHOST_IOCTL_RW(uint32_t, index, struct vhost_vring_state, state, vhost_get_vring_base); break; case VHOST_SET_VRING_ADDR: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh); VHOST_IOCTL_R(struct vhost_vring_addr, addr, vhost_set_vring_addr); break; case VHOST_SET_VRING_KICK: case VHOST_SET_VRING_CALL: if (cmd == VHOST_SET_VRING_KICK) LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_VRING_KICK\n", ctx.fh); else LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_VRING_CALL\n", ctx.fh); if (!in_buf) VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0); else { int fd; file = *(const struct vhost_vring_file *)in_buf; LOG_DEBUG(VHOST_CONFIG, "idx:%d fd:%d\n", file.index, file.fd); fd = eventfd_copy(file.fd, ctx.pid); if (fd < 0) { fuse_reply_ioctl(req, -1, NULL, 0); result = -1; break; } file.fd = fd; if (cmd == VHOST_SET_VRING_KICK) { result = vhost_set_vring_kick(ctx, &file); fuse_reply_ioctl(req, result, NULL, 0); } else { result = vhost_set_vring_call(ctx, &file); fuse_reply_ioctl(req, result, NULL, 0); } } break; default: RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") IOCTL: DOESN NOT EXIST\n", ctx.fh); result = -1; fuse_reply_ioctl(req, result, NULL, 0); } if (result < 0) LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: FAIL\n", ctx.fh); else LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: SUCCESS\n", ctx.fh); }