From patchwork Tue Oct 27 18:16:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 37019 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 85698B7BA0 for ; Wed, 28 Oct 2009 05:21:16 +1100 (EST) Received: from localhost ([127.0.0.1]:43429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2qfO-0005Q8-5P for incoming@patchwork.ozlabs.org; Tue, 27 Oct 2009 14:21:10 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2qdH-0004YB-Pv for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:18:59 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2qdC-0004Vf-NS for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:18:59 -0400 Received: from [199.232.76.173] (port=37358 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2qdC-0004VW-Fk for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:18:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51267) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N2qdA-0000eZ-Ng for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:18:54 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9RIIapE023380; Tue, 27 Oct 2009 14:18:36 -0400 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9RIIZU3009015; Tue, 27 Oct 2009 14:18:35 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 8A63ABE09; Tue, 27 Oct 2009 18:16:39 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Tue, 27 Oct 2009 18:16:35 +0000 Message-Id: <1256667399-3149-2-git-send-email-markmc@redhat.com> In-Reply-To: <1256667399-3149-1-git-send-email-markmc@redhat.com> References: <1256667399-3149-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Sven Rudolph , Scott Tsai , Mark McLoughlin Subject: [Qemu-devel] [PATCH 1/5] tap: disable draining queue in one go 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 If qemu_send_packet_async() returns zero, it means the packet has been queued and the sent callback will be invoked once it has been flushed. This is only possible where the NIC's receive() handler returns zero and promises to notify the networking core that room is available in its queue again. In the case where the receive handler does not have this capability (and its queue fills up) it returns -1 and the networking core does not queue up the packet. This condition is indicated by a -1 return from qemu_send_packet_async(). Currently, tap handles this condition simply by dropping the packet. It should do its best to avoid getting into this situation by checking such NIC's have room for a packet before copying the packet from the tap interface. tap_send() used to achieve this by only reading a single packet before returning to the mainloop. That way, tap_can_send() is called before reading each packet. tap_send() was changed to completely drain the tap interface queue without taking into account the situation where the NIC returns an error and the packet is not queued. Let's start fixing this by reverting to the previous behaviour of reading one packet at a time. Reported-by: Scott Tsai Tested-by: Sven Rudolph Signed-off-by: Mark McLoughlin --- net/tap.c | 33 +++++++++++++++------------------ 1 files changed, 15 insertions(+), 18 deletions(-) diff --git a/net/tap.c b/net/tap.c index 60354e4..f32226b 100644 --- a/net/tap.c +++ b/net/tap.c @@ -187,26 +187,23 @@ static void tap_send_completed(VLANClientState *vc, ssize_t len) static void tap_send(void *opaque) { TAPState *s = opaque; + uint8_t *buf = s->buf; int size; - do { - uint8_t *buf = s->buf; - - size = tap_read_packet(s->fd, s->buf, sizeof(s->buf)); - if (size <= 0) { - break; - } + size = tap_read_packet(s->fd, s->buf, sizeof(s->buf)); + if (size <= 0) { + return; + } - if (s->has_vnet_hdr && !s->using_vnet_hdr) { - buf += sizeof(struct virtio_net_hdr); - size -= sizeof(struct virtio_net_hdr); - } + if (s->has_vnet_hdr && !s->using_vnet_hdr) { + buf += sizeof(struct virtio_net_hdr); + size -= sizeof(struct virtio_net_hdr); + } - size = qemu_send_packet_async(s->vc, buf, size, tap_send_completed); - if (size == 0) { - tap_read_poll(s, 0); - } - } while (size > 0); + size = qemu_send_packet_async(s->vc, buf, size, tap_send_completed); + if (size == 0) { + tap_read_poll(s, 0); + } } int tap_has_ufo(VLANClientState *vc)