From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2qey-0005Ry-Qt for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:20:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2qes-0005Q3-Bp for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:20:42 -0400 Received: from [199.232.76.173] (port=58205 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2qes-0005Q0-7b for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:20:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39785) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N2qeq-0000vD-P1 for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:20:38 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9RIKX6a023693 for ; Tue, 27 Oct 2009 14:20:33 -0400 From: Mark McLoughlin Date: Tue, 27 Oct 2009 18:18:37 +0000 Message-Id: <1256667517-4250-1-git-send-email-markmc@redhat.com> Subject: [Qemu-devel] [PATCH, stable-0.11] net: disable draining tap queue in one go List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Mark McLoughlin 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.c | 18 ++++++++---------- 1 files changed, 8 insertions(+), 10 deletions(-) diff --git a/net.c b/net.c index 3d3829d..7466961 100644 --- a/net.c +++ b/net.c @@ -1378,17 +1378,15 @@ static void tap_send(void *opaque) TAPState *s = opaque; int size; - do { - 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; + } - size = qemu_send_packet_async(s->vc, s->buf, size, tap_send_completed); - if (size == 0) { - tap_read_poll(s, 0); - } - } while (size > 0); + size = qemu_send_packet_async(s->vc, s->buf, size, tap_send_completed); + if (size == 0) { + tap_read_poll(s, 0); + } } #ifdef TUNSETSNDBUF -- 1.6.2.5