From patchwork Wed Feb 27 15:22:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 223633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DFCF92C007A for ; Thu, 28 Feb 2013 02:24:26 +1100 (EST) Received: from localhost ([::1]:35159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAiro-0006es-Ev for incoming@patchwork.ozlabs.org; Wed, 27 Feb 2013 10:24:24 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAiq6-00041D-Ak for qemu-devel@nongnu.org; Wed, 27 Feb 2013 10:22:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAiq3-0007j8-47 for qemu-devel@nongnu.org; Wed, 27 Feb 2013 10:22:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26224) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAiq2-0007j2-R0 for qemu-devel@nongnu.org; Wed, 27 Feb 2013 10:22:35 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1RFMVg5015670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 27 Feb 2013 10:22:31 -0500 Received: from localhost (ovpn-112-39.ams2.redhat.com [10.36.112.39]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1RFMTdn026248; Wed, 27 Feb 2013 10:22:29 -0500 From: Stefan Hajnoczi To: Date: Wed, 27 Feb 2013 16:22:19 +0100 Message-Id: <1361978545-13789-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1361978545-13789-1-git-send-email-stefanha@redhat.com> References: <1361978545-13789-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Luigi Rizzo , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 1/7] net: fix qemu_flush_queued_packets() in presence of a hub X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Luigi Rizzo When frontend and backend are connected through a hub as below (showing only one direction), and the frontend (or in general, all output ports of the hub) cannot accept more traffic, the backend queues packets in queue-A. When the frontend (or in general, one output port) becomes ready again, quemu tries to flush packets from queue-B, which is unfortunately empty. e1000.0 <--[queue B]-- hub0port0(hub)hub0port1 <--[queue A]-- tap.0 To fix this i propose to introduce a new function net_hub_flush() which is called when trying to flush a queue connected to a hub. Signed-off-by: Luigi Rizzo Signed-off-by: Stefan Hajnoczi --- net/hub.c | 14 ++++++++++++++ net/hub.h | 1 + net/net.c | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/net/hub.c b/net/hub.c index a24c9d1..df32074 100644 --- a/net/hub.c +++ b/net/hub.c @@ -338,3 +338,17 @@ void net_hub_check_clients(void) } } } + +bool net_hub_flush(NetClientState *nc) +{ + NetHubPort *port; + NetHubPort *source_port = DO_UPCAST(NetHubPort, nc, nc); + int ret = 0; + + QLIST_FOREACH(port, &source_port->hub->ports, next) { + if (port != source_port) { + ret += qemu_net_queue_flush(port->nc.send_queue); + } + } + return ret ? true : false; +} diff --git a/net/hub.h b/net/hub.h index 583ada8..a625eff 100644 --- a/net/hub.h +++ b/net/hub.h @@ -21,5 +21,6 @@ NetClientState *net_hub_add_port(int hub_id, const char *name); NetClientState *net_hub_find_client_by_name(int hub_id, const char *name); void net_hub_info(Monitor *mon); void net_hub_check_clients(void); +bool net_hub_flush(NetClientState *nc); #endif /* NET_HUB_H */ diff --git a/net/net.c b/net/net.c index be03a8d..a66aa02 100644 --- a/net/net.c +++ b/net/net.c @@ -441,6 +441,12 @@ void qemu_flush_queued_packets(NetClientState *nc) { nc->receive_disabled = 0; + if (nc->peer && nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT) { + if (net_hub_flush(nc->peer)) { + qemu_notify_event(); + } + return; + } if (qemu_net_queue_flush(nc->send_queue)) { /* We emptied the queue successfully, signal to the IO thread to repoll * the file descriptor (for tap, for example).