From patchwork Thu Feb 4 12:47:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 44480 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AFEFEB7D47 for ; Fri, 5 Feb 2010 00:16:42 +1100 (EST) Received: from localhost ([127.0.0.1]:49188 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nd1Ts-0002Nh-Vp for incoming@patchwork.ozlabs.org; Thu, 04 Feb 2010 08:10:49 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nd1AP-0004LH-4f for qemu-devel@nongnu.org; Thu, 04 Feb 2010 07:50:41 -0500 Received: from [199.232.76.173] (port=55486 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nd1AO-0004L1-N2 for qemu-devel@nongnu.org; Thu, 04 Feb 2010 07:50:40 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nd1AM-00086P-So for qemu-devel@nongnu.org; Thu, 04 Feb 2010 07:50:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42551) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nd1AL-000869-Dx for qemu-devel@nongnu.org; Thu, 04 Feb 2010 07:50:38 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o14CoXfg000430 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 4 Feb 2010 07:50:33 -0500 Received: from redhat.com (vpn2-9-138.ams2.redhat.com [10.36.9.138]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o14CoVra004437; Thu, 4 Feb 2010 07:50:32 -0500 Date: Thu, 4 Feb 2010 14:47:22 +0200 From: "Michael S. Tsirkin" To: Anthony Liguori , qemu-devel@nongnu.org Message-ID: <20100204124722.GN22559@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 13/15] tap: add vhost/vhostfd options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Michael S. Tsirkin --- net.c | 8 ++++++++ net/tap.c | 29 +++++++++++++++++++++++++++++ qemu-options.hx | 4 +++- 3 files changed, 40 insertions(+), 1 deletions(-) diff --git a/net.c b/net.c index 6ef93e6..b942d03 100644 --- a/net.c +++ b/net.c @@ -976,6 +976,14 @@ static struct { .name = "vnet_hdr", .type = QEMU_OPT_BOOL, .help = "enable the IFF_VNET_HDR flag on the tap interface" + }, { + .name = "vhost", + .type = QEMU_OPT_BOOL, + .help = "enable vhost-net network accelerator", + }, { + .name = "vhostfd", + .type = QEMU_OPT_STRING, + .help = "file descriptor of an already opened vhost net device", }, #endif /* _WIN32 */ { /* end of list */ } diff --git a/net/tap.c b/net/tap.c index 7e9ca79..d9f2e41 100644 --- a/net/tap.c +++ b/net/tap.c @@ -41,6 +41,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 */ @@ -57,6 +59,7 @@ typedef struct TAPState { unsigned int has_vnet_hdr : 1; unsigned int using_vnet_hdr : 1; unsigned int has_ufo: 1; + struct vhost_net *vhost_net; } TAPState; static int launch_script(const char *setup_script, const char *ifname, int fd); @@ -252,6 +255,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]) @@ -307,6 +314,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; } @@ -456,6 +464,27 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan } } + if (qemu_opt_get_bool(opts, "vhost", 0)) { + 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) { + qemu_error("vhost-net requested but could not be initialized\n"); + return -1; + } + } else if (qemu_opt_get(opts, "vhostfd")) { + qemu_error("vhostfd= is not valid without vhost\n"); + return -1; + } + if (vlan) { vlan->nb_host_devs++; } diff --git a/qemu-options.hx b/qemu-options.hx index 5c9f482..c2b25c5 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -831,7 +831,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][,ifname=name][,script=file][,downscript=dfile][,sndbuf=nbytes][,vnet_hdr=on|off]\n" + "-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" " connect the host TAP network interface to VLAN 'n' and use the\n" " network scripts 'file' (default=%s)\n" " and 'dfile' (default=%s)\n" @@ -841,6 +841,8 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, " default of 'sndbuf=1048576' can be disabled using 'sndbuf=0')\n" " use vnet_hdr=off to avoid enabling the IFF_VNET_HDR tap flag\n" " use vnet_hdr=on to make the lack of IFF_VNET_HDR support an error condition\n" + " use vhost=on to enable experimental in kernel accelerator\n" + " use 'vhostfd=h' to connect to an already opened vhost net device\n" #endif "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n" " connect the vlan 'n' to another VLAN using a socket connection\n"