aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2010-03-17 13:08:24 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2010-04-01 13:56:43 -0500
commit82b0d80ef6a37b46bac1311c31935dc130a5a703 (patch)
treeca955498bd7a81e437608f83907572a8ef9f98f1 /net
parentd59700553ecbf052cce1e099e8f4dae2704fe424 (diff)
tap: add vhost/vhostfd options
This adds vhost binary option to tap, to enable vhost net accelerator. Default is off for now, we'll be able to make default on long term when we know it's stable. vhostfd option can be used by management, to pass in the fd. Assigning vhostfd implies vhost=on. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net')
-rw-r--r--net/tap.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/net/tap.c b/net/tap.c
index c19740b584..740665f5b6 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -42,6 +42,8 @@
#include "net/tap-linux.h"
+#include "hw/vhost_net.h"
+
/* Maximum GSO packet size (64k) plus plenty of room for
* the ethernet and virtio_net headers
*/
@@ -58,6 +60,7 @@ typedef struct TAPState {
unsigned int has_vnet_hdr : 1;
unsigned int using_vnet_hdr : 1;
unsigned int has_ufo: 1;
+ VHostNetState *vhost_net;
} TAPState;
static int launch_script(const char *setup_script, const char *ifname, int fd);
@@ -253,6 +256,10 @@ static void tap_cleanup(VLANClientState *nc)
{
TAPState *s = DO_UPCAST(TAPState, nc, nc);
+ if (s->vhost_net) {
+ vhost_net_cleanup(s->vhost_net);
+ }
+
qemu_purge_queued_packets(nc);
if (s->down_script[0])
@@ -308,6 +315,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
s->has_ufo = tap_probe_has_ufo(s->fd);
tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
tap_read_poll(s, 1);
+ s->vhost_net = NULL;
return s;
}
@@ -457,5 +465,26 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
}
}
+ if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd"))) {
+ int vhostfd, r;
+ if (qemu_opt_get(opts, "vhostfd")) {
+ r = net_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd"));
+ if (r == -1) {
+ return -1;
+ }
+ vhostfd = r;
+ } else {
+ vhostfd = -1;
+ }
+ s->vhost_net = vhost_net_init(&s->nc, vhostfd);
+ if (!s->vhost_net) {
+ error_report("vhost-net requested but could not be initialized");
+ return -1;
+ }
+ } else if (qemu_opt_get(opts, "vhostfd")) {
+ error_report("vhostfd= is not valid without vhost");
+ return -1;
+ }
+
return 0;
}