From patchwork Wed Oct 21 11:27:42 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 36531 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 B7E22B7B7C for ; Wed, 21 Oct 2009 23:29:04 +1100 (EST) Received: from localhost ([127.0.0.1]:43346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0aJJ-0001mC-CG for incoming@patchwork.ozlabs.org; Wed, 21 Oct 2009 08:29:01 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N0ZOB-0006jl-3j for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N0ZO3-0006em-OC for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:57 -0400 Received: from [199.232.76.173] (port=57330 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N0ZO2-0006e9-BF for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5448) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N0ZO1-0002xM-Mn for qemu-devel@nongnu.org; Wed, 21 Oct 2009 07:29:50 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTm2I009294 for ; Wed, 21 Oct 2009 07:29:49 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9LBTmdi023695; Wed, 21 Oct 2009 07:29:48 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id E62E5462C2; Wed, 21 Oct 2009 12:27:58 +0100 (IST) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 21 Oct 2009 12:27:42 +0100 Message-Id: <1256124478-2988-4-git-send-email-markmc@redhat.com> In-Reply-To: <1256124478-2988-1-git-send-email-markmc@redhat.com> References: <1256124478-2988-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 03/19] net: make tap_receive() re-use tap_receive_iov() code 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 In future we will want to prepend a virtio_net header if the NIC didn't supply one but IFF_VNET_HDR is enabled on the interface. This is most easily achived by using writev() in all cases. Signed-off-by: Mark McLoughlin --- net.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-) diff --git a/net.c b/net.c index 0e3388b..728941a 100644 --- a/net.c +++ b/net.c @@ -1291,10 +1291,8 @@ static void tap_writable(void *opaque) qemu_flush_queued_packets(s->vc); } -static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, - int iovcnt) +static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt) { - TAPState *s = vc->opaque; ssize_t len; do { @@ -1309,16 +1307,25 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, return len; } +static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov, + int iovcnt) +{ + TAPState *s = vc->opaque; + + return tap_write_packet(s, iov, iovcnt); +} + static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size) { TAPState *s = vc->opaque; - ssize_t len; + struct iovec iov[1]; + int iovcnt = 0; - do { - len = write(s->fd, buf, size); - } while (len == -1 && (errno == EINTR || errno == EAGAIN)); + iov[iovcnt].iov_base = (char *)buf; + iov[iovcnt].iov_len = size; + iovcnt++; - return len; + return tap_write_packet(s, iov, iovcnt); } static int tap_can_send(void *opaque)