diff mbox

[3/5] Add vhostsock option

Message ID 1385754746-21172-4-git-send-email-a.motakis@virtualopensystems.com
State New
Headers show

Commit Message

Antonios Motakis Nov. 29, 2013, 7:52 p.m. UTC
Adding a new tap network backend option - vhostsock. It points
to a named unix domain socket, that will be used to communicate
with vhost-user backend. This is a temporary work around; in future
versions of this series vhost-user will be made independent from
the tap network backend.

Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com>
Signed-off-by: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com>
---
 hw/net/vhost_net.c      | 22 +++++++++++++++++-----
 include/net/vhost_net.h |  5 ++++-
 net/tap.c               |  4 +++-
 qapi-schema.json        |  3 +++
 qemu-options.hx         |  3 ++-
 5 files changed, 29 insertions(+), 8 deletions(-)

Comments

Stefan Hajnoczi Dec. 4, 2013, 1:42 p.m. UTC | #1
On Fri, Nov 29, 2013 at 08:52:24PM +0100, Antonios Motakis wrote:
> @@ -91,15 +91,27 @@ static int vhost_net_get_fd(NetClientState *backend)
>      }
>  }
>  
> -struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
> -                                 bool force)
> +struct vhost_net *vhost_net_init(NetClientState *backend, char *vhostsock,
> +                                 int devfd, bool force)
>  {
>      int r;
>      struct vhost_net *net = g_malloc(sizeof *net);
> +    const char *backend_sock = 0;
> +    VhostBackendType backend_type = VHOST_BACKEND_TYPE_NONE;
> +
>      if (!backend) {
>          fprintf(stderr, "vhost-net requires backend to be setup\n");
>          goto fail;
>      }
> +
> +    if (vhostsock && strcmp(vhostsock, VHOST_NET_DEFAULT_SOCK) != 0) {

This is a weird hack.  Why check for VHOST_NET_DEFAULT_SOCK at all?

If the option is not present then kernel vhost is used, if the option is
present then userspace vhost is used.  I don't understand why a magic
hardcoded path is useful.
Eric Blake Dec. 4, 2013, 2:28 p.m. UTC | #2
On 11/29/2013 12:52 PM, Antonios Motakis wrote:
> Adding a new tap network backend option - vhostsock. It points
> to a named unix domain socket, that will be used to communicate
> with vhost-user backend. This is a temporary work around; in future
> versions of this series vhost-user will be made independent from
> the tap network backend.
> 

> +++ b/qapi-schema.json
> @@ -2891,6 +2891,8 @@
>  #
>  # @vhostforce: #optional vhost on for non-MSIX virtio guests
>  #
> +# @vhostsock: #optional vhost backend socket
> +#

Needs a "(since 2.0)" designation.
Antonios Motakis Dec. 4, 2013, 3:21 p.m. UTC | #3
On Wed, Dec 4, 2013 at 2:42 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:

> On Fri, Nov 29, 2013 at 08:52:24PM +0100, Antonios Motakis wrote:
> > @@ -91,15 +91,27 @@ static int vhost_net_get_fd(NetClientState *backend)
> >      }
> >  }
> >
> > -struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
> > -                                 bool force)
> > +struct vhost_net *vhost_net_init(NetClientState *backend, char
> *vhostsock,
> > +                                 int devfd, bool force)
> >  {
> >      int r;
> >      struct vhost_net *net = g_malloc(sizeof *net);
> > +    const char *backend_sock = 0;
> > +    VhostBackendType backend_type = VHOST_BACKEND_TYPE_NONE;
> > +
> >      if (!backend) {
> >          fprintf(stderr, "vhost-net requires backend to be setup\n");
> >          goto fail;
> >      }
> > +
> > +    if (vhostsock && strcmp(vhostsock, VHOST_NET_DEFAULT_SOCK) != 0) {
>
> This is a weird hack.  Why check for VHOST_NET_DEFAULT_SOCK at all?
>
> If the option is not present then kernel vhost is used, if the option is
> present then userspace vhost is used.  I don't understand why a magic
> hardcoded path is useful.
>

This code will be reworked for the next version of the series, so this
shouldn't be a problem then.

Antonios
diff mbox

Patch

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 58a1880..8c9d425 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -91,15 +91,27 @@  static int vhost_net_get_fd(NetClientState *backend)
     }
 }
 
-struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
-                                 bool force)
+struct vhost_net *vhost_net_init(NetClientState *backend, char *vhostsock,
+                                 int devfd, bool force)
 {
     int r;
     struct vhost_net *net = g_malloc(sizeof *net);
+    const char *backend_sock = 0;
+    VhostBackendType backend_type = VHOST_BACKEND_TYPE_NONE;
+
     if (!backend) {
         fprintf(stderr, "vhost-net requires backend to be setup\n");
         goto fail;
     }
+
+    if (vhostsock && strcmp(vhostsock, VHOST_NET_DEFAULT_SOCK) != 0) {
+        backend_type = VHOST_BACKEND_TYPE_USER;
+        backend_sock = vhostsock;
+    } else {
+        backend_type = VHOST_BACKEND_TYPE_KERNEL;
+        backend_sock = VHOST_NET_DEFAULT_SOCK;
+    }
+
     r = vhost_net_get_fd(backend);
     if (r < 0) {
         goto fail;
@@ -112,7 +124,7 @@  struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
     net->dev.nvqs = 2;
     net->dev.vqs = net->vqs;
 
-    r = vhost_dev_init(&net->dev, devfd, "/dev/vhost-net", VHOST_BACKEND_TYPE_KERNEL, force);
+    r = vhost_dev_init(&net->dev, devfd, backend_sock, backend_type, force);
     if (r < 0) {
         goto fail;
     }
@@ -282,8 +294,8 @@  void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
     vhost_virtqueue_mask(&net->dev, dev, idx, mask);
 }
 #else
-struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
-                                 bool force)
+struct vhost_net *vhost_net_init(NetClientState *backend, char *vhostsock,
+                                 int devfd, bool force)
 {
     error_report("vhost-net support is not compiled in");
     return NULL;
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 2d936bb..7bb6435 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -3,10 +3,13 @@ 
 
 #include "net/net.h"
 
+#define VHOST_NET_DEFAULT_SOCK  "/dev/vhost-net"
+
 struct vhost_net;
 typedef struct vhost_net VHostNetState;
 
-VHostNetState *vhost_net_init(NetClientState *backend, int devfd, bool force);
+VHostNetState *vhost_net_init(NetClientState *backend, char *vhostsock,
+                              int devfd, bool force);
 
 bool vhost_net_query(VHostNetState *net, VirtIODevice *dev);
 int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues);
diff --git a/net/tap.c b/net/tap.c
index 39c1cda..c4eba01 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -632,7 +632,9 @@  static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
             vhostfd = -1;
         }
 
-        s->vhost_net = vhost_net_init(&s->nc, vhostfd,
+        s->vhost_net = vhost_net_init(&s->nc,
+                                      tap->has_vhostsock ? tap->vhostsock : 0,
+                                      vhostfd,
                                       tap->has_vhostforce && tap->vhostforce);
         if (!s->vhost_net) {
             error_report("vhost-net requested but could not be initialized");
diff --git a/qapi-schema.json b/qapi-schema.json
index 83fa485..dc35929 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2891,6 +2891,8 @@ 
 #
 # @vhostforce: #optional vhost on for non-MSIX virtio guests
 #
+# @vhostsock: #optional vhost backend socket
+#
 # @queues: #optional number of queues to be created for multiqueue capable tap
 #
 # Since 1.2
@@ -2909,6 +2911,7 @@ 
     '*vhostfd':    'str',
     '*vhostfds':   'str',
     '*vhostforce': 'bool',
+    '*vhostsock':  'str',
     '*queues':     'uint32'} }
 
 ##
diff --git a/qemu-options.hx b/qemu-options.hx
index 8b94264..9f80720 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1370,7 +1370,7 @@  DEF("net", HAS_ARG, QEMU_OPTION_net,
     "-net tap[,vlan=n][,name=str],ifname=name\n"
     "                connect the host TAP network interface to VLAN 'n'\n"
 #else
-    "-net tap[,vlan=n][,name=str][,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]\n"
+    "-net tap[,vlan=n][,name=str][,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n][,vhostsock=file]\n"
     "                connect the host TAP network interface to VLAN 'n'\n"
     "                use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n"
     "                to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n"
@@ -1390,6 +1390,7 @@  DEF("net", HAS_ARG, QEMU_OPTION_net,
     "                use 'vhostfd=h' to connect to an already opened vhost net device\n"
     "                use 'vhostfds=x:y:...:z to connect to multiple already opened vhost net devices\n"
     "                use 'queues=n' to specify the number of queues to be created for multiqueue TAP\n"
+    "                use 'vhostsock=file' vhost-user backend socket\n"
     "-net bridge[,vlan=n][,name=str][,br=bridge][,helper=helper]\n"
     "                connects a host TAP network interface to a host bridge device 'br'\n"
     "                (default=" DEFAULT_BRIDGE_INTERFACE ") using the program 'helper'\n"