On 12/20/20 10:14 PM, Maxime Coquelin wrote:
> 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.coque...@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(-)
>
...
> @@ -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;
> @@ -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 )
> {
> - return;
> + struct vhost_vdpa_data *data = dev->backend_data;
> +
> + close(data->vhostfd);
> +
Note to self: free(data); here.
> 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 */
> int callfds[VIRTIO_MAX_VIRTQUEUES];
> int kickfds[VIRTIO_MAX_VIRTQUEUES];
>