[dpdk-dev] [PATCH 40/40] net/virtio: move Vhost-vDPA data to its backend

Xia, Chenbo chenbo.xia at intel.com
Thu Jan 7 07:50:51 CET 2021


Hi Maxime,

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin at redhat.com>
> Sent: Monday, December 21, 2020 5:14 AM
> To: dev at dpdk.org; Xia, Chenbo <chenbo.xia at intel.com>; olivier.matz at 6wind.com;
> amorenoz at redhat.com; david.marchand at redhat.com
> Cc: Maxime Coquelin <maxime.coquelin at redhat.com>
> Subject: [PATCH 40/40] net/virtio: move Vhost-vDPA data to its backend
> 
> As done earlier for Vhost-user and Vhost-kernel, this
> patch moves the Vhost-vDPA specific data to its backend
> file.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
> ---
>  drivers/net/virtio/virtio_user/vhost_vdpa.c   | 77 ++++++++++++++-----
>  .../net/virtio/virtio_user/virtio_user_dev.h  |  3 -
>  2 files changed, 58 insertions(+), 22 deletions(-)
> 

<snip>

> @@ -269,16 +298,23 @@ vhost_vdpa_set_status(struct virtio_user_dev *dev,
> uint8_t status)
>  static int
>  vhost_vdpa_setup(struct virtio_user_dev *dev)
>  {
> +	struct vhost_vdpa_data *data;
>  	uint32_t did = (uint32_t)-1;
> 
> -	dev->vhostfd = open(dev->path, O_RDWR);
> -	if (dev->vhostfd < 0) {
> +	data = malloc(sizeof(*data));
> +	if (!data) {
> +		PMD_DRV_LOG(ERR, "(%s) Faidle to allocate backend data", dev-
> >path);
> +		return -1;
> +	}
> +
> +	data->vhostfd = open(dev->path, O_RDWR);
> +	if (data->vhostfd < 0) {
>  		PMD_DRV_LOG(ERR, "Failed to open %s: %s\n",
>  				dev->path, strerror(errno));
>  		return -1;
>  	}
> 
> -	if (ioctl(dev->vhostfd, VHOST_VDPA_GET_DEVICE_ID, &did) < 0 ||
> +	if (ioctl(data->vhostfd, VHOST_VDPA_GET_DEVICE_ID, &did) < 0 ||
>  			did != VIRTIO_ID_NETWORK) {
>  		PMD_DRV_LOG(ERR, "Invalid vdpa device ID: %u\n", did);
>  		return -1;

Need to clean up resources when error happens?

> @@ -288,9 +324,12 @@ vhost_vdpa_setup(struct virtio_user_dev *dev)
>  }
> 
>  static int
> -vhost_vdpa_destroy(struct virtio_user_dev *dev __rte_unused)
> +vhost_vdpa_destroy(struct virtio_user_dev *dev )

Should delete the space before ')'?

>  {
> -	return;
> +	struct vhost_vdpa_data *data = dev->backend_data;
> +
> +	close(data->vhostfd);
> +
>  	return 0;
>  }
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h
> b/drivers/net/virtio/virtio_user/virtio_user_dev.h
> index 5a2c9d38dd..2e0d6504f6 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
> @@ -28,9 +28,6 @@ struct virtio_user_dev {
>  	enum virtio_user_backend_type backend_type;
>  	bool		is_server;  /* server or client mode */
> 
> -	/* for vhost_vdpa backend */
> -	int		vhostfd;
> -
>  	/* for both vhost_user and vhost_kernel */

Is this comment no longer needed too?

Thanks!
Chenbo

>  	int		callfds[VIRTIO_MAX_VIRTQUEUES];
>  	int		kickfds[VIRTIO_MAX_VIRTQUEUES];
> --
> 2.29.2



More information about the dev mailing list