qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC v3 6/8] vhost-backend: export the vhost backend helper


From: Laurent Vivier
Subject: Re: [RFC v3 6/8] vhost-backend: export the vhost backend helper
Date: Tue, 16 Jun 2020 10:16:43 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0

On 29/05/2020 16:06, Cindy Lu wrote:
> export the helper then we can reuse some of them in vhost-vdpa
> 
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
>  hw/virtio/vhost-backend.c         | 34 ++++++++++++++++++-------------
>  include/hw/virtio/vhost-backend.h | 28 +++++++++++++++++++++++++
>  2 files changed, 48 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
> index 48905383f8..42efb4967b 100644
> --- a/hw/virtio/vhost-backend.c
> +++ b/hw/virtio/vhost-backend.c
> @@ -14,7 +14,7 @@
>  #include "qemu/error-report.h"
>  #include "qemu/main-loop.h"
>  #include "standard-headers/linux/vhost_types.h"
> -
> +#include "hw/virtio/vhost-vdpa.h"

You can't include this file because it is created in the next patch.

>  #ifdef CONFIG_VHOST_KERNEL
>  #include <linux/vhost.h>
>  #include <sys/ioctl.h>
> @@ -22,10 +22,16 @@
>  static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int 
> request,
>                               void *arg)
>  {
> -    int fd = (uintptr_t) dev->opaque;
> -
> -    assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL);
> -
> +    int fd = -1;
> +    struct vhost_vdpa *v = NULL;
> +    if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL) {
> +        fd  = (uintptr_t) dev->opaque;
> +    }
> +    if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA) {
> +        v = dev->opaque;
> +        fd = v->device_fd;
> +    }
> +    assert(fd != -1);

A switch would be cleaner:

    switch (dev->vhost_ops->backend_type) {
    case VHOST_BACKEND_TYPE_KERNEL:
        fd  = (uintptr_t)dev->opaque;
        break;
    case VHOST_BACKEND_TYPE_VDPA:
        fd = ((struct vhost_vdpa *)dev->opaque)->device_fd;
        break;
    default:
        g_assert_not_reached()
    }

>      return ioctl(fd, request, arg);
>  }
>  

Thanks,
Laurent




reply via email to

[Prev in Thread] Current Thread [Next in Thread]