peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame qemu-tap-add-vhost-vhostfd-options.patch

Justin M. Forbes 272dfe
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Justin M. Forbes 272dfe
---
Justin M. Forbes 272dfe
 net.c           |    8 ++++++++
Justin M. Forbes 272dfe
 net/tap.c       |   29 +++++++++++++++++++++++++++++
Justin M. Forbes 272dfe
 qemu-options.hx |    4 +++-
Justin M. Forbes 272dfe
 3 files changed, 40 insertions(+), 1 deletions(-)
Justin M. Forbes 272dfe
Justin M. Forbes 272dfe
diff --git a/net.c b/net.c
Justin M. Forbes 272dfe
index 6ef93e6..b942d03 100644
Justin M. Forbes 272dfe
--- a/net.c
Justin M. Forbes 272dfe
+++ b/net.c
Justin M. Forbes 272dfe
@@ -976,6 +976,14 @@ static struct {
Justin M. Forbes 272dfe
                 .name = "vnet_hdr",
Justin M. Forbes 272dfe
                 .type = QEMU_OPT_BOOL,
Justin M. Forbes 272dfe
                 .help = "enable the IFF_VNET_HDR flag on the tap interface"
Justin M. Forbes 272dfe
+            }, {
Justin M. Forbes 272dfe
+                .name = "vhost",
Justin M. Forbes 272dfe
+                .type = QEMU_OPT_BOOL,
Justin M. Forbes 272dfe
+                .help = "enable vhost-net network accelerator",
Justin M. Forbes 272dfe
+            }, {
Justin M. Forbes 272dfe
+                .name = "vhostfd",
Justin M. Forbes 272dfe
+                .type = QEMU_OPT_STRING,
Justin M. Forbes 272dfe
+                .help = "file descriptor of an already opened vhost net device",
Justin M. Forbes 272dfe
             },
Justin M. Forbes 272dfe
 #endif /* _WIN32 */
Justin M. Forbes 272dfe
             { /* end of list */ }
Justin M. Forbes 272dfe
diff --git a/net/tap.c b/net/tap.c
Justin M. Forbes 272dfe
index 7e9ca79..d9f2e41 100644
Justin M. Forbes 272dfe
--- a/net/tap.c
Justin M. Forbes 272dfe
+++ b/net/tap.c
Justin M. Forbes 272dfe
@@ -41,6 +41,8 @@
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
 #include "net/tap-linux.h"
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
+#include "hw/vhost_net.h"
Justin M. Forbes 272dfe
+
Justin M. Forbes 272dfe
 /* Maximum GSO packet size (64k) plus plenty of room for
Justin M. Forbes 272dfe
  * the ethernet and virtio_net headers
Justin M. Forbes 272dfe
  */
Justin M. Forbes 272dfe
@@ -57,6 +59,7 @@ typedef struct TAPState {
Justin M. Forbes 272dfe
     unsigned int has_vnet_hdr : 1;
Justin M. Forbes 272dfe
     unsigned int using_vnet_hdr : 1;
Justin M. Forbes 272dfe
     unsigned int has_ufo: 1;
Justin M. Forbes 272dfe
+    struct vhost_net *vhost_net;
Justin M. Forbes 272dfe
 } TAPState;
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
 static int launch_script(const char *setup_script, const char *ifname, int fd);
Justin M. Forbes 272dfe
@@ -252,6 +255,10 @@ static void tap_cleanup(VLANClientState *nc)
Justin M. Forbes 272dfe
 {
Justin M. Forbes 272dfe
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
+    if (s->vhost_net) {
Justin M. Forbes 272dfe
+        vhost_net_cleanup(s->vhost_net);
Justin M. Forbes 272dfe
+    }
Justin M. Forbes 272dfe
+
Justin M. Forbes 272dfe
     qemu_purge_queued_packets(nc);
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
     if (s->down_script[0])
Justin M. Forbes 272dfe
@@ -307,6 +314,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
Justin M. Forbes 272dfe
     s->has_ufo = tap_probe_has_ufo(s->fd);
Justin M. Forbes 272dfe
     tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
Justin M. Forbes 272dfe
     tap_read_poll(s, 1);
Justin M. Forbes 272dfe
+    s->vhost_net = NULL;
Justin M. Forbes 272dfe
     return s;
Justin M. Forbes 272dfe
 }
