aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorVeaceslav Falico <vfalico@redhat.com>2013-09-25 03:20:18 -0400
committerDavid S. Miller <davem@davemloft.net>2013-09-26 16:02:05 -0400
commit77140d2951432487d012dbcdcf124168eafc49ca (patch)
tree83ace6a8c59e8ff3ebf0b3d5906f215c284401cc /drivers/net
parent6475ae4ceea2f430db1daabf6460a9f36bc97438 (diff)
bonding: rework bond_find_best_slave() to use bond_for_each_slave()
bond_find_best_slave() does not have to be balanced - i.e. return the slave that is *after* some other slave, but rather return the best slave that suits, except of bond->primary_slave - in which case we just return it if it's suitable. After that we just look through all the slaves and return either first up slave or the slave whose link came back earliest. We also don't care about curr_active_slave lock cause we use it in bond_should_change_active() only and there we take it right away - i.e. it won't go away. CC: Jay Vosburgh <fubar@us.ibm.com> CC: Andy Gospodarek <andy@greyhouse.net> Signed-off-by: Veaceslav Falico <vfalico@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/bonding/bond_main.c43
1 files changed, 12 insertions, 31 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 85e99aedabb1..6abbfaca0b93 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -785,43 +785,24 @@ static bool bond_should_change_active(struct bonding *bond)
785/** 785/**
786 * find_best_interface - select the best available slave to be the active one 786 * find_best_interface - select the best available slave to be the active one
787 * @bond: our bonding struct 787 * @bond: our bonding struct
788 *
789 * Warning: Caller must hold curr_slave_lock for writing.
790 */ 788 */
791static struct slave *bond_find_best_slave(struct bonding *bond) 789static struct slave *bond_find_best_slave(struct bonding *bond)
792{ 790{
793 struct slave *new_active, *old_active; 791 struct slave *slave, *bestslave = NULL;
794 struct slave *bestslave = NULL; 792 struct list_head *iter;
795 int mintime = bond->params.updelay; 793 int mintime = bond->params.updelay;
796 int i;
797 794
798 new_active = bond->curr_active_slave; 795 if (bond->primary_slave && bond->primary_slave->link == BOND_LINK_UP &&
799 796 bond_should_change_active(bond))
800 if (!new_active) { /* there were no active slaves left */ 797 return bond->primary_slave;
801 new_active = bond_first_slave(bond);
802 if (!new_active)
803 return NULL; /* still no slave, return NULL */
804 }
805 798
806 if ((bond->primary_slave) && 799 bond_for_each_slave(bond, slave, iter) {
807 bond->primary_slave->link == BOND_LINK_UP && 800 if (slave->link == BOND_LINK_UP)
808 bond_should_change_active(bond)) { 801 return slave;
809 new_active = bond->primary_slave; 802 if (slave->link == BOND_LINK_BACK && IS_UP(slave->dev) &&
810 } 803 slave->delay < mintime) {
811 804 mintime = slave->delay;
812 /* remember where to stop iterating over the slaves */ 805 bestslave = slave;
813 old_active = new_active;
814
815 bond_for_each_slave_from(bond, new_active, i, old_active) {
816 if (new_active->link == BOND_LINK_UP) {
817 return new_active;
818 } else if (new_active->link == BOND_LINK_BACK &&
819 IS_UP(new_active->dev)) {
820 /* link up, but waiting for stabilization */
821 if (new_active->delay < mintime) {
822 mintime = new_active->delay;
823 bestslave = new_active;
824 }
825 } 806 }
826 } 807 }
827 808