[v8,10/12] vhost: add type to rte vdpa device

Message ID 1666094871-25721-11-git-send-email-andy.pei@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series vdpa/ifc: add multi queue support |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Pei, Andy Oct. 18, 2022, 12:07 p.m. UTC
  Add type to rte_vdpa_device to store device type.
Call vdpa ops get_dev_type to fill type when register
vdpa device.

Signed-off-by: Andy Pei <andy.pei@intel.com>
---
 lib/vhost/socket.c      | 15 +--------------
 lib/vhost/vdpa.c        | 15 +++++++++++++++
 lib/vhost/vdpa_driver.h |  2 ++
 3 files changed, 18 insertions(+), 14 deletions(-)
  

Comments

Maxime Coquelin Oct. 18, 2022, 1:15 p.m. UTC | #1
On 10/18/22 14:07, Andy Pei wrote:
> Add type to rte_vdpa_device to store device type.
> Call vdpa ops get_dev_type to fill type when register
> vdpa device.
> 
> Signed-off-by: Andy Pei <andy.pei@intel.com>
> ---
>   lib/vhost/socket.c      | 15 +--------------
>   lib/vhost/vdpa.c        | 15 +++++++++++++++
>   lib/vhost/vdpa_driver.h |  2 ++
>   3 files changed, 18 insertions(+), 14 deletions(-)
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks for doing the change!
Maxime
  
Pei, Andy Oct. 18, 2022, 1:42 p.m. UTC | #2
Hi Maxime,

Thanks for your efforts.

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Tuesday, October 18, 2022 9:15 PM
> To: Pei, Andy <andy.pei@intel.com>; dev@dpdk.org
> Cc: Xia, Chenbo <Chenbo.Xia@intel.com>; Xu, Rosen <rosen.xu@intel.com>;
> Huang, Wei <wei.huang@intel.com>; Cao, Gang <gang.cao@intel.com>
> Subject: Re: [PATCH v8 10/12] vhost: add type to rte vdpa device
> 
> 
> 
> On 10/18/22 14:07, Andy Pei wrote:
> > Add type to rte_vdpa_device to store device type.
> > Call vdpa ops get_dev_type to fill type when register vdpa device.
> >
> > Signed-off-by: Andy Pei <andy.pei@intel.com>
> > ---
> >   lib/vhost/socket.c      | 15 +--------------
> >   lib/vhost/vdpa.c        | 15 +++++++++++++++
> >   lib/vhost/vdpa_driver.h |  2 ++
> >   3 files changed, 18 insertions(+), 14 deletions(-)
> >
> 
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> 
> Thanks for doing the change!
> Maxime
  

Patch

diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
index 608ae57..863a6f6 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -627,7 +627,6 @@  struct rte_vdpa_device *
 {
 	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);
@@ -644,19 +643,7 @@  struct rte_vdpa_device *
 		goto unlock_exit;
 	}
 
-	if (vdpa_dev->ops->get_dev_type) {
-		ret = vdpa_dev->ops->get_dev_type(vdpa_dev, &vdpa_type);
-		if (ret) {
-			VHOST_LOG_CONFIG(path, ERR,
-				"failed to get vdpa dev type for socket file.\n");
-			ret = -1;
-			goto unlock_exit;
-		}
-	} else {
-		vdpa_type = RTE_VHOST_VDPA_DEVICE_TYPE_NET;
-	}
-
-	*type = vdpa_type;
+	*type = vdpa_dev->type;
 
 unlock_exit:
 	pthread_mutex_unlock(&vhost_user.mutex);
diff --git a/lib/vhost/vdpa.c b/lib/vhost/vdpa.c
index bb82857..577cb00 100644
--- a/lib/vhost/vdpa.c
+++ b/lib/vhost/vdpa.c
@@ -73,6 +73,7 @@  struct rte_vdpa_device *
 		struct rte_vdpa_dev_ops *ops)
 {
 	struct rte_vdpa_device *dev;
+	int ret = 0;
 
 	if (ops == NULL)
 		return NULL;
@@ -101,6 +102,20 @@  struct rte_vdpa_device *
 
 	dev->device = rte_dev;
 	dev->ops = ops;
+
+	if (ops->get_dev_type) {
+		ret = ops->get_dev_type(dev, &dev->type);
+		if (ret) {
+			VHOST_LOG_CONFIG(rte_dev->name, ERR,
+					 "Failed to get vdpa dev type.\n");
+			ret = -1;
+			goto out_unlock;
+		}
+	} else {
+		/** by default, we assume vdpa device is a net device */
+		dev->type = RTE_VHOST_VDPA_DEVICE_TYPE_NET;
+	}
+
 	TAILQ_INSERT_TAIL(&vdpa_device_list, dev, next);
 out_unlock:
 	rte_spinlock_unlock(&vdpa_device_list_lock);
diff --git a/lib/vhost/vdpa_driver.h b/lib/vhost/vdpa_driver.h
index 8b88a53..8db4ab9 100644
--- a/lib/vhost/vdpa_driver.h
+++ b/lib/vhost/vdpa_driver.h
@@ -92,6 +92,8 @@  struct rte_vdpa_device {
 	struct rte_device *device;
 	/** vdpa device operations */
 	struct rte_vdpa_dev_ops *ops;
+	/** vdpa device type: net, blk... */
+	uint32_t type;
 };
 
 /**