From patchwork Tue Jul 24 15:35:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 172930 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 67F202C0087 for ; Wed, 25 Jul 2012 02:36:21 +1000 (EST) Received: from localhost ([::1]:54406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SthAm-0004Tc-Vh for incoming@patchwork.ozlabs.org; Tue, 24 Jul 2012 11:37:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sth9E-0001Ta-Uo for qemu-devel@nongnu.org; Tue, 24 Jul 2012 11:35:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sth9A-0006UO-KD for qemu-devel@nongnu.org; Tue, 24 Jul 2012 11:35:44 -0400 Received: from e06smtp14.uk.ibm.com ([195.75.94.110]:49288) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sth9A-0006UH-Be for qemu-devel@nongnu.org; Tue, 24 Jul 2012 11:35:40 -0400 Received: from /spool/local by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 24 Jul 2012 16:35:39 +0100 Received: from d06nrmr1707.portsmouth.uk.ibm.com (9.149.39.225) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 24 Jul 2012 16:35:37 +0100 Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6OFZa1Q2981956 for ; Tue, 24 Jul 2012 16:35:36 +0100 Received: from d06av05.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6OFZaue028232 for ; Tue, 24 Jul 2012 09:35:36 -0600 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.145]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6OFZac7028229; Tue, 24 Jul 2012 09:35:36 -0600 From: Stefan Hajnoczi To: Date: Tue, 24 Jul 2012 16:35:19 +0100 Message-Id: <1343144119-18757-17-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343144119-18757-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1343144119-18757-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12072415-1948-0000-0000-0000027C2AD8 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.110 Cc: Paolo Bonzini , Zhi Yong Wu , Laszlo Ersek , Stefan Hajnoczi , Zhi Yong Wu Subject: [Qemu-devel] [PATCH v2 16/16] hub: add the support for hub own flow control 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: Zhi Yong Wu Only when all other hub port's *peer* .can_receive() all return 1, the source hub port .can_receive() return 1. Reviewed-by: Paolo Bonzini Signed-off-by: Zhi Yong Wu Signed-off-by: Stefan Hajnoczi --- net/hub.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/net/hub.c b/net/hub.c index 522fe99..ac157e3 100644 --- a/net/hub.c +++ b/net/hub.c @@ -15,6 +15,7 @@ #include "monitor.h" #include "net.h" #include "hub.h" +#include "iov.h" /* * A hub broadcasts incoming packets to all its ports except the source port. @@ -59,16 +60,16 @@ static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port, const struct iovec *iov, int iovcnt) { NetHubPort *port; - ssize_t ret = 0; + ssize_t len = iov_size(iov, iovcnt); QLIST_FOREACH(port, &hub->ports, next) { if (port == source_port) { continue; } - ret = qemu_sendv_packet(&port->nc, iov, iovcnt); + qemu_sendv_packet(&port->nc, iov, iovcnt); } - return ret; + return len; } static NetHub *net_hub_new(int id) @@ -85,6 +86,25 @@ static NetHub *net_hub_new(int id) return hub; } +static int net_hub_port_can_receive(NetClientState *nc) +{ + NetHubPort *port; + NetHubPort *src_port = DO_UPCAST(NetHubPort, nc, nc); + NetHub *hub = src_port->hub; + + QLIST_FOREACH(port, &hub->ports, next) { + if (port == src_port) { + continue; + } + + if (!qemu_can_send_packet(&port->nc)) { + return 0; + } + } + + return 1; +} + static ssize_t net_hub_port_receive(NetClientState *nc, const uint8_t *buf, size_t len) { @@ -111,6 +131,7 @@ static void net_hub_port_cleanup(NetClientState *nc) static NetClientInfo net_hub_port_info = { .type = NET_CLIENT_OPTIONS_KIND_HUBPORT, .size = sizeof(NetHubPort), + .can_receive = net_hub_port_can_receive, .receive = net_hub_port_receive, .receive_iov = net_hub_port_receive_iov, .cleanup = net_hub_port_cleanup,