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 <l...@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