From patchwork Mon Jun 4 05:29:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiyong Wu X-Patchwork-Id: 162640 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 B8449B6FA4 for ; Mon, 4 Jun 2012 16:07:54 +1000 (EST) Received: from localhost ([::1]:55759 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbPts-0008HV-Cf for incoming@patchwork.ozlabs.org; Mon, 04 Jun 2012 01:32:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbPtk-00087T-PW for qemu-devel@nongnu.org; Mon, 04 Jun 2012 01:32:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbPti-00019n-Sr for qemu-devel@nongnu.org; Mon, 04 Jun 2012 01:32:12 -0400 Received: from e32.co.us.ibm.com ([32.97.110.150]:43562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbPti-000197-Ga for qemu-devel@nongnu.org; Mon, 04 Jun 2012 01:32:10 -0400 Received: from /spool/local by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 3 Jun 2012 23:32:08 -0600 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 3 Jun 2012 23:32:07 -0600 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id B046519D8048 for ; Mon, 4 Jun 2012 05:31:35 +0000 (WET) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q545VAB6215062 for ; Sun, 3 Jun 2012 23:31:20 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q545UrFS021827 for ; Sun, 3 Jun 2012 23:30:54 -0600 Received: from us.ibm.com (f15.cn.ibm.com [9.115.118.120] (may be forged)) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id q545UnjQ021050; Sun, 3 Jun 2012 23:30:50 -0600 Received: by us.ibm.com (sSMTP sendmail emulation); Mon, 4 Jun 2012 13:30:47 +0800 From: zwu.kernel@gmail.com To: qemu-devel@nongnu.org Date: Mon, 4 Jun 2012 13:29:27 +0800 Message-Id: <1338787767-3443-17-git-send-email-zwu.kernel@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1338787767-3443-1-git-send-email-zwu.kernel@gmail.com> References: <1338787767-3443-1-git-send-email-zwu.kernel@gmail.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12060405-3270-0000-0000-000006E08B27 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.110.150 Cc: aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, jan.kiszka@siemens.com, Zhi Yong Wu , luowenj@cn.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v4 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-off-by: Paolo Bonzini Signed-off-by: Zhi Yong Wu --- net/hub.c | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-) diff --git a/net/hub.c b/net/hub.c index 230d86a..efd90b5 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(unsigned int id) @@ -85,6 +86,25 @@ static NetHub *net_hub_new(unsigned 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_TYPE_HUB, .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,