vhost: rename device ops struct
[dpdk.git] / lib / librte_vhost / socket.c
index 53663f4..3b68fc9 100644 (file)
@@ -77,6 +77,8 @@ struct vhost_user_socket {
         */
        uint64_t supported_features;
        uint64_t features;
+
+       struct vhost_device_ops const *notify_ops;
 };
 
 struct vhost_user_connection {
@@ -579,7 +581,13 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features)
                *features = vsocket->features;
        pthread_mutex_unlock(&vhost_user.mutex);
 
-       return vsocket ? 0 : -1;
+       if (!vsocket) {
+               RTE_LOG(ERR, VHOST_CONFIG,
+                       "socket file %s is not registered yet.\n", path);
+               return -1;
+       } else {
+               return 0;
+       }
 }
 
 /*
@@ -613,6 +621,21 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
        pthread_mutex_init(&vsocket->conn_mutex, NULL);
        vsocket->dequeue_zero_copy = flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY;
 
+       /*
+        * Set the supported features correctly for the builtin vhost-user
+        * net driver.
+        *
+        * Applications know nothing about features the builtin virtio net
+        * driver (virtio_net.c) supports, thus it's not possible for them
+        * to invoke rte_vhost_driver_set_features(). To workaround it, here
+        * we set it unconditionally. If the application want to implement
+        * another vhost-user driver (say SCSI), it should call the
+        * rte_vhost_driver_set_features(), which will overwrite following
+        * two values.
+        */
+       vsocket->supported_features = VIRTIO_NET_SUPPORTED_FEATURES;
+       vsocket->features           = VIRTIO_NET_SUPPORTED_FEATURES;
+
        if ((flags & RTE_VHOST_USER_CLIENT) != 0) {
                vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
                if (vsocket->reconnect && reconn_tid == 0) {
@@ -722,6 +745,36 @@ rte_vhost_driver_unregister(const char *path)
        return -1;
 }
 
+/*
+ * Register ops so that we can add/remove device to data core.
+ */
+int
+rte_vhost_driver_callback_register(const char *path,
+       struct vhost_device_ops const * const ops)
+{
+       struct vhost_user_socket *vsocket;
+
+       pthread_mutex_lock(&vhost_user.mutex);
+       vsocket = find_vhost_user_socket(path);
+       if (vsocket)
+               vsocket->notify_ops = ops;
+       pthread_mutex_unlock(&vhost_user.mutex);
+
+       return vsocket ? 0 : -1;
+}
+
+struct vhost_device_ops const *
+vhost_driver_callback_get(const char *path)
+{
+       struct vhost_user_socket *vsocket;
+
+       pthread_mutex_lock(&vhost_user.mutex);
+       vsocket = find_vhost_user_socket(path);
+       pthread_mutex_unlock(&vhost_user.mutex);
+
+       return vsocket ? vsocket->notify_ops : NULL;
+}
+
 int
 rte_vhost_driver_session_start(void)
 {