qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Antonios Motakis <a.motakis@virtualopensystems.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel@nongnu.org, n.nikolaev@virtualopensystems.com,
	Anthony Liguori <anthony@codemonkey.ws>,
	lukego@gmail.com, Paolo Bonzini <pbonzini@redhat.com>,
	tech@virtualopensystems.com
Subject: Re: [Qemu-devel] [PATCH 2/5] Add vhost-kernel and the vhost-user skeleton
Date: Wed, 4 Dec 2013 14:47:40 +0100	[thread overview]
Message-ID: <20131204134740.GB27381@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1385754746-21172-3-git-send-email-a.motakis@virtualopensystems.com>

On Fri, Nov 29, 2013 at 08:52:23PM +0100, Antonios Motakis wrote:
> diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
> index 05de174..80defe4 100644
> --- a/hw/virtio/vhost-backend.c
> +++ b/hw/virtio/vhost-backend.c
> @@ -25,9 +25,18 @@ static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int request,
>  
>  int vhost_call(struct vhost_dev *dev, unsigned long int request, void *arg)
>  {
> -    int result;
> +    int result = -1;
>  
> -    result = vhost_kernel_call(dev, request, arg);
> +    switch (dev->backend_type) {
> +    case VHOST_BACKEND_TYPE_KERNEL:
> +        result = vhost_kernel_call(dev, request, arg);
> +        break;
> +    case VHOST_BACKEND_TYPE_USER:
> +        fprintf(stderr, "vhost-user not implemented\n");
> +        break;
> +    default:
> +        fprintf(stderr, "Unknown vhost backend type\n");
> +    }

The switch statement approach gets messy fast when local variables are
needed inside some case labels.  It also makes it hard to conditionally
compile features without using #ifdef.

Perhaps instead a VhostOps struct could be used:

/* Vhost backends implement this interface */
typedef struct {
    int vhost_call(struct vhost_dev *dev,
                   unsigned long int request,
                   void *arg);
    ...
} VhostOps;

const VhostOps vhost_kernel_ops = {
    ...
};

const VhostOps vhost_user_opts = {
    ...
};

ret = dev->vhost_ops->vhost_call(dev, request, arg);

Something along those lines.  It keeps the different backend
implementations separate (they can live in separate files and be
conditional in Makefile.objs).

  reply	other threads:[~2013-12-04 13:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-29 19:52 [Qemu-devel] [RFC 0/5] Vhost and vhost-net support for userspace based backends Antonios Motakis
2013-11-29 19:52 ` [Qemu-devel] [PATCH 1/5] Decouple vhost from kernel interface Antonios Motakis
2013-11-29 19:52 ` [Qemu-devel] [PATCH 2/5] Add vhost-kernel and the vhost-user skeleton Antonios Motakis
2013-12-04 13:47   ` Stefan Hajnoczi [this message]
2013-12-04 15:23     ` Antonios Motakis
2013-11-29 19:52 ` [Qemu-devel] [PATCH 3/5] Add vhostsock option Antonios Motakis
2013-12-04 13:42   ` Stefan Hajnoczi
2013-12-04 15:21     ` Antonios Motakis
2013-12-04 14:28   ` Eric Blake
2013-11-29 19:52 ` [Qemu-devel] [PATCH 4/5] Add domain socket communication for vhost-user backend Antonios Motakis
2013-11-29 19:52 ` [Qemu-devel] [PATCH 5/5] Add vhost-user calls implementation Antonios Motakis
2013-12-04 20:00   ` Michael S. Tsirkin
2013-12-10 12:05     ` Antonios Motakis
2013-12-04 13:56 ` [Qemu-devel] [RFC 0/5] Vhost and vhost-net support for userspace based backends Stefan Hajnoczi
2013-12-04 15:23   ` Antonios Motakis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131204134740.GB27381@stefanha-thinkpad.redhat.com \
    --to=stefanha@gmail.com \
    --cc=a.motakis@virtualopensystems.com \
    --cc=anthony@codemonkey.ws \
    --cc=lukego@gmail.com \
    --cc=mst@redhat.com \
    --cc=n.nikolaev@virtualopensystems.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tech@virtualopensystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).