aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2009-10-27 18:16:35 +0000
committerAnthony Liguori <aliguori@us.ibm.com>2009-11-09 08:43:02 -0600
commitbe1636b3ab36b3decdd0eb35b3b09a998060104f (patch)
tree3aee9c328047e1874d8694e0ff7c25338cd4a3f3 /net
parenteb852011ab3c56bd1f8e9d2c7d0dfb3eb321430a (diff)
tap: disable draining queue in one go
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 <scottt.tw@gmail.com> Tested-by: Sven Rudolph <Sven_Rudolph@drewag.de> Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net')
-rw-r--r--net/tap.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/net/tap.c b/net/tap.c
index bdb4a15c2..8cdb79346 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -188,26 +188,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)