From patchwork Thu Sep 5 07:49:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Tianhong X-Patchwork-Id: 272807 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id CAB5A2C00E1 for ; Thu, 5 Sep 2013 17:49:39 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763446Ab3IEHtg (ORCPT ); Thu, 5 Sep 2013 03:49:36 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:51841 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762687Ab3IEHtf (ORCPT ); Thu, 5 Sep 2013 03:49:35 -0400 Received: from 172.24.2.119 (EHLO szxeml212-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BHC38919; Thu, 05 Sep 2013 15:49:13 +0800 (CST) Received: from SZXEML456-HUB.china.huawei.com (10.82.67.199) by szxeml212-edg.china.huawei.com (172.24.2.181) with Microsoft SMTP Server (TLS) id 14.1.323.7; Thu, 5 Sep 2013 15:49:11 +0800 Received: from [127.0.0.1] (10.135.72.199) by szxeml456-hub.china.huawei.com (10.82.67.199) with Microsoft SMTP Server id 14.1.323.7; Thu, 5 Sep 2013 15:49:03 +0800 Message-ID: <5228376D.2040608@huawei.com> Date: Thu, 5 Sep 2013 15:49:01 +0800 From: Ding Tianhong User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Jay Vosburgh , Andy Gospodarek , "David S. Miller" , Nikolay Aleksandrov , Veaceslav Falico , Netdev Subject: [PATCH net-next v3 5/6] bonding: restructure and add rcu for bond_for_each_slave_next() X-Originating-IP: [10.135.72.199] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Remove the wordy int and add bond_for_each_slave_next_rcu() for future use. Suggested-by: Nikolay Aleksandrov Suggested-by: Veaceslav Falico Signed-off-by: Ding Tianhong Cc: Nikolay Aleksandrov Cc: Veaceslav Falico --- drivers/net/bonding/bond_alb.c | 3 +-- drivers/net/bonding/bond_main.c | 6 ++---- drivers/net/bonding/bonding.h | 23 +++++++++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index 91f179d..c75d383 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c @@ -383,7 +383,6 @@ static struct slave *rlb_next_rx_slave(struct bonding *bond) { struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); struct slave *rx_slave, *slave, *start_at; - int i = 0; if (bond_info->next_rx_slave) start_at = bond_info->next_rx_slave; @@ -392,7 +391,7 @@ static struct slave *rlb_next_rx_slave(struct bonding *bond) rx_slave = NULL; - bond_for_each_slave_from(bond, slave, i, start_at) { + bond_for_each_slave_from(bond, slave, start_at) { if (SLAVE_IS_OK(slave)) { if (!rx_slave) { rx_slave = slave; diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 39e5b1c..4190389 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -782,7 +782,6 @@ static struct slave *bond_find_best_slave(struct bonding *bond) struct slave *new_active, *old_active; struct slave *bestslave = NULL; int mintime = bond->params.updelay; - int i; new_active = bond->curr_active_slave; @@ -801,7 +800,7 @@ static struct slave *bond_find_best_slave(struct bonding *bond) /* remember where to stop iterating over the slaves */ old_active = new_active; - bond_for_each_slave_from(bond, new_active, i, old_active) { + bond_for_each_slave_from(bond, new_active, old_active) { if (new_active->link == BOND_LINK_UP) { return new_active; } else if (new_active->link == BOND_LINK_BACK && @@ -2756,7 +2755,6 @@ do_failover: static void bond_ab_arp_probe(struct bonding *bond) { struct slave *slave, *next_slave; - int i; read_lock(&bond->curr_slave_lock); @@ -2788,7 +2786,7 @@ static void bond_ab_arp_probe(struct bonding *bond) /* search for next candidate */ next_slave = bond_next_slave(bond, bond->current_arp_slave); - bond_for_each_slave_from(bond, slave, i, next_slave) { + bond_for_each_slave_from(bond, slave, next_slave) { if (IS_UP(slave->dev)) { slave->link = BOND_LINK_BACK; bond_set_slave_active_flags(slave); diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index f013b12..48fd41a 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h @@ -123,18 +123,33 @@ (bond_is_first_slave(bond, pos) ? bond_last_slave_rcu(bond) : \ bond_to_slave_rcu((pos)->list.prev)) +/* Check whether the slave is the only one in bond */ + /** * bond_for_each_slave_from - iterate the slaves list from a starting point * @bond: the bond holding this list. * @pos: current slave. - * @cnt: counter for max number of moves * @start: starting point. * * Caller must hold bond->lock */ -#define bond_for_each_slave_from(bond, pos, cnt, start) \ - for (cnt = 0, pos = start; pos && cnt < (bond)->slave_cnt; \ - cnt++, pos = bond_next_slave(bond, pos)) +#define bond_for_each_slave_from(bond, pos, start) \ + for (pos = start; pos && &pos->list != &bond->slave_list; \ + (pos = bond_next_slave(bond, pos)) != start ? pos : \ + (pos = list_entry(&bond->slave_list, typeof(*pos), list))) + +/** + * bond_for_each_slave_from_rcu - iterate the slaves list from a starting point + * @bond: the bond holding this list. + * @pos: current slave. + * @start: starting point. + * + * Caller must hold rcu_read_lock + */ +#define bond_for_each_slave_from_rcu(bond, pos, start) \ + for (pos = start; pos && &pos->list != &bond->slave_list; \ + (pos = bond_next_slave_rcu(bond, pos)) != start ? pos : \ + (pos = list_entry_rcu(&bond->slave_list, typeof(*pos), list))) /** * bond_for_each_slave - iterate over all slaves