diff options
author | Nikolay Aleksandrov <nikolay@redhat.com> | 2014-09-11 16:49:27 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-09-13 16:29:07 -0400 |
commit | e470259fa1bd7ce5a375b16c5ec97cc0e83b058d (patch) | |
tree | 54598d31df40f265aed61901b30a64f32b62b16b /drivers/net/bonding/bond_3ad.c | |
parent | 4bab16d7c97498e91564231b922d49f52efaf7d4 (diff) |
bonding: 3ad: convert to bond->mode_lock
Now that we have bond->mode_lock, we can remove the state_machine_lock
and use it in its place. There're no fast paths requiring the per-port
spinlocks so it should be okay to consolidate them into mode_lock.
Also move it inside the unbinding function as we don't want to expose
mode_lock outside of the specific modes.
Suggested-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding/bond_3ad.c')
-rw-r--r-- | drivers/net/bonding/bond_3ad.c | 70 |
1 files changed, 21 insertions, 49 deletions
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index 1824d1df4d09..2bb360f32a64 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c | |||
@@ -234,24 +234,6 @@ static inline int __check_agg_selection_timer(struct port *port) | |||
234 | } | 234 | } |
235 | 235 | ||
236 | /** | 236 | /** |
237 | * __get_state_machine_lock - lock the port's state machines | ||
238 | * @port: the port we're looking at | ||
239 | */ | ||
240 | static inline void __get_state_machine_lock(struct port *port) | ||
241 | { | ||
242 | spin_lock_bh(&(SLAVE_AD_INFO(port->slave)->state_machine_lock)); | ||
243 | } | ||
244 | |||
245 | /** | ||
246 | * __release_state_machine_lock - unlock the port's state machines | ||
247 | * @port: the port we're looking at | ||
248 | */ | ||
249 | static inline void __release_state_machine_lock(struct port *port) | ||
250 | { | ||
251 | spin_unlock_bh(&(SLAVE_AD_INFO(port->slave)->state_machine_lock)); | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * __get_link_speed - get a port's speed | 237 | * __get_link_speed - get a port's speed |
256 | * @port: the port we're looking at | 238 | * @port: the port we're looking at |
257 | * | 239 | * |
@@ -341,16 +323,6 @@ static u8 __get_duplex(struct port *port) | |||
341 | return retval; | 323 | return retval; |
342 | } | 324 | } |
343 | 325 | ||
344 | /** | ||
345 | * __initialize_port_locks - initialize a port's STATE machine spinlock | ||
346 | * @port: the slave of the port we're looking at | ||
347 | */ | ||
348 | static inline void __initialize_port_locks(struct slave *slave) | ||
349 | { | ||
350 | /* make sure it isn't called twice */ | ||
351 | spin_lock_init(&(SLAVE_AD_INFO(slave)->state_machine_lock)); | ||
352 | } | ||
353 | |||
354 | /* Conversions */ | 326 | /* Conversions */ |
355 | 327 | ||
356 | /** | 328 | /** |
@@ -1843,7 +1815,6 @@ void bond_3ad_bind_slave(struct slave *slave) | |||
1843 | 1815 | ||
1844 | ad_initialize_port(port, bond->params.lacp_fast); | 1816 | ad_initialize_port(port, bond->params.lacp_fast); |
1845 | 1817 | ||
1846 | __initialize_port_locks(slave); | ||
1847 | port->slave = slave; | 1818 | port->slave = slave; |
1848 | port->actor_port_number = SLAVE_AD_INFO(slave)->id; | 1819 | port->actor_port_number = SLAVE_AD_INFO(slave)->id; |
1849 | /* key is determined according to the link speed, duplex and user key(which | 1820 | /* key is determined according to the link speed, duplex and user key(which |
@@ -1899,6 +1870,8 @@ void bond_3ad_unbind_slave(struct slave *slave) | |||
1899 | struct slave *slave_iter; | 1870 | struct slave *slave_iter; |
1900 | struct list_head *iter; | 1871 | struct list_head *iter; |
1901 | 1872 | ||
1873 | /* Sync against bond_3ad_state_machine_handler() */ | ||
1874 | spin_lock_bh(&bond->mode_lock); | ||
1902 | aggregator = &(SLAVE_AD_INFO(slave)->aggregator); | 1875 | aggregator = &(SLAVE_AD_INFO(slave)->aggregator); |
1903 | port = &(SLAVE_AD_INFO(slave)->port); | 1876 | port = &(SLAVE_AD_INFO(slave)->port); |
1904 | 1877 | ||
@@ -1906,7 +1879,7 @@ void bond_3ad_unbind_slave(struct slave *slave) | |||
1906 | if (!port->slave) { | 1879 | if (!port->slave) { |
1907 | netdev_warn(bond->dev, "Trying to unbind an uninitialized port on %s\n", | 1880 | netdev_warn(bond->dev, "Trying to unbind an uninitialized port on %s\n", |
1908 | slave->dev->name); | 1881 | slave->dev->name); |
1909 | return; | 1882 | goto out; |
1910 | } | 1883 | } |
1911 | 1884 | ||
1912 | netdev_dbg(bond->dev, "Unbinding Link Aggregation Group %d\n", | 1885 | netdev_dbg(bond->dev, "Unbinding Link Aggregation Group %d\n", |
@@ -2032,6 +2005,9 @@ void bond_3ad_unbind_slave(struct slave *slave) | |||
2032 | } | 2005 | } |
2033 | } | 2006 | } |
2034 | port->slave = NULL; | 2007 | port->slave = NULL; |
2008 | |||
2009 | out: | ||
2010 | spin_unlock_bh(&bond->mode_lock); | ||
2035 | } | 2011 | } |
2036 | 2012 | ||
2037 | /** | 2013 | /** |
@@ -2057,6 +2033,10 @@ void bond_3ad_state_machine_handler(struct work_struct *work) | |||
2057 | struct port *port; | 2033 | struct port *port; |
2058 | bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER; | 2034 | bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER; |
2059 | 2035 | ||
2036 | /* Lock to protect data accessed by all (e.g., port->sm_vars) and | ||
2037 | * against running with bond_3ad_unbind_slave. ad_rx_machine may run | ||
2038 | * concurrently due to incoming LACPDU as well. | ||
2039 | */ | ||
2060 | spin_lock_bh(&bond->mode_lock); | 2040 | spin_lock_bh(&bond->mode_lock); |
2061 | rcu_read_lock(); | 2041 | rcu_read_lock(); |
2062 | 2042 | ||
@@ -2093,12 +2073,6 @@ void bond_3ad_state_machine_handler(struct work_struct *work) | |||
2093 | goto re_arm; | 2073 | goto re_arm; |
2094 | } | 2074 | } |
2095 | 2075 | ||
2096 | /* Lock around state machines to protect data accessed | ||
2097 | * by all (e.g., port->sm_vars). ad_rx_machine may run | ||
2098 | * concurrently due to incoming LACPDU. | ||
2099 | */ | ||
2100 | __get_state_machine_lock(port); | ||
2101 | |||
2102 | ad_rx_machine(NULL, port); | 2076 | ad_rx_machine(NULL, port); |
2103 | ad_periodic_machine(port); | 2077 | ad_periodic_machine(port); |
2104 | ad_port_selection_logic(port); | 2078 | ad_port_selection_logic(port); |
@@ -2108,8 +2082,6 @@ void bond_3ad_state_machine_handler(struct work_struct *work) | |||
2108 | /* turn off the BEGIN bit, since we already handled it */ | 2082 | /* turn off the BEGIN bit, since we already handled it */ |
2109 | if (port->sm_vars & AD_PORT_BEGIN) | 2083 | if (port->sm_vars & AD_PORT_BEGIN) |
2110 | port->sm_vars &= ~AD_PORT_BEGIN; | 2084 | port->sm_vars &= ~AD_PORT_BEGIN; |
2111 | |||
2112 | __release_state_machine_lock(port); | ||
2113 | } | 2085 | } |
2114 | 2086 | ||
2115 | re_arm: | 2087 | re_arm: |
@@ -2161,9 +2133,9 @@ static int bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, | |||
2161 | netdev_dbg(slave->bond->dev, "Received LACPDU on port %d\n", | 2133 | netdev_dbg(slave->bond->dev, "Received LACPDU on port %d\n", |
2162 | port->actor_port_number); | 2134 | port->actor_port_number); |
2163 | /* Protect against concurrent state machines */ | 2135 | /* Protect against concurrent state machines */ |
2164 | __get_state_machine_lock(port); | 2136 | spin_lock(&slave->bond->mode_lock); |
2165 | ad_rx_machine(lacpdu, port); | 2137 | ad_rx_machine(lacpdu, port); |
2166 | __release_state_machine_lock(port); | 2138 | spin_unlock(&slave->bond->mode_lock); |
2167 | break; | 2139 | break; |
2168 | 2140 | ||
2169 | case AD_TYPE_MARKER: | 2141 | case AD_TYPE_MARKER: |
@@ -2213,7 +2185,7 @@ void bond_3ad_adapter_speed_changed(struct slave *slave) | |||
2213 | return; | 2185 | return; |
2214 | } | 2186 | } |
2215 | 2187 | ||
2216 | __get_state_machine_lock(port); | 2188 | spin_lock_bh(&slave->bond->mode_lock); |
2217 | 2189 | ||
2218 | port->actor_admin_port_key &= ~AD_SPEED_KEY_BITS; | 2190 | port->actor_admin_port_key &= ~AD_SPEED_KEY_BITS; |
2219 | port->actor_oper_port_key = port->actor_admin_port_key |= | 2191 | port->actor_oper_port_key = port->actor_admin_port_key |= |
@@ -2224,7 +2196,7 @@ void bond_3ad_adapter_speed_changed(struct slave *slave) | |||
2224 | */ | 2196 | */ |
2225 | port->sm_vars |= AD_PORT_BEGIN; | 2197 | port->sm_vars |= AD_PORT_BEGIN; |
2226 | 2198 | ||
2227 | __release_state_machine_lock(port); | 2199 | spin_unlock_bh(&slave->bond->mode_lock); |
2228 | } | 2200 | } |
2229 | 2201 | ||
2230 | /** | 2202 | /** |
@@ -2246,7 +2218,7 @@ void bond_3ad_adapter_duplex_changed(struct slave *slave) | |||
2246 | return; | 2218 | return; |
2247 | } | 2219 | } |
2248 | 2220 | ||
2249 | __get_state_machine_lock(port); | 2221 | spin_lock_bh(&slave->bond->mode_lock); |
2250 | 2222 | ||
2251 | port->actor_admin_port_key &= ~AD_DUPLEX_KEY_BITS; | 2223 | port->actor_admin_port_key &= ~AD_DUPLEX_KEY_BITS; |
2252 | port->actor_oper_port_key = port->actor_admin_port_key |= | 2224 | port->actor_oper_port_key = port->actor_admin_port_key |= |
@@ -2257,7 +2229,7 @@ void bond_3ad_adapter_duplex_changed(struct slave *slave) | |||
2257 | */ | 2229 | */ |
2258 | port->sm_vars |= AD_PORT_BEGIN; | 2230 | port->sm_vars |= AD_PORT_BEGIN; |
2259 | 2231 | ||
2260 | __release_state_machine_lock(port); | 2232 | spin_unlock_bh(&slave->bond->mode_lock); |
2261 | } | 2233 | } |
2262 | 2234 | ||
2263 | /** | 2235 | /** |
@@ -2280,7 +2252,7 @@ void bond_3ad_handle_link_change(struct slave *slave, char link) | |||
2280 | return; | 2252 | return; |
2281 | } | 2253 | } |
2282 | 2254 | ||
2283 | __get_state_machine_lock(port); | 2255 | spin_lock_bh(&slave->bond->mode_lock); |
2284 | /* on link down we are zeroing duplex and speed since | 2256 | /* on link down we are zeroing duplex and speed since |
2285 | * some of the adaptors(ce1000.lan) report full duplex/speed | 2257 | * some of the adaptors(ce1000.lan) report full duplex/speed |
2286 | * instead of N/A(duplex) / 0(speed). | 2258 | * instead of N/A(duplex) / 0(speed). |
@@ -2311,7 +2283,7 @@ void bond_3ad_handle_link_change(struct slave *slave, char link) | |||
2311 | */ | 2283 | */ |
2312 | port->sm_vars |= AD_PORT_BEGIN; | 2284 | port->sm_vars |= AD_PORT_BEGIN; |
2313 | 2285 | ||
2314 | __release_state_machine_lock(port); | 2286 | spin_unlock_bh(&slave->bond->mode_lock); |
2315 | } | 2287 | } |
2316 | 2288 | ||
2317 | /** | 2289 | /** |
@@ -2495,7 +2467,7 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond, | |||
2495 | * When modify lacp_rate parameter via sysfs, | 2467 | * When modify lacp_rate parameter via sysfs, |
2496 | * update actor_oper_port_state of each port. | 2468 | * update actor_oper_port_state of each port. |
2497 | * | 2469 | * |
2498 | * Hold slave->state_machine_lock, | 2470 | * Hold bond->mode_lock, |
2499 | * so we can modify port->actor_oper_port_state, | 2471 | * so we can modify port->actor_oper_port_state, |
2500 | * no matter bond is up or down. | 2472 | * no matter bond is up or down. |
2501 | */ | 2473 | */ |
@@ -2507,13 +2479,13 @@ void bond_3ad_update_lacp_rate(struct bonding *bond) | |||
2507 | int lacp_fast; | 2479 | int lacp_fast; |
2508 | 2480 | ||
2509 | lacp_fast = bond->params.lacp_fast; | 2481 | lacp_fast = bond->params.lacp_fast; |
2482 | spin_lock_bh(&bond->mode_lock); | ||
2510 | bond_for_each_slave(bond, slave, iter) { | 2483 | bond_for_each_slave(bond, slave, iter) { |
2511 | port = &(SLAVE_AD_INFO(slave)->port); | 2484 | port = &(SLAVE_AD_INFO(slave)->port); |
2512 | __get_state_machine_lock(port); | ||
2513 | if (lacp_fast) | 2485 | if (lacp_fast) |
2514 | port->actor_oper_port_state |= AD_STATE_LACP_TIMEOUT; | 2486 | port->actor_oper_port_state |= AD_STATE_LACP_TIMEOUT; |
2515 | else | 2487 | else |
2516 | port->actor_oper_port_state &= ~AD_STATE_LACP_TIMEOUT; | 2488 | port->actor_oper_port_state &= ~AD_STATE_LACP_TIMEOUT; |
2517 | __release_state_machine_lock(port); | ||
2518 | } | 2489 | } |
2490 | spin_unlock_bh(&bond->mode_lock); | ||
2519 | } | 2491 | } |