aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio-net.c
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2009-10-27 18:16:38 +0000
committerAnthony Liguori <aliguori@us.ibm.com>2009-11-09 08:43:02 -0600
commitcdd5cc12ba8cf0c068da319370bdd3ba45eaf7ac (patch)
tree6f1b669c8dcc886571eb1130f1a75f345300da5d /hw/virtio-net.c
parent839f368f2b3e4405c9847bf763bdaf3bc26f714d (diff)
virtio-net: split the has_buffers() logic from can_receive()
We should only return zero from receive() for a condition which we'll get notification of when it changes. Currently, we're returning zero if the guest driver is not ready, but we won't ever flush our queue when that status changes. Also, don't check buffer space in can_receive(), but instead just allow receive() to return zero when this condition occurs and have the caller handle queueing the packet. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio-net.c')
-rw-r--r--hw/virtio-net.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 4bc111422a..4b09a930ef 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -367,12 +367,19 @@ static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
qemu_notify_event();
}
-static int do_virtio_net_can_receive(VirtIONet *n, int bufsize)
+static int virtio_net_can_receive(VLANClientState *vc)
{
+ VirtIONet *n = vc->opaque;
+
if (!virtio_queue_ready(n->rx_vq) ||
!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
return 0;
+ return 1;
+}
+
+static int virtio_net_has_buffers(VirtIONet *n, int bufsize)
+{
if (virtio_queue_empty(n->rx_vq) ||
(n->mergeable_rx_bufs &&
!virtqueue_avail_bytes(n->rx_vq, bufsize, 0))) {
@@ -384,13 +391,6 @@ static int do_virtio_net_can_receive(VirtIONet *n, int bufsize)
return 1;
}
-static int virtio_net_can_receive(VLANClientState *vc)
-{
- VirtIONet *n = vc->opaque;
-
- return do_virtio_net_can_receive(n, VIRTIO_NET_MAX_BUFSIZE);
-}
-
/* dhclient uses AF_PACKET but doesn't pass auxdata to the kernel so
* it never finds out that the packets don't have valid checksums. This
* causes dhclient to get upset. Fedora's carried a patch for ages to
@@ -517,7 +517,10 @@ static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_
struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
size_t hdr_len, offset, i;
- if (!do_virtio_net_can_receive(n, size))
+ if (!virtio_net_can_receive(n->vc))
+ return -1;
+
+ if (!virtio_net_has_buffers(n, size))
return 0;
if (!receive_filter(n, buf, size))