Received: from eggs.gnu.org ([2001:4830:134:3::10]:40896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoCnx-0005ua-Vf for qemu-devel@nongnu.org; Wed, 04 Dec 2013 08:48:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoCno-0003G8-QA for qemu-devel@nongnu.org; Wed, 04 Dec 2013 08:47:53 -0500 Received: from mail-ee0-x22a.google.com ([2a00:1450:4013:c00::22a]:47432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoCno-0003G3-JH for qemu-devel@nongnu.org; Wed, 04 Dec 2013 08:47:44 -0500 Received: by mail-ee0-f42.google.com with SMTP id e53so1400381eek.1 for ; Wed, 04 Dec 2013 05:47:43 -0800 (PST) Date: Wed, 4 Dec 2013 14:47:40 +0100 From: Stefan Hajnoczi Message-ID: <20131204134740.GB27381@stefanha-thinkpad.redhat.com> References: <1385754746-21172-1-git-send-email-a.motakis@virtualopensystems.com> <1385754746-21172-3-git-send-email-a.motakis@virtualopensystems.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1385754746-21172-3-git-send-email-a.motakis@virtualopensystems.com> Subject: Re: [Qemu-devel] [PATCH 2/5] Add vhost-kernel and the vhost-user skeleton List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Antonios Motakis Cc: "Michael S. Tsirkin" , qemu-devel@nongnu.org, n.nikolaev@virtualopensystems.com, Anthony Liguori , lukego@gmail.com, Paolo Bonzini , tech@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).