cxgbe: get descriptor limits
[dpdk.git] / lib / librte_vhost / vhost_cuse / vhost-net-cdev.c
index 57c76cb..ae7ad8d 100644 (file)
@@ -44,7 +44,9 @@
 #include <rte_string_fns.h>
 #include <rte_virtio_net.h>
 
-#include "vhost-net-cdev.h"
+#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,7 @@ 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;
+struct vhost_net_device_ops const *ops;
 
 /*
  * Returns vhost_device_ctx from given fuse_req_t. The index is populated later
@@ -194,7 +196,13 @@ 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:
@@ -246,8 +254,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
@@ -284,17 +292,37 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
                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 = ops->set_vring_kick(ctx, &file);
+                               fuse_reply_ioctl(req, result, NULL, 0);
+                       } else {
+                               result = ops->set_vring_call(ctx, &file);
+                               fuse_reply_ioctl(req, result, NULL, 0);
+                       }
+               }
                break;
 
        default:
@@ -345,6 +373,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.
@@ -376,6 +407,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.