[PATCH v7 07/18] vhost: add API to get vDPA device type
Andy Pei
andy.pei at intel.com
Wed Apr 27 10:29:55 CEST 2022
Vhost backend of different devices have different features.
Add a API to get vDPA device type, net device or blk device
currently, so users can set different features for different
kinds of devices.
Signed-off-by: Andy Pei <andy.pei at intel.com>
---
lib/vhost/rte_vhost.h | 17 +++++++++++++++++
lib/vhost/socket.c | 39 +++++++++++++++++++++++++++++++++++++++
lib/vhost/vdpa_driver.h | 3 +++
lib/vhost/version.map | 2 ++
4 files changed, 61 insertions(+)
diff --git a/lib/vhost/rte_vhost.h b/lib/vhost/rte_vhost.h
index c733f85..c977a24 100644
--- a/lib/vhost/rte_vhost.h
+++ b/lib/vhost/rte_vhost.h
@@ -117,6 +117,9 @@
#define RTE_MAX_VHOST_DEVICE 1024
+#define VDPA_DEVICE_TYPE_NET 0
+#define VDPA_DEVICE_TYPE_BLK 1
+
struct rte_vdpa_device;
/**
@@ -486,6 +489,20 @@ struct rte_vdpa_device *
rte_vhost_driver_get_vdpa_device(const char *path);
/**
+ * Get the device type of the vdpa device.
+ *
+ * @param path
+ * The vhost-user socket file path
+ * @param type
+ * the device type of the vdpa device
+ * @return
+ * 0 on success, -1 on failure
+ */
+__rte_experimental
+int
+rte_vhost_driver_get_vdpa_dev_type(const char *path, uint32_t *type);
+
+/**
* Set the feature bits the vhost-user driver supports.
*
* @param path
diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
index b304339..7da90e8 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -619,6 +619,45 @@ struct rte_vdpa_device *
}
int
+rte_vhost_driver_get_vdpa_dev_type(const char *path, uint32_t *type)
+{
+ struct vhost_user_socket *vsocket;
+ struct rte_vdpa_device *vdpa_dev;
+ uint32_t vdpa_type = 0;
+ int ret = 0;
+
+ pthread_mutex_lock(&vhost_user.mutex);
+ vsocket = find_vhost_user_socket(path);
+ if (!vsocket) {
+ VHOST_LOG_CONFIG(ERR,
+ "(%s) socket file is not registered yet.\n",
+ path);
+ ret = -1;
+ goto unlock_exit;
+ }
+
+ vdpa_dev = vsocket->vdpa_dev;
+ if (!vdpa_dev) {
+ ret = -1;
+ goto unlock_exit;
+ }
+
+ if (vdpa_dev->ops->get_dev_type(vdpa_dev, &vdpa_type) < 0) {
+ VHOST_LOG_CONFIG(ERR,
+ "(%s) failed to get vdpa dev type for socket file.\n",
+ path);
+ ret = -1;
+ goto unlock_exit;
+ }
+
+ *type = vdpa_type;
+
+unlock_exit:
+ pthread_mutex_unlock(&vhost_user.mutex);
+ return ret;
+}
+
+int
rte_vhost_driver_disable_features(const char *path, uint64_t features)
{
struct vhost_user_socket *vsocket;
diff --git a/lib/vhost/vdpa_driver.h b/lib/vhost/vdpa_driver.h
index e59a834..9cbd7cd 100644
--- a/lib/vhost/vdpa_driver.h
+++ b/lib/vhost/vdpa_driver.h
@@ -78,6 +78,9 @@ struct rte_vdpa_dev_ops {
/** Set the device configuration space */
int (*set_config)(int vid, uint8_t *config, uint32_t offset,
uint32_t size, uint32_t flags);
+
+ /** get device type: net device, blk device... */
+ int (*get_dev_type)(struct rte_vdpa_device *dev, uint32_t *type);
};
/**
diff --git a/lib/vhost/version.map b/lib/vhost/version.map
index 0a66c58..fe4e8de 100644
--- a/lib/vhost/version.map
+++ b/lib/vhost/version.map
@@ -87,6 +87,8 @@ EXPERIMENTAL {
# added in 22.03
rte_vhost_async_dma_configure;
+
+ rte_vhost_driver_get_vdpa_dev_type;
};
INTERNAL {
--
1.8.3.1
More information about the dev
mailing list