Justin M. Forbes 272dfe
 
Justin M. Forbes eff942
@@ -456,5 +464,26 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
Justin M. Forbes 272dfe
         }
Justin M. Forbes 272dfe
     }
Justin M. Forbes 272dfe
 
Justin M. Forbes 272dfe
+    if (qemu_opt_get_bool(opts, "vhost", 0)) {
Justin M. Forbes 272dfe
+        int vhostfd, r;
Justin M. Forbes 272dfe
+        if (qemu_opt_get(opts, "vhostfd")) {
Justin M. Forbes 272dfe
+            r = net_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd"));
Justin M. Forbes 272dfe
+            if (r == -1) {
Justin M. Forbes 272dfe
+                return -1;
Justin M. Forbes 272dfe
+            }
Justin M. Forbes 272dfe
+            vhostfd = r;
Justin M. Forbes 272dfe
+        } else {
Justin M. Forbes 272dfe
+            vhostfd = -1;
Justin M. Forbes 272dfe
+        }
Justin M. Forbes 272dfe
+        s->vhost_net = vhost_net_init(&s->nc, vhostfd);
Justin M. Forbes 272dfe
+        if (!s->vhost_net) {
Justin M. Forbes 272dfe
+            qemu_error("vhost-net requested but could not be initialized\n");
Justin M. Forbes 272dfe
+            return -1;
Justin M. Forbes 272dfe
+        }
Justin M. Forbes 272dfe
+    } else if (qemu_opt_get(opts, "vhostfd")) {
Justin M. Forbes 272dfe
+        qemu_error("vhostfd= is not valid without vhost\n");
Justin M. Forbes 272dfe
+        return -1;
Justin M. Forbes 272dfe
+    }
Justin M. Forbes 272dfe
+
Justin M. Forbes eff942
     return 0;
Justin M. Forbes eff942
 }
Justin M. Forbes 272dfe
diff --git a/qemu-options.hx b/qemu-options.hx
Justin M. Forbes 272dfe
index ca73ba5..2b3d9b8 100644
Justin M. Forbes 272dfe
--- a/qemu-options.hx
Justin M. Forbes 272dfe
+++ b/qemu-options.hx
Justin M. Forbes 272dfe
@@ -814,7 +814,7 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
Justin M. Forbes 272dfe
     "-net tap[,vlan=n][,name=str],ifname=name\n"
Justin M. Forbes 272dfe
     "                connect the host TAP network interface to VLAN 'n'\n"
Justin M. Forbes 272dfe
 #else
Justin M. Forbes 272dfe
-    "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile][,sndbuf=nbytes][,vnet_hdr=on|off]\n"
Justin M. Forbes 272dfe
+    "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h]\n"
Justin M. Forbes 272dfe
     "                connect the host TAP network interface to VLAN 'n' and use the\n"
Justin M. Forbes 272dfe
     "                network scripts 'file' (default=%s)\n"
Justin M. Forbes 272dfe
     "                and 'dfile' (default=%s);\n"
Justin M. Forbes 272dfe
@@ -824,6 +824,8 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
Justin M. Forbes 272dfe
     "                default of 'sndbuf=1048576' can be disabled using 'sndbuf=0'\n"
Justin M. Forbes 272dfe
     "                use vnet_hdr=off to avoid enabling the IFF_VNET_HDR tap flag; use\n"
Justin M. Forbes 272dfe
     "                vnet_hdr=on to make the lack of IFF_VNET_HDR support an error condition\n"
Justin M. Forbes 272dfe
+    "                use vhost=on to enable experimental in kernel accelerator\n"
Justin M. Forbes 272dfe
+    "                use 'vhostfd=h' to connect to an already opened vhost net device\n"
Justin M. Forbes 272dfe
 #endif
Justin M. Forbes 272dfe
     "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
Justin M. Forbes 272dfe
     "                connect the vlan 'n' to another VLAN using a socket connection\n"
Justin M. Forbes 272dfe
-- 
Justin M. Forbes 272dfe
1.6.6.144.g5c3af