vhost: add API to set protocol features flags
authorMaxime Coquelin <maxime.coquelin@redhat.com>
Tue, 19 Mar 2019 10:54:16 +0000 (11:54 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 20 Mar 2019 17:15:42 +0000 (18:15 +0100)
rte_vhost_driver_set_protocol_features API is to be used
by external backends to advertise vhost-user protocol
features it supports.

It has to be called after rte_vhost_driver_register() and
before rte_vhost_driver_start().

Example of usage to advertize VHOST_USER_PROTOCOL_F_FOOBAR
protocol feature:

const char *path = "/tmp/vhost-user";
uint64_t protocol_features;
rte_vhost_driver_register(path, 0);
rte_vhost_driver_get_protocol_features(path, &protocol_features);
protocol_features |= VHOST_USER_PROTOCOL_F_FOOBAR;
rte_vhost_driver_set_protocol_features(path, protocol_features);
rte_vhost_driver_start(path);

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Tested-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
lib/librte_vhost/rte_vhost.h
lib/librte_vhost/rte_vhost_version.map
lib/librte_vhost/socket.c

index 2753670..c9c3929 100644 (file)
@@ -405,6 +405,20 @@ int rte_vhost_driver_disable_features(const char *path, uint64_t features);
  */
 int rte_vhost_driver_get_features(const char *path, uint64_t *features);
 
+/**
+ * Set the protocol feature bits before feature negotiation.
+ *
+ * @param path
+ *  The vhost-user socket file path
+ * @param protocol_features
+ *  Supported protocol features
+ * @return
+ *  0 on success, -1 on failure
+ */
+int __rte_experimental
+rte_vhost_driver_set_protocol_features(const char *path,
+               uint64_t protocol_features);
+
 /**
  * Get the protocol feature bits before feature negotiation.
  *
index 8a3bc19..5f1d4a7 100644 (file)
@@ -86,4 +86,5 @@ EXPERIMENTAL {
        rte_vhost_host_notifier_ctrl;
        rte_vdpa_relay_vring_used;
        rte_vhost_extern_callback_register;
+       rte_vhost_driver_set_protocol_features;
 };
index 9883b04..3da9de6 100644 (file)
@@ -707,6 +707,20 @@ unlock_exit:
        return ret;
 }
 
+int
+rte_vhost_driver_set_protocol_features(const char *path,
+               uint64_t protocol_features)
+{
+       struct vhost_user_socket *vsocket;
+
+       pthread_mutex_lock(&vhost_user.mutex);
+       vsocket = find_vhost_user_socket(path);
+       if (vsocket)
+               vsocket->protocol_features = protocol_features;
+       pthread_mutex_unlock(&vhost_user.mutex);
+       return vsocket ? 0 : -1;
+}
+
 int
 rte_vhost_driver_get_protocol_features(const char *path,
                uint64_t *protocol_features)