Commit 95ed0edd authored by David S. Miller's avatar David S. Miller

Merge branch 'bond-link-status-fixes'

Mahesh Bandewar says:

====================
link-status fixes for mii-monitoring

The mii monitoring is divided into two phases - inspect and commit. The
inspect phase technically should not make any changes to the state and
defer it to the commit phase. However detected link state inconsistencies
on several machines and discovered that it's the result of some
inconsistent update to link states and assumption that you *always* get
rtnl-mutex. In reality when trylock() fails to acquire rtnl-mutex, the
commit phase is postponed until next mii-mon run. At the next round
because of the state change performed in the previous inspect-run, this
round does not detect any changes and would skip calling commit phase.
This would result in an inconsistent state until next link event happens
(if it ever happens).

During the the commit phase, it's always assumed that speed and duplex
fetch is always successful, but that's always not the case. However the
slave state is marked UP irrespective of speed / duplex fetch operation.
If the speed / duplex fetch operation results in insane values for either
of these two fields, then keeping internal link state UP is not going to
provide fruitful results either.

Please see into individual patches for more details.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 205ed44e e292dcae
...@@ -2446,9 +2446,9 @@ void bond_3ad_adapter_speed_duplex_changed(struct slave *slave) ...@@ -2446,9 +2446,9 @@ void bond_3ad_adapter_speed_duplex_changed(struct slave *slave)
spin_lock_bh(&slave->bond->mode_lock); spin_lock_bh(&slave->bond->mode_lock);
ad_update_actor_keys(port, false); ad_update_actor_keys(port, false);
spin_unlock_bh(&slave->bond->mode_lock);
netdev_dbg(slave->bond->dev, "Port %d slave %s changed speed/duplex\n", netdev_dbg(slave->bond->dev, "Port %d slave %s changed speed/duplex\n",
port->actor_port_number, slave->dev->name); port->actor_port_number, slave->dev->name);
spin_unlock_bh(&slave->bond->mode_lock);
} }
/** /**
...@@ -2492,12 +2492,12 @@ void bond_3ad_handle_link_change(struct slave *slave, char link) ...@@ -2492,12 +2492,12 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
agg = __get_first_agg(port); agg = __get_first_agg(port);
ad_agg_selection_logic(agg, &dummy); ad_agg_selection_logic(agg, &dummy);
spin_unlock_bh(&slave->bond->mode_lock);
netdev_dbg(slave->bond->dev, "Port %d changed link status to %s\n", netdev_dbg(slave->bond->dev, "Port %d changed link status to %s\n",
port->actor_port_number, port->actor_port_number,
link == BOND_LINK_UP ? "UP" : "DOWN"); link == BOND_LINK_UP ? "UP" : "DOWN");
spin_unlock_bh(&slave->bond->mode_lock);
/* RTNL is held and mode_lock is released so it's safe /* RTNL is held and mode_lock is released so it's safe
* to update slave_array here. * to update slave_array here.
*/ */
......
...@@ -365,9 +365,10 @@ int bond_set_carrier(struct bonding *bond) ...@@ -365,9 +365,10 @@ int bond_set_carrier(struct bonding *bond)
/* Get link speed and duplex from the slave's base driver /* Get link speed and duplex from the slave's base driver
* using ethtool. If for some reason the call fails or the * using ethtool. If for some reason the call fails or the
* values are invalid, set speed and duplex to -1, * values are invalid, set speed and duplex to -1,
* and return. * and return. Return 1 if speed or duplex settings are
* UNKNOWN; 0 otherwise.
*/ */
static void bond_update_speed_duplex(struct slave *slave) static int bond_update_speed_duplex(struct slave *slave)
{ {
struct net_device *slave_dev = slave->dev; struct net_device *slave_dev = slave->dev;
struct ethtool_link_ksettings ecmd; struct ethtool_link_ksettings ecmd;
...@@ -377,24 +378,27 @@ static void bond_update_speed_duplex(struct slave *slave) ...@@ -377,24 +378,27 @@ static void bond_update_speed_duplex(struct slave *slave)
slave->duplex = DUPLEX_UNKNOWN; slave->duplex = DUPLEX_UNKNOWN;
res = __ethtool_get_link_ksettings(slave_dev, &ecmd); res = __ethtool_get_link_ksettings(slave_dev, &ecmd);
if (res < 0) if (res < 0) {
return; slave->link = BOND_LINK_DOWN;
return 1;
if (ecmd.base.speed == 0 || ecmd.base.speed == ((__u32)-1)) }
return; if (ecmd.base.speed == 0 || ecmd.base.speed == ((__u32)-1)) {
slave->link = BOND_LINK_DOWN;
return 1;
}
switch (ecmd.base.duplex) { switch (ecmd.base.duplex) {
case DUPLEX_FULL: case DUPLEX_FULL:
case DUPLEX_HALF: case DUPLEX_HALF:
break; break;
default: default:
return; slave->link = BOND_LINK_DOWN;
return 1;
} }
slave->speed = ecmd.base.speed; slave->speed = ecmd.base.speed;
slave->duplex = ecmd.base.duplex; slave->duplex = ecmd.base.duplex;
return; return 0;
} }
const char *bond_slave_link_status(s8 link) const char *bond_slave_link_status(s8 link)
...@@ -2033,8 +2037,7 @@ static int bond_miimon_inspect(struct bonding *bond) ...@@ -2033,8 +2037,7 @@ static int bond_miimon_inspect(struct bonding *bond)
if (link_state) if (link_state)
continue; continue;
bond_set_slave_link_state(slave, BOND_LINK_FAIL, bond_propose_link_state(slave, BOND_LINK_FAIL);
BOND_SLAVE_NOTIFY_LATER);
slave->delay = bond->params.downdelay; slave->delay = bond->params.downdelay;
if (slave->delay) { if (slave->delay) {
netdev_info(bond->dev, "link status down for %sinterface %s, disabling it in %d ms\n", netdev_info(bond->dev, "link status down for %sinterface %s, disabling it in %d ms\n",
...@@ -2049,8 +2052,7 @@ static int bond_miimon_inspect(struct bonding *bond) ...@@ -2049,8 +2052,7 @@ static int bond_miimon_inspect(struct bonding *bond)
case BOND_LINK_FAIL: case BOND_LINK_FAIL:
if (link_state) { if (link_state) {
/* recovered before downdelay expired */ /* recovered before downdelay expired */
bond_set_slave_link_state(slave, BOND_LINK_UP, bond_propose_link_state(slave, BOND_LINK_UP);
BOND_SLAVE_NOTIFY_LATER);
slave->last_link_up = jiffies; slave->last_link_up = jiffies;
netdev_info(bond->dev, "link status up again after %d ms for interface %s\n", netdev_info(bond->dev, "link status up again after %d ms for interface %s\n",
(bond->params.downdelay - slave->delay) * (bond->params.downdelay - slave->delay) *
...@@ -2072,8 +2074,7 @@ static int bond_miimon_inspect(struct bonding *bond) ...@@ -2072,8 +2074,7 @@ static int bond_miimon_inspect(struct bonding *bond)
if (!link_state) if (!link_state)
continue; continue;
bond_set_slave_link_state(slave, BOND_LINK_BACK, bond_propose_link_state(slave, BOND_LINK_BACK);
BOND_SLAVE_NOTIFY_LATER);
slave->delay = bond->params.updelay; slave->delay = bond->params.updelay;
if (slave->delay) { if (slave->delay) {
...@@ -2086,9 +2087,7 @@ static int bond_miimon_inspect(struct bonding *bond) ...@@ -2086,9 +2087,7 @@ static int bond_miimon_inspect(struct bonding *bond)
/*FALLTHRU*/ /*FALLTHRU*/
case BOND_LINK_BACK: case BOND_LINK_BACK:
if (!link_state) { if (!link_state) {
bond_set_slave_link_state(slave, bond_propose_link_state(slave, BOND_LINK_DOWN);
BOND_LINK_DOWN,
BOND_SLAVE_NOTIFY_LATER);
netdev_info(bond->dev, "link status down again after %d ms for interface %s\n", netdev_info(bond->dev, "link status down again after %d ms for interface %s\n",
(bond->params.updelay - slave->delay) * (bond->params.updelay - slave->delay) *
bond->params.miimon, bond->params.miimon,
...@@ -2126,7 +2125,12 @@ static void bond_miimon_commit(struct bonding *bond) ...@@ -2126,7 +2125,12 @@ static void bond_miimon_commit(struct bonding *bond)
continue; continue;
case BOND_LINK_UP: case BOND_LINK_UP:
bond_update_speed_duplex(slave); if (bond_update_speed_duplex(slave)) {
netdev_warn(bond->dev,
"failed to get link speed/duplex for %s\n",
slave->dev->name);
continue;
}
bond_set_slave_link_state(slave, BOND_LINK_UP, bond_set_slave_link_state(slave, BOND_LINK_UP,
BOND_SLAVE_NOTIFY_NOW); BOND_SLAVE_NOTIFY_NOW);
slave->last_link_up = jiffies; slave->last_link_up = jiffies;
...@@ -2225,6 +2229,8 @@ static void bond_mii_monitor(struct work_struct *work) ...@@ -2225,6 +2229,8 @@ static void bond_mii_monitor(struct work_struct *work)
mii_work.work); mii_work.work);
bool should_notify_peers = false; bool should_notify_peers = false;
unsigned long delay; unsigned long delay;
struct slave *slave;
struct list_head *iter;
delay = msecs_to_jiffies(bond->params.miimon); delay = msecs_to_jiffies(bond->params.miimon);
...@@ -2245,6 +2251,9 @@ static void bond_mii_monitor(struct work_struct *work) ...@@ -2245,6 +2251,9 @@ static void bond_mii_monitor(struct work_struct *work)
goto re_arm; goto re_arm;
} }
bond_for_each_slave(bond, slave, iter) {
bond_commit_link_state(slave, BOND_SLAVE_NOTIFY_LATER);
}
bond_miimon_commit(bond); bond_miimon_commit(bond);
rtnl_unlock(); /* might sleep, hold no other locks */ rtnl_unlock(); /* might sleep, hold no other locks */
......
...@@ -154,6 +154,7 @@ struct slave { ...@@ -154,6 +154,7 @@ struct slave {
unsigned long last_rx; unsigned long last_rx;
unsigned long target_last_arp_rx[BOND_MAX_ARP_TARGETS]; unsigned long target_last_arp_rx[BOND_MAX_ARP_TARGETS];
s8 link; /* one of BOND_LINK_XXXX */ s8 link; /* one of BOND_LINK_XXXX */
s8 link_new_state; /* one of BOND_LINK_XXXX */
s8 new_link; s8 new_link;
u8 backup:1, /* indicates backup slave. Value corresponds with u8 backup:1, /* indicates backup slave. Value corresponds with
BOND_STATE_ACTIVE and BOND_STATE_BACKUP */ BOND_STATE_ACTIVE and BOND_STATE_BACKUP */
...@@ -504,13 +505,17 @@ static inline bool bond_is_slave_inactive(struct slave *slave) ...@@ -504,13 +505,17 @@ static inline bool bond_is_slave_inactive(struct slave *slave)
return slave->inactive; return slave->inactive;
} }
static inline void bond_set_slave_link_state(struct slave *slave, int state, static inline void bond_propose_link_state(struct slave *slave, int state)
bool notify) {
slave->link_new_state = state;
}
static inline void bond_commit_link_state(struct slave *slave, bool notify)
{ {
if (slave->link == state) if (slave->link == slave->link_new_state)
return; return;
slave->link = state; slave->link = slave->link_new_state;
if (notify) { if (notify) {
bond_queue_slave_event(slave); bond_queue_slave_event(slave);
bond_lower_state_changed(slave); bond_lower_state_changed(slave);
...@@ -523,6 +528,13 @@ static inline void bond_set_slave_link_state(struct slave *slave, int state, ...@@ -523,6 +528,13 @@ static inline void bond_set_slave_link_state(struct slave *slave, int state,
} }
} }
static inline void bond_set_slave_link_state(struct slave *slave, int state,
bool notify)
{
bond_propose_link_state(slave, state);
bond_commit_link_state(slave, notify);
}
static inline void bond_slave_link_notify(struct bonding *bond) static inline void bond_slave_link_notify(struct bonding *bond)
{ {
struct list_head *iter; struct list_head *iter;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment