From patchwork Tue Feb 5 14:46:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luigi Rizzo X-Patchwork-Id: 218266 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 E90212C02CB for ; Wed, 6 Feb 2013 01:46:36 +1100 (EST) Received: from localhost ([::1]:52628 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2jn8-0004dh-IM for incoming@patchwork.ozlabs.org; Tue, 05 Feb 2013 09:46:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:45599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2jn1-0004dG-9r for qemu-devel@nongnu.org; Tue, 05 Feb 2013 09:46:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U2jmz-0003oy-PF for qemu-devel@nongnu.org; Tue, 05 Feb 2013 09:46:27 -0500 Received: from onelab2.iet.unipi.it ([131.114.59.238]:64919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2jmz-0003oU-IS for qemu-devel@nongnu.org; Tue, 05 Feb 2013 09:46:25 -0500 Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 8592173027; Tue, 5 Feb 2013 15:46:19 +0100 (CET) Date: Tue, 5 Feb 2013 15:46:19 +0100 From: Luigi Rizzo To: qemu-devel@nongnu.org Message-ID: <20130205144619.GA29583@onelab2.iet.unipi.it> References: <20130121025050.GA20214@onelab2.iet.unipi.it> <20130122065420.GA37378@onelab2.iet.unipi.it> <20130129130827.GB17199@stefanha-thinkpad.redhat.com> Mime-Version: 1.0 Content-Disposition: inline In-Reply-To: <20130129130827.GB17199@stefanha-thinkpad.redhat.com> User-Agent: Mutt/1.4.2.3i X-detected-operating-system: by eggs.gnu.org: Mac OS X 10.x X-Received-From: 131.114.59.238 Subject: [Qemu-devel] [PATCH v2] 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 On Tue, Jan 29, 2013 at 02:08:27PM +0100, Stefan Hajnoczi wrote: > It's cleaner to add a bool (*flush)(NetClientState *nc) function to > NetClientInfo but given that net.c already knows about hub.c > specifically we don't gain much by trying to decouple this callback. If > you want to leave it hardcoded that's fine by me. I'd leave it like this for now. Here is the version with fixed style bugs. ---------------------------------------- DESCRIPTION: 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. cheers luigi Signed-off-by: Luigi Rizzo 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 9806862..9489702 100644 --- a/net/net.c +++ b/net/net.c @@ -439,6 +439,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).