> -----Original Message-----
> From: Maxime Coquelin <maxime.coque...@redhat.com>
> Sent: Friday, March 31, 2023 11:43 PM
> To: dev@dpdk.org; david.march...@redhat.com; Xia, Chenbo
> <chenbo....@intel.com>; m...@redhat.com; f...@redhat.com;
> jasow...@redhat.com; Liang, Cunming <cunming.li...@intel.com>; Xie, Yongji
> <xieyon...@bytedance.com>; echau...@redhat.com; epere...@redhat.com;
> amore...@redhat.com
> Cc: Maxime Coquelin <maxime.coque...@redhat.com>
> Subject: [RFC 11/27] vhost: introduce backend ops
> 
> This patch introduces backend ops struct, that will enable
> calling backend specifics callbacks (Vhost-user, VDUSE), in
> shared code.
> 
> This is an empty shell for now, it will be filled in later
> patches.
> 
> Signed-off-by: Maxime Coquelin <maxime.coque...@redhat.com>
> ---
>  lib/vhost/socket.c     |  2 +-
>  lib/vhost/vhost.c      |  8 +++++++-
>  lib/vhost/vhost.h      | 10 +++++++++-
>  lib/vhost/vhost_user.c |  8 ++++++++
>  lib/vhost/vhost_user.h |  1 +
>  5 files changed, 26 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
> index 669c322e12..ba54263824 100644
> --- a/lib/vhost/socket.c
> +++ b/lib/vhost/socket.c
> @@ -221,7 +221,7 @@ vhost_user_add_connection(int fd, struct
> vhost_user_socket *vsocket)
>               return;
>       }
> 
> -     vid = vhost_new_device();
> +     vid = vhost_user_new_device();
>       if (vid == -1) {
>               goto err;
>       }
> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> index 4f16307e4d..41f212315e 100644
> --- a/lib/vhost/vhost.c
> +++ b/lib/vhost/vhost.c
> @@ -676,11 +676,16 @@ reset_device(struct virtio_net *dev)
>   * there is a new virtio device being attached).
>   */
>  int
> -vhost_new_device(void)
> +vhost_new_device(struct vhost_backend_ops *ops)
>  {
>       struct virtio_net *dev;
>       int i;
> 
> +     if (ops == NULL) {
> +             VHOST_LOG_CONFIG("device", ERR, "missing backend ops.\n");
> +             return -1;
> +     }
> +
>       pthread_mutex_lock(&vhost_dev_lock);
>       for (i = 0; i < RTE_MAX_VHOST_DEVICE; i++) {
>               if (vhost_devices[i] == NULL)
> @@ -708,6 +713,7 @@ vhost_new_device(void)
>       dev->backend_req_fd = -1;
>       dev->postcopy_ufd = -1;
>       rte_spinlock_init(&dev->backend_req_lock);
> +     dev->backend_ops = ops;
> 
>       return i;
>  }
> diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h
> index 4ace5ab081..cc5c707205 100644
> --- a/lib/vhost/vhost.h
> +++ b/lib/vhost/vhost.h
> @@ -89,6 +89,12 @@
>       for (iter = val; iter < num; iter++)
>  #endif
> 
> +/**
> + * Structure that contains backend-specific ops.
> + */
> +struct vhost_backend_ops {
> +};
> +
>  /**
>   * Structure contains buffer address, length and descriptor index
>   * from vring to do scatter RX.
> @@ -513,6 +519,8 @@ struct virtio_net {
>       void                    *extern_data;
>       /* pre and post vhost user message handlers for the device */
>       struct rte_vhost_user_extern_ops extern_ops;
> +
> +     struct vhost_backend_ops *backend_ops;
>  } __rte_cache_aligned;
> 
>  static inline void
> @@ -812,7 +820,7 @@ get_device(int vid)
>       return dev;
>  }
> 
> -int vhost_new_device(void);
> +int vhost_new_device(struct vhost_backend_ops *ops);
>  void cleanup_device(struct virtio_net *dev, int destroy);
>  void reset_device(struct virtio_net *dev);
>  void vhost_destroy_device(int);
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index a989f2c46d..2d5dec5bc1 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -3464,3 +3464,11 @@ int rte_vhost_host_notifier_ctrl(int vid, uint16_t
> qid, bool enable)
> 
>       return ret;
>  }
> +
> +static struct vhost_backend_ops vhost_user_backend_ops;
> +
> +int
> +vhost_user_new_device(void)
> +{
> +     return vhost_new_device(&vhost_user_backend_ops);
> +}
> diff --git a/lib/vhost/vhost_user.h b/lib/vhost/vhost_user.h
> index a0987a58f9..61456049c8 100644
> --- a/lib/vhost/vhost_user.h
> +++ b/lib/vhost/vhost_user.h
> @@ -185,5 +185,6 @@ int vhost_user_iotlb_miss(struct virtio_net *dev,
> uint64_t iova, uint8_t perm);
>  int read_fd_message(char *ifname, int sockfd, char *buf, int buflen, int
> *fds, int max_fds,
>               int *fd_num);
>  int send_fd_message(char *ifname, int sockfd, char *buf, int buflen, int
> *fds, int fd_num);
> +int vhost_user_new_device(void);
> 
>  #endif
> --
> 2.39.2

Reviewed-by: Chenbo Xia <chenbo....@intel.com> 

Reply via email to