From patchwork Tue Oct 27 18:16:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 37022 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 D9548B7BB7 for ; Wed, 28 Oct 2009 05:29:34 +1100 (EST) Received: from localhost ([127.0.0.1]:49628 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2qnT-0003GC-Rl for incoming@patchwork.ozlabs.org; Tue, 27 Oct 2009 14:29:31 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2qdK-0004Zr-TR for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:19:02 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2qdG-0004XN-BV for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:19:02 -0400 Received: from [199.232.76.173] (port=37365 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2qdG-0004XI-86 for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:18:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1027) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N2qdE-0000eh-PM for qemu-devel@nongnu.org; Tue, 27 Oct 2009 14:18:58 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9RIIa9Y000881; 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-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9RIIZso023514; Tue, 27 Oct 2009 14:18:35 -0400 Received: by blaa.localdomain (Postfix, from userid 500) id 8D559518B; Tue, 27 Oct 2009 18:16:39 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Tue, 27 Oct 2009 18:16:38 +0000 Message-Id: <1256667399-3149-5-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.12 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 4/5] virtio-net: split the has_buffers() logic from can_receive() 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 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 --- hw/virtio-net.c | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/virtio-net.c b/hw/virtio-net.c index 7ee393b..a30aff4 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))