X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_vhost%2Fvhost_cuse%2Fvhost-net-cdev.c;h=c613e68e8e231be96889542abc8915d2ee2aa565;hb=5d0c255e6b6c412e7cc687ea67af0f5f48e0f25e;hp=2bb07af15621d0eb7aeeb358a429681c9a4eb5a3;hpb=34f4c46dc42d781f83e181ce744d79779d53c8a1;p=dpdk.git diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c index 2bb07af156..c613e68e8e 100644 --- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c @@ -44,7 +44,9 @@ #include #include +#include "virtio-net-cdev.h" #include "vhost-net.h" +#include "eventfd_copy.h" #define FUSE_OPT_DUMMY "\0\0" #define FUSE_OPT_FORE "-f\0\0" @@ -56,7 +58,6 @@ static const char cuse_device_name[] = "/dev/cuse"; static const char default_cdev[] = "vhost-net"; static struct fuse_session *session; -static struct vhost_net_device_ops const *ops; /* * Returns vhost_device_ctx from given fuse_req_t. The index is populated later @@ -84,7 +85,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi) struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi); int err = 0; - err = ops->new_device(ctx); + err = vhost_new_device(ctx); if (err == -1) { fuse_reply_err(req, EPERM); return; @@ -106,7 +107,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi) int err = 0; struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi); - ops->destroy_device(ctx); + vhost_destroy_device(ctx); RTE_LOG(INFO, VHOST_CONFIG, "(%"PRIu64") Device released\n", ctx.fh); fuse_reply_err(req, err); } @@ -194,31 +195,37 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, case VHOST_NET_SET_BACKEND: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_NET_SET_BACKEND\n", ctx.fh); - VHOST_IOCTL_R(struct vhost_vring_file, file, ops->set_backend); + 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, ops->get_features); + 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, ops->set_features); + 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(ops->reset_owner); + VHOST_IOCTL(vhost_reset_owner); break; case VHOST_SET_OWNER: LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_OWNER\n", ctx.fh); - VHOST_IOCTL(ops->set_owner); + VHOST_IOCTL(vhost_set_owner); break; case VHOST_SET_MEM_TABLE: @@ -246,8 +253,8 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, break; default: - result = ops->set_mem_table(ctx, - in_buf, mem_temp.nregions); + result = cuse_set_mem_table(ctx, in_buf, + mem_temp.nregions); if (result) fuse_reply_err(req, EINVAL); else @@ -259,42 +266,62 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, LOG_DEBUG(VHOST_CONFIG, "(%"PRIu64") IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh); VHOST_IOCTL_R(struct vhost_vring_state, state, - ops->set_vring_num); + 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, - ops->set_vring_base); + 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, ops->get_vring_base); + 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, - ops->set_vring_addr); + vhost_set_vring_addr); break; case VHOST_SET_VRING_KICK: - LOG_DEBUG(VHOST_CONFIG, - "(%"PRIu64") IOCTL: VHOST_SET_VRING_KICK\n", ctx.fh); - VHOST_IOCTL_R(struct vhost_vring_file, file, - ops->set_vring_kick); - break; - case VHOST_SET_VRING_CALL: - LOG_DEBUG(VHOST_CONFIG, - "(%"PRIu64") IOCTL: VHOST_SET_VRING_CALL\n", ctx.fh); - VHOST_IOCTL_R(struct vhost_vring_file, file, - ops->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: @@ -345,6 +372,9 @@ rte_vhost_driver_register(const char *dev_name) return -1; } + if (eventfd_init() < 0) + return -1; + /* * The device name is created. This is passed to QEMU so that it can * register the device with our application. @@ -366,8 +396,6 @@ rte_vhost_driver_register(const char *dev_name) cuse_info.dev_info_argv = device_argv; cuse_info.flags = CUSE_UNRESTRICTED_IOCTL; - ops = get_virtio_net_callbacks(); - session = cuse_lowlevel_setup(3, fuse_argv, &cuse_info, &vhost_net_ops, 0, NULL); if (session == NULL) @@ -376,6 +404,15 @@ rte_vhost_driver_register(const char *dev_name) return 0; } +/** + * An empty function for unregister + */ +int +rte_vhost_driver_unregister(const char *dev_name __rte_unused) +{ + return 0; +} + /** * The CUSE session is launched allowing the application to receive open, * release and ioctl calls.