Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5a983f3 authored by Mazhar Rana's avatar Mazhar Rana Committed by David S. Miller
Browse files

bonding: "primary_reselect" with "failure" is not working properly



When "primary_reselect" is set to "failure", primary interface should
not become active until current active slave is down. But if we set first
member of bond device as a "primary" interface and "primary_reselect"
is set to "failure" then whenever primary interface's link get back(up)
it become active slave even if current active slave is still up.

With this patch, "bond_find_best_slave" will not traverse members if
primary interface is not candidate for failover/reselection and current
active slave is still up.

Signed-off-by: default avatarMazhar Rana <mazhar.rana@cyberoam.com>
Signed-off-by: default avatarJay Vosburgh <j.vosburgh@gmail.com>
Signed-off-by: default avatarJay Vosburgh <jay.vosburgh@canonical.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fc24f2b2
Loading
Loading
Loading
Loading
+34 −17
Original line number Original line Diff line number Diff line
@@ -689,40 +689,57 @@ static void bond_do_fail_over_mac(struct bonding *bond,


}
}


static bool bond_should_change_active(struct bonding *bond)
static struct slave *bond_choose_primary_or_current(struct bonding *bond)
{
{
	struct slave *prim = rtnl_dereference(bond->primary_slave);
	struct slave *prim = rtnl_dereference(bond->primary_slave);
	struct slave *curr = rtnl_dereference(bond->curr_active_slave);
	struct slave *curr = rtnl_dereference(bond->curr_active_slave);


	if (!prim || !curr || curr->link != BOND_LINK_UP)
	if (!prim || prim->link != BOND_LINK_UP) {
		return true;
		if (!curr || curr->link != BOND_LINK_UP)
			return NULL;
		return curr;
	}

	if (bond->force_primary) {
	if (bond->force_primary) {
		bond->force_primary = false;
		bond->force_primary = false;
		return true;
		return prim;
	}

	if (!curr || curr->link != BOND_LINK_UP)
		return prim;

	/* At this point, prim and curr are both up */
	switch (bond->params.primary_reselect) {
	case BOND_PRI_RESELECT_ALWAYS:
		return prim;
	case BOND_PRI_RESELECT_BETTER:
		if (prim->speed < curr->speed)
			return curr;
		if (prim->speed == curr->speed && prim->duplex <= curr->duplex)
			return curr;
		return prim;
	case BOND_PRI_RESELECT_FAILURE:
		return curr;
	default:
		netdev_err(bond->dev, "impossible primary_reselect %d\n",
			   bond->params.primary_reselect);
		return curr;
	}
	}
	if (bond->params.primary_reselect == BOND_PRI_RESELECT_BETTER &&
	    (prim->speed < curr->speed ||
	     (prim->speed == curr->speed && prim->duplex <= curr->duplex)))
		return false;
	if (bond->params.primary_reselect == BOND_PRI_RESELECT_FAILURE)
		return false;
	return true;
}
}


/**
/**
 * find_best_interface - select the best available slave to be the active one
 * bond_find_best_slave - select the best available slave to be the active one
 * @bond: our bonding struct
 * @bond: our bonding struct
 */
 */
static struct slave *bond_find_best_slave(struct bonding *bond)
static struct slave *bond_find_best_slave(struct bonding *bond)
{
{
	struct slave *slave, *bestslave = NULL, *primary;
	struct slave *slave, *bestslave = NULL;
	struct list_head *iter;
	struct list_head *iter;
	int mintime = bond->params.updelay;
	int mintime = bond->params.updelay;


	primary = rtnl_dereference(bond->primary_slave);
	slave = bond_choose_primary_or_current(bond);
	if (primary && primary->link == BOND_LINK_UP &&
	if (slave)
	    bond_should_change_active(bond))
		return slave;
		return primary;


	bond_for_each_slave(bond, slave, iter) {
	bond_for_each_slave(bond, slave, iter) {
		if (slave->link == BOND_LINK_UP)
		if (slave->link == BOND_LINK_UP)