diff options
Diffstat (limited to 'drivers/net/bonding')
-rw-r--r-- | drivers/net/bonding/bond_3ad.c | 191 | ||||
-rw-r--r-- | drivers/net/bonding/bond_alb.c | 81 | ||||
-rw-r--r-- | drivers/net/bonding/bond_alb.h | 4 | ||||
-rw-r--r-- | drivers/net/bonding/bond_main.c | 303 | ||||
-rw-r--r-- | drivers/net/bonding/bond_procfs.c | 21 | ||||
-rw-r--r-- | drivers/net/bonding/bond_sysfs.c | 62 | ||||
-rw-r--r-- | drivers/net/bonding/bonding.h | 74 |
7 files changed, 332 insertions, 404 deletions
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index 0d8f427ade93..c62606a67f6a 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c | |||
@@ -136,41 +136,6 @@ static inline struct bonding *__get_bond_by_port(struct port *port) | |||
136 | } | 136 | } |
137 | 137 | ||
138 | /** | 138 | /** |
139 | * __get_first_port - get the first port in the bond | ||
140 | * @bond: the bond we're looking at | ||
141 | * | ||
142 | * Return the port of the first slave in @bond, or %NULL if it can't be found. | ||
143 | */ | ||
144 | static inline struct port *__get_first_port(struct bonding *bond) | ||
145 | { | ||
146 | struct slave *first_slave = bond_first_slave(bond); | ||
147 | |||
148 | return first_slave ? &(SLAVE_AD_INFO(first_slave).port) : NULL; | ||
149 | } | ||
150 | |||
151 | /** | ||
152 | * __get_next_port - get the next port in the bond | ||
153 | * @port: the port we're looking at | ||
154 | * | ||
155 | * Return the port of the slave that is next in line of @port's slave in the | ||
156 | * bond, or %NULL if it can't be found. | ||
157 | */ | ||
158 | static inline struct port *__get_next_port(struct port *port) | ||
159 | { | ||
160 | struct bonding *bond = __get_bond_by_port(port); | ||
161 | struct slave *slave = port->slave, *slave_next; | ||
162 | |||
163 | // If there's no bond for this port, or this is the last slave | ||
164 | if (bond == NULL) | ||
165 | return NULL; | ||
166 | slave_next = bond_next_slave(bond, slave); | ||
167 | if (!slave_next || bond_is_first_slave(bond, slave_next)) | ||
168 | return NULL; | ||
169 | |||
170 | return &(SLAVE_AD_INFO(slave_next).port); | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * __get_first_agg - get the first aggregator in the bond | 139 | * __get_first_agg - get the first aggregator in the bond |
175 | * @bond: the bond we're looking at | 140 | * @bond: the bond we're looking at |
176 | * | 141 | * |
@@ -190,28 +155,6 @@ static inline struct aggregator *__get_first_agg(struct port *port) | |||
190 | return first_slave ? &(SLAVE_AD_INFO(first_slave).aggregator) : NULL; | 155 | return first_slave ? &(SLAVE_AD_INFO(first_slave).aggregator) : NULL; |
191 | } | 156 | } |
192 | 157 | ||
193 | /** | ||
194 | * __get_next_agg - get the next aggregator in the bond | ||
195 | * @aggregator: the aggregator we're looking at | ||
196 | * | ||
197 | * Return the aggregator of the slave that is next in line of @aggregator's | ||
198 | * slave in the bond, or %NULL if it can't be found. | ||
199 | */ | ||
200 | static inline struct aggregator *__get_next_agg(struct aggregator *aggregator) | ||
201 | { | ||
202 | struct slave *slave = aggregator->slave, *slave_next; | ||
203 | struct bonding *bond = bond_get_bond_by_slave(slave); | ||
204 | |||
205 | // If there's no bond for this aggregator, or this is the last slave | ||
206 | if (bond == NULL) | ||
207 | return NULL; | ||
208 | slave_next = bond_next_slave(bond, slave); | ||
209 | if (!slave_next || bond_is_first_slave(bond, slave_next)) | ||
210 | return NULL; | ||
211 | |||
212 | return &(SLAVE_AD_INFO(slave_next).aggregator); | ||
213 | } | ||
214 | |||
215 | /* | 158 | /* |
216 | * __agg_has_partner | 159 | * __agg_has_partner |
217 | * | 160 | * |
@@ -755,16 +698,15 @@ static u32 __get_agg_bandwidth(struct aggregator *aggregator) | |||
755 | */ | 698 | */ |
756 | static struct aggregator *__get_active_agg(struct aggregator *aggregator) | 699 | static struct aggregator *__get_active_agg(struct aggregator *aggregator) |
757 | { | 700 | { |
758 | struct aggregator *retval = NULL; | 701 | struct bonding *bond = aggregator->slave->bond; |
702 | struct list_head *iter; | ||
703 | struct slave *slave; | ||
759 | 704 | ||
760 | for (; aggregator; aggregator = __get_next_agg(aggregator)) { | 705 | bond_for_each_slave(bond, slave, iter) |
761 | if (aggregator->is_active) { | 706 | if (SLAVE_AD_INFO(slave).aggregator.is_active) |
762 | retval = aggregator; | 707 | return &(SLAVE_AD_INFO(slave).aggregator); |
763 | break; | ||
764 | } | ||
765 | } | ||
766 | 708 | ||
767 | return retval; | 709 | return NULL; |
768 | } | 710 | } |
769 | 711 | ||
770 | /** | 712 | /** |
@@ -1274,12 +1216,17 @@ static void ad_port_selection_logic(struct port *port) | |||
1274 | { | 1216 | { |
1275 | struct aggregator *aggregator, *free_aggregator = NULL, *temp_aggregator; | 1217 | struct aggregator *aggregator, *free_aggregator = NULL, *temp_aggregator; |
1276 | struct port *last_port = NULL, *curr_port; | 1218 | struct port *last_port = NULL, *curr_port; |
1219 | struct list_head *iter; | ||
1220 | struct bonding *bond; | ||
1221 | struct slave *slave; | ||
1277 | int found = 0; | 1222 | int found = 0; |
1278 | 1223 | ||
1279 | // if the port is already Selected, do nothing | 1224 | // if the port is already Selected, do nothing |
1280 | if (port->sm_vars & AD_PORT_SELECTED) | 1225 | if (port->sm_vars & AD_PORT_SELECTED) |
1281 | return; | 1226 | return; |
1282 | 1227 | ||
1228 | bond = __get_bond_by_port(port); | ||
1229 | |||
1283 | // if the port is connected to other aggregator, detach it | 1230 | // if the port is connected to other aggregator, detach it |
1284 | if (port->aggregator) { | 1231 | if (port->aggregator) { |
1285 | // detach the port from its former aggregator | 1232 | // detach the port from its former aggregator |
@@ -1320,8 +1267,8 @@ static void ad_port_selection_logic(struct port *port) | |||
1320 | } | 1267 | } |
1321 | } | 1268 | } |
1322 | // search on all aggregators for a suitable aggregator for this port | 1269 | // search on all aggregators for a suitable aggregator for this port |
1323 | for (aggregator = __get_first_agg(port); aggregator; | 1270 | bond_for_each_slave(bond, slave, iter) { |
1324 | aggregator = __get_next_agg(aggregator)) { | 1271 | aggregator = &(SLAVE_AD_INFO(slave).aggregator); |
1325 | 1272 | ||
1326 | // keep a free aggregator for later use(if needed) | 1273 | // keep a free aggregator for later use(if needed) |
1327 | if (!aggregator->lag_ports) { | 1274 | if (!aggregator->lag_ports) { |
@@ -1515,19 +1462,23 @@ static int agg_device_up(const struct aggregator *agg) | |||
1515 | static void ad_agg_selection_logic(struct aggregator *agg) | 1462 | static void ad_agg_selection_logic(struct aggregator *agg) |
1516 | { | 1463 | { |
1517 | struct aggregator *best, *active, *origin; | 1464 | struct aggregator *best, *active, *origin; |
1465 | struct bonding *bond = agg->slave->bond; | ||
1466 | struct list_head *iter; | ||
1467 | struct slave *slave; | ||
1518 | struct port *port; | 1468 | struct port *port; |
1519 | 1469 | ||
1520 | origin = agg; | 1470 | origin = agg; |
1521 | active = __get_active_agg(agg); | 1471 | active = __get_active_agg(agg); |
1522 | best = (active && agg_device_up(active)) ? active : NULL; | 1472 | best = (active && agg_device_up(active)) ? active : NULL; |
1523 | 1473 | ||
1524 | do { | 1474 | bond_for_each_slave(bond, slave, iter) { |
1475 | agg = &(SLAVE_AD_INFO(slave).aggregator); | ||
1476 | |||
1525 | agg->is_active = 0; | 1477 | agg->is_active = 0; |
1526 | 1478 | ||
1527 | if (agg->num_of_ports && agg_device_up(agg)) | 1479 | if (agg->num_of_ports && agg_device_up(agg)) |
1528 | best = ad_agg_selection_test(best, agg); | 1480 | best = ad_agg_selection_test(best, agg); |
1529 | 1481 | } | |
1530 | } while ((agg = __get_next_agg(agg))); | ||
1531 | 1482 | ||
1532 | if (best && | 1483 | if (best && |
1533 | __get_agg_selection_mode(best->lag_ports) == BOND_AD_STABLE) { | 1484 | __get_agg_selection_mode(best->lag_ports) == BOND_AD_STABLE) { |
@@ -1565,8 +1516,8 @@ static void ad_agg_selection_logic(struct aggregator *agg) | |||
1565 | best->lag_ports, best->slave, | 1516 | best->lag_ports, best->slave, |
1566 | best->slave ? best->slave->dev->name : "NULL"); | 1517 | best->slave ? best->slave->dev->name : "NULL"); |
1567 | 1518 | ||
1568 | for (agg = __get_first_agg(best->lag_ports); agg; | 1519 | bond_for_each_slave(bond, slave, iter) { |
1569 | agg = __get_next_agg(agg)) { | 1520 | agg = &(SLAVE_AD_INFO(slave).aggregator); |
1570 | 1521 | ||
1571 | pr_debug("Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", | 1522 | pr_debug("Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", |
1572 | agg->aggregator_identifier, agg->num_of_ports, | 1523 | agg->aggregator_identifier, agg->num_of_ports, |
@@ -1614,13 +1565,7 @@ static void ad_agg_selection_logic(struct aggregator *agg) | |||
1614 | } | 1565 | } |
1615 | } | 1566 | } |
1616 | 1567 | ||
1617 | if (origin->slave) { | 1568 | bond_3ad_set_carrier(bond); |
1618 | struct bonding *bond; | ||
1619 | |||
1620 | bond = bond_get_bond_by_slave(origin->slave); | ||
1621 | if (bond) | ||
1622 | bond_3ad_set_carrier(bond); | ||
1623 | } | ||
1624 | } | 1569 | } |
1625 | 1570 | ||
1626 | /** | 1571 | /** |
@@ -1969,6 +1914,9 @@ void bond_3ad_unbind_slave(struct slave *slave) | |||
1969 | struct port *port, *prev_port, *temp_port; | 1914 | struct port *port, *prev_port, *temp_port; |
1970 | struct aggregator *aggregator, *new_aggregator, *temp_aggregator; | 1915 | struct aggregator *aggregator, *new_aggregator, *temp_aggregator; |
1971 | int select_new_active_agg = 0; | 1916 | int select_new_active_agg = 0; |
1917 | struct bonding *bond = slave->bond; | ||
1918 | struct slave *slave_iter; | ||
1919 | struct list_head *iter; | ||
1972 | 1920 | ||
1973 | // find the aggregator related to this slave | 1921 | // find the aggregator related to this slave |
1974 | aggregator = &(SLAVE_AD_INFO(slave).aggregator); | 1922 | aggregator = &(SLAVE_AD_INFO(slave).aggregator); |
@@ -1998,14 +1946,16 @@ void bond_3ad_unbind_slave(struct slave *slave) | |||
1998 | // reason to search for new aggregator, and that we will find one | 1946 | // reason to search for new aggregator, and that we will find one |
1999 | if ((aggregator->lag_ports != port) || (aggregator->lag_ports->next_port_in_aggregator)) { | 1947 | if ((aggregator->lag_ports != port) || (aggregator->lag_ports->next_port_in_aggregator)) { |
2000 | // find new aggregator for the related port(s) | 1948 | // find new aggregator for the related port(s) |
2001 | new_aggregator = __get_first_agg(port); | 1949 | bond_for_each_slave(bond, slave_iter, iter) { |
2002 | for (; new_aggregator; new_aggregator = __get_next_agg(new_aggregator)) { | 1950 | new_aggregator = &(SLAVE_AD_INFO(slave_iter).aggregator); |
2003 | // if the new aggregator is empty, or it is connected to our port only | 1951 | // if the new aggregator is empty, or it is connected to our port only |
2004 | if (!new_aggregator->lag_ports | 1952 | if (!new_aggregator->lag_ports |
2005 | || ((new_aggregator->lag_ports == port) | 1953 | || ((new_aggregator->lag_ports == port) |
2006 | && !new_aggregator->lag_ports->next_port_in_aggregator)) | 1954 | && !new_aggregator->lag_ports->next_port_in_aggregator)) |
2007 | break; | 1955 | break; |
2008 | } | 1956 | } |
1957 | if (!slave_iter) | ||
1958 | new_aggregator = NULL; | ||
2009 | // if new aggregator found, copy the aggregator's parameters | 1959 | // if new aggregator found, copy the aggregator's parameters |
2010 | // and connect the related lag_ports to the new aggregator | 1960 | // and connect the related lag_ports to the new aggregator |
2011 | if ((new_aggregator) && ((!new_aggregator->lag_ports) || ((new_aggregator->lag_ports == port) && !new_aggregator->lag_ports->next_port_in_aggregator))) { | 1961 | if ((new_aggregator) && ((!new_aggregator->lag_ports) || ((new_aggregator->lag_ports == port) && !new_aggregator->lag_ports->next_port_in_aggregator))) { |
@@ -2056,15 +2006,17 @@ void bond_3ad_unbind_slave(struct slave *slave) | |||
2056 | pr_info("%s: Removing an active aggregator\n", | 2006 | pr_info("%s: Removing an active aggregator\n", |
2057 | slave->bond->dev->name); | 2007 | slave->bond->dev->name); |
2058 | // select new active aggregator | 2008 | // select new active aggregator |
2059 | ad_agg_selection_logic(__get_first_agg(port)); | 2009 | temp_aggregator = __get_first_agg(port); |
2010 | if (temp_aggregator) | ||
2011 | ad_agg_selection_logic(temp_aggregator); | ||
2060 | } | 2012 | } |
2061 | } | 2013 | } |
2062 | } | 2014 | } |
2063 | 2015 | ||
2064 | pr_debug("Unbinding port %d\n", port->actor_port_number); | 2016 | pr_debug("Unbinding port %d\n", port->actor_port_number); |
2065 | // find the aggregator that this port is connected to | 2017 | // find the aggregator that this port is connected to |
2066 | temp_aggregator = __get_first_agg(port); | 2018 | bond_for_each_slave(bond, slave_iter, iter) { |
2067 | for (; temp_aggregator; temp_aggregator = __get_next_agg(temp_aggregator)) { | 2019 | temp_aggregator = &(SLAVE_AD_INFO(slave_iter).aggregator); |
2068 | prev_port = NULL; | 2020 | prev_port = NULL; |
2069 | // search the port in the aggregator's related ports | 2021 | // search the port in the aggregator's related ports |
2070 | for (temp_port = temp_aggregator->lag_ports; temp_port; | 2022 | for (temp_port = temp_aggregator->lag_ports; temp_port; |
@@ -2111,19 +2063,24 @@ void bond_3ad_state_machine_handler(struct work_struct *work) | |||
2111 | { | 2063 | { |
2112 | struct bonding *bond = container_of(work, struct bonding, | 2064 | struct bonding *bond = container_of(work, struct bonding, |
2113 | ad_work.work); | 2065 | ad_work.work); |
2114 | struct port *port; | ||
2115 | struct aggregator *aggregator; | 2066 | struct aggregator *aggregator; |
2067 | struct list_head *iter; | ||
2068 | struct slave *slave; | ||
2069 | struct port *port; | ||
2116 | 2070 | ||
2117 | read_lock(&bond->lock); | 2071 | read_lock(&bond->lock); |
2118 | 2072 | ||
2119 | //check if there are any slaves | 2073 | //check if there are any slaves |
2120 | if (list_empty(&bond->slave_list)) | 2074 | if (!bond_has_slaves(bond)) |
2121 | goto re_arm; | 2075 | goto re_arm; |
2122 | 2076 | ||
2123 | // check if agg_select_timer timer after initialize is timed out | 2077 | // check if agg_select_timer timer after initialize is timed out |
2124 | if (BOND_AD_INFO(bond).agg_select_timer && !(--BOND_AD_INFO(bond).agg_select_timer)) { | 2078 | if (BOND_AD_INFO(bond).agg_select_timer && !(--BOND_AD_INFO(bond).agg_select_timer)) { |
2079 | slave = bond_first_slave(bond); | ||
2080 | port = slave ? &(SLAVE_AD_INFO(slave).port) : NULL; | ||
2081 | |||
2125 | // select the active aggregator for the bond | 2082 | // select the active aggregator for the bond |
2126 | if ((port = __get_first_port(bond))) { | 2083 | if (port) { |
2127 | if (!port->slave) { | 2084 | if (!port->slave) { |
2128 | pr_warning("%s: Warning: bond's first port is uninitialized\n", | 2085 | pr_warning("%s: Warning: bond's first port is uninitialized\n", |
2129 | bond->dev->name); | 2086 | bond->dev->name); |
@@ -2137,7 +2094,8 @@ void bond_3ad_state_machine_handler(struct work_struct *work) | |||
2137 | } | 2094 | } |
2138 | 2095 | ||
2139 | // for each port run the state machines | 2096 | // for each port run the state machines |
2140 | for (port = __get_first_port(bond); port; port = __get_next_port(port)) { | 2097 | bond_for_each_slave(bond, slave, iter) { |
2098 | port = &(SLAVE_AD_INFO(slave).port); | ||
2141 | if (!port->slave) { | 2099 | if (!port->slave) { |
2142 | pr_warning("%s: Warning: Found an uninitialized port\n", | 2100 | pr_warning("%s: Warning: Found an uninitialized port\n", |
2143 | bond->dev->name); | 2101 | bond->dev->name); |
@@ -2382,9 +2340,12 @@ int __bond_3ad_get_active_agg_info(struct bonding *bond, | |||
2382 | struct ad_info *ad_info) | 2340 | struct ad_info *ad_info) |
2383 | { | 2341 | { |
2384 | struct aggregator *aggregator = NULL; | 2342 | struct aggregator *aggregator = NULL; |
2343 | struct list_head *iter; | ||
2344 | struct slave *slave; | ||
2385 | struct port *port; | 2345 | struct port *port; |
2386 | 2346 | ||
2387 | for (port = __get_first_port(bond); port; port = __get_next_port(port)) { | 2347 | bond_for_each_slave(bond, slave, iter) { |
2348 | port = &(SLAVE_AD_INFO(slave).port); | ||
2388 | if (port->aggregator && port->aggregator->is_active) { | 2349 | if (port->aggregator && port->aggregator->is_active) { |
2389 | aggregator = port->aggregator; | 2350 | aggregator = port->aggregator; |
2390 | break; | 2351 | break; |
@@ -2417,14 +2378,15 @@ int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info) | |||
2417 | 2378 | ||
2418 | int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) | 2379 | int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) |
2419 | { | 2380 | { |
2420 | struct slave *slave, *start_at; | ||
2421 | struct bonding *bond = netdev_priv(dev); | 2381 | struct bonding *bond = netdev_priv(dev); |
2422 | int slave_agg_no; | 2382 | struct slave *slave, *first_ok_slave; |
2423 | int slaves_in_agg; | 2383 | struct aggregator *agg; |
2424 | int agg_id; | ||
2425 | int i; | ||
2426 | struct ad_info ad_info; | 2384 | struct ad_info ad_info; |
2385 | struct list_head *iter; | ||
2386 | int slaves_in_agg; | ||
2387 | int slave_agg_no; | ||
2427 | int res = 1; | 2388 | int res = 1; |
2389 | int agg_id; | ||
2428 | 2390 | ||
2429 | read_lock(&bond->lock); | 2391 | read_lock(&bond->lock); |
2430 | if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { | 2392 | if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { |
@@ -2437,20 +2399,28 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) | |||
2437 | agg_id = ad_info.aggregator_id; | 2399 | agg_id = ad_info.aggregator_id; |
2438 | 2400 | ||
2439 | if (slaves_in_agg == 0) { | 2401 | if (slaves_in_agg == 0) { |
2440 | /*the aggregator is empty*/ | ||
2441 | pr_debug("%s: Error: active aggregator is empty\n", dev->name); | 2402 | pr_debug("%s: Error: active aggregator is empty\n", dev->name); |
2442 | goto out; | 2403 | goto out; |
2443 | } | 2404 | } |
2444 | 2405 | ||
2445 | slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg); | 2406 | slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg); |
2407 | first_ok_slave = NULL; | ||
2446 | 2408 | ||
2447 | bond_for_each_slave(bond, slave) { | 2409 | bond_for_each_slave(bond, slave, iter) { |
2448 | struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; | 2410 | agg = SLAVE_AD_INFO(slave).port.aggregator; |
2411 | if (!agg || agg->aggregator_identifier != agg_id) | ||
2412 | continue; | ||
2449 | 2413 | ||
2450 | if (agg && (agg->aggregator_identifier == agg_id)) { | 2414 | if (slave_agg_no >= 0) { |
2415 | if (!first_ok_slave && SLAVE_IS_OK(slave)) | ||
2416 | first_ok_slave = slave; | ||
2451 | slave_agg_no--; | 2417 | slave_agg_no--; |
2452 | if (slave_agg_no < 0) | 2418 | continue; |
2453 | break; | 2419 | } |
2420 | |||
2421 | if (SLAVE_IS_OK(slave)) { | ||
2422 | res = bond_dev_queue_xmit(bond, skb, slave->dev); | ||
2423 | goto out; | ||
2454 | } | 2424 | } |
2455 | } | 2425 | } |
2456 | 2426 | ||
@@ -2460,20 +2430,10 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) | |||
2460 | goto out; | 2430 | goto out; |
2461 | } | 2431 | } |
2462 | 2432 | ||
2463 | start_at = slave; | 2433 | /* we couldn't find any suitable slave after the agg_no, so use the |
2464 | 2434 | * first suitable found, if found. */ | |
2465 | bond_for_each_slave_from(bond, slave, i, start_at) { | 2435 | if (first_ok_slave) |
2466 | int slave_agg_id = 0; | 2436 | res = bond_dev_queue_xmit(bond, skb, first_ok_slave->dev); |
2467 | struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; | ||
2468 | |||
2469 | if (agg) | ||
2470 | slave_agg_id = agg->aggregator_identifier; | ||
2471 | |||
2472 | if (SLAVE_IS_OK(slave) && agg && (slave_agg_id == agg_id)) { | ||
2473 | res = bond_dev_queue_xmit(bond, skb, slave->dev); | ||
2474 | break; | ||
2475 | } | ||
2476 | } | ||
2477 | 2437 | ||
2478 | out: | 2438 | out: |
2479 | read_unlock(&bond->lock); | 2439 | read_unlock(&bond->lock); |
@@ -2515,11 +2475,12 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond, | |||
2515 | void bond_3ad_update_lacp_rate(struct bonding *bond) | 2475 | void bond_3ad_update_lacp_rate(struct bonding *bond) |
2516 | { | 2476 | { |
2517 | struct port *port = NULL; | 2477 | struct port *port = NULL; |
2478 | struct list_head *iter; | ||
2518 | struct slave *slave; | 2479 | struct slave *slave; |
2519 | int lacp_fast; | 2480 | int lacp_fast; |
2520 | 2481 | ||
2521 | lacp_fast = bond->params.lacp_fast; | 2482 | lacp_fast = bond->params.lacp_fast; |
2522 | bond_for_each_slave(bond, slave) { | 2483 | bond_for_each_slave(bond, slave, iter) { |
2523 | port = &(SLAVE_AD_INFO(slave).port); | 2484 | port = &(SLAVE_AD_INFO(slave).port); |
2524 | __get_state_machine_lock(port); | 2485 | __get_state_machine_lock(port); |
2525 | if (lacp_fast) | 2486 | if (lacp_fast) |
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index f428ef574372..e96041816b5b 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c | |||
@@ -223,13 +223,14 @@ static long long compute_gap(struct slave *slave) | |||
223 | static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) | 223 | static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) |
224 | { | 224 | { |
225 | struct slave *slave, *least_loaded; | 225 | struct slave *slave, *least_loaded; |
226 | struct list_head *iter; | ||
226 | long long max_gap; | 227 | long long max_gap; |
227 | 228 | ||
228 | least_loaded = NULL; | 229 | least_loaded = NULL; |
229 | max_gap = LLONG_MIN; | 230 | max_gap = LLONG_MIN; |
230 | 231 | ||
231 | /* Find the slave with the largest gap */ | 232 | /* Find the slave with the largest gap */ |
232 | bond_for_each_slave(bond, slave) { | 233 | bond_for_each_slave(bond, slave, iter) { |
233 | if (SLAVE_IS_OK(slave)) { | 234 | if (SLAVE_IS_OK(slave)) { |
234 | long long gap = compute_gap(slave); | 235 | long long gap = compute_gap(slave); |
235 | 236 | ||
@@ -382,30 +383,31 @@ out: | |||
382 | static struct slave *rlb_next_rx_slave(struct bonding *bond) | 383 | static struct slave *rlb_next_rx_slave(struct bonding *bond) |
383 | { | 384 | { |
384 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); | 385 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
385 | struct slave *rx_slave, *slave, *start_at; | 386 | struct slave *before = NULL, *rx_slave = NULL, *slave; |
386 | int i = 0; | 387 | struct list_head *iter; |
387 | 388 | bool found = false; | |
388 | if (bond_info->next_rx_slave) | ||
389 | start_at = bond_info->next_rx_slave; | ||
390 | else | ||
391 | start_at = bond_first_slave(bond); | ||
392 | |||
393 | rx_slave = NULL; | ||
394 | 389 | ||
395 | bond_for_each_slave_from(bond, slave, i, start_at) { | 390 | bond_for_each_slave(bond, slave, iter) { |
396 | if (SLAVE_IS_OK(slave)) { | 391 | if (!SLAVE_IS_OK(slave)) |
397 | if (!rx_slave) { | 392 | continue; |
398 | rx_slave = slave; | 393 | if (!found) { |
399 | } else if (slave->speed > rx_slave->speed) { | 394 | if (!before || before->speed < slave->speed) |
395 | before = slave; | ||
396 | } else { | ||
397 | if (!rx_slave || rx_slave->speed < slave->speed) | ||
400 | rx_slave = slave; | 398 | rx_slave = slave; |
401 | } | ||
402 | } | 399 | } |
400 | if (slave == bond_info->rx_slave) | ||
401 | found = true; | ||
403 | } | 402 | } |
403 | /* we didn't find anything after the current or we have something | ||
404 | * better before and up to the current slave | ||
405 | */ | ||
406 | if (!rx_slave || (before && rx_slave->speed < before->speed)) | ||
407 | rx_slave = before; | ||
404 | 408 | ||
405 | if (rx_slave) { | 409 | if (rx_slave) |
406 | slave = bond_next_slave(bond, rx_slave); | 410 | bond_info->rx_slave = rx_slave; |
407 | bond_info->next_rx_slave = slave; | ||
408 | } | ||
409 | 411 | ||
410 | return rx_slave; | 412 | return rx_slave; |
411 | } | 413 | } |
@@ -1019,7 +1021,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[]) | |||
1019 | 1021 | ||
1020 | /* loop through vlans and send one packet for each */ | 1022 | /* loop through vlans and send one packet for each */ |
1021 | rcu_read_lock(); | 1023 | rcu_read_lock(); |
1022 | netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) { | 1024 | netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) { |
1023 | if (upper->priv_flags & IFF_802_1Q_VLAN) | 1025 | if (upper->priv_flags & IFF_802_1Q_VLAN) |
1024 | alb_send_lp_vid(slave, mac_addr, | 1026 | alb_send_lp_vid(slave, mac_addr, |
1025 | vlan_dev_vlan_id(upper)); | 1027 | vlan_dev_vlan_id(upper)); |
@@ -1172,10 +1174,11 @@ static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *sla | |||
1172 | */ | 1174 | */ |
1173 | static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave) | 1175 | static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave) |
1174 | { | 1176 | { |
1175 | struct slave *tmp_slave1, *free_mac_slave = NULL; | ||
1176 | struct slave *has_bond_addr = bond->curr_active_slave; | 1177 | struct slave *has_bond_addr = bond->curr_active_slave; |
1178 | struct slave *tmp_slave1, *free_mac_slave = NULL; | ||
1179 | struct list_head *iter; | ||
1177 | 1180 | ||
1178 | if (list_empty(&bond->slave_list)) { | 1181 | if (!bond_has_slaves(bond)) { |
1179 | /* this is the first slave */ | 1182 | /* this is the first slave */ |
1180 | return 0; | 1183 | return 0; |
1181 | } | 1184 | } |
@@ -1196,7 +1199,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav | |||
1196 | /* The slave's address is equal to the address of the bond. | 1199 | /* The slave's address is equal to the address of the bond. |
1197 | * Search for a spare address in the bond for this slave. | 1200 | * Search for a spare address in the bond for this slave. |
1198 | */ | 1201 | */ |
1199 | bond_for_each_slave(bond, tmp_slave1) { | 1202 | bond_for_each_slave(bond, tmp_slave1, iter) { |
1200 | if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) { | 1203 | if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) { |
1201 | /* no slave has tmp_slave1's perm addr | 1204 | /* no slave has tmp_slave1's perm addr |
1202 | * as its curr addr | 1205 | * as its curr addr |
@@ -1246,15 +1249,16 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav | |||
1246 | */ | 1249 | */ |
1247 | static int alb_set_mac_address(struct bonding *bond, void *addr) | 1250 | static int alb_set_mac_address(struct bonding *bond, void *addr) |
1248 | { | 1251 | { |
1249 | char tmp_addr[ETH_ALEN]; | 1252 | struct slave *slave, *rollback_slave; |
1250 | struct slave *slave; | 1253 | struct list_head *iter; |
1251 | struct sockaddr sa; | 1254 | struct sockaddr sa; |
1255 | char tmp_addr[ETH_ALEN]; | ||
1252 | int res; | 1256 | int res; |
1253 | 1257 | ||
1254 | if (bond->alb_info.rlb_enabled) | 1258 | if (bond->alb_info.rlb_enabled) |
1255 | return 0; | 1259 | return 0; |
1256 | 1260 | ||
1257 | bond_for_each_slave(bond, slave) { | 1261 | bond_for_each_slave(bond, slave, iter) { |
1258 | /* save net_device's current hw address */ | 1262 | /* save net_device's current hw address */ |
1259 | memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN); | 1263 | memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN); |
1260 | 1264 | ||
@@ -1274,10 +1278,12 @@ unwind: | |||
1274 | sa.sa_family = bond->dev->type; | 1278 | sa.sa_family = bond->dev->type; |
1275 | 1279 | ||
1276 | /* unwind from head to the slave that failed */ | 1280 | /* unwind from head to the slave that failed */ |
1277 | bond_for_each_slave_continue_reverse(bond, slave) { | 1281 | bond_for_each_slave(bond, rollback_slave, iter) { |
1278 | memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN); | 1282 | if (rollback_slave == slave) |
1279 | dev_set_mac_address(slave->dev, &sa); | 1283 | break; |
1280 | memcpy(slave->dev->dev_addr, tmp_addr, ETH_ALEN); | 1284 | memcpy(tmp_addr, rollback_slave->dev->dev_addr, ETH_ALEN); |
1285 | dev_set_mac_address(rollback_slave->dev, &sa); | ||
1286 | memcpy(rollback_slave->dev->dev_addr, tmp_addr, ETH_ALEN); | ||
1281 | } | 1287 | } |
1282 | 1288 | ||
1283 | return res; | 1289 | return res; |
@@ -1458,11 +1464,12 @@ void bond_alb_monitor(struct work_struct *work) | |||
1458 | struct bonding *bond = container_of(work, struct bonding, | 1464 | struct bonding *bond = container_of(work, struct bonding, |
1459 | alb_work.work); | 1465 | alb_work.work); |
1460 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); | 1466 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
1467 | struct list_head *iter; | ||
1461 | struct slave *slave; | 1468 | struct slave *slave; |
1462 | 1469 | ||
1463 | read_lock(&bond->lock); | 1470 | read_lock(&bond->lock); |
1464 | 1471 | ||
1465 | if (list_empty(&bond->slave_list)) { | 1472 | if (!bond_has_slaves(bond)) { |
1466 | bond_info->tx_rebalance_counter = 0; | 1473 | bond_info->tx_rebalance_counter = 0; |
1467 | bond_info->lp_counter = 0; | 1474 | bond_info->lp_counter = 0; |
1468 | goto re_arm; | 1475 | goto re_arm; |
@@ -1480,7 +1487,7 @@ void bond_alb_monitor(struct work_struct *work) | |||
1480 | */ | 1487 | */ |
1481 | read_lock(&bond->curr_slave_lock); | 1488 | read_lock(&bond->curr_slave_lock); |
1482 | 1489 | ||
1483 | bond_for_each_slave(bond, slave) | 1490 | bond_for_each_slave(bond, slave, iter) |
1484 | alb_send_learning_packets(slave, slave->dev->dev_addr); | 1491 | alb_send_learning_packets(slave, slave->dev->dev_addr); |
1485 | 1492 | ||
1486 | read_unlock(&bond->curr_slave_lock); | 1493 | read_unlock(&bond->curr_slave_lock); |
@@ -1493,7 +1500,7 @@ void bond_alb_monitor(struct work_struct *work) | |||
1493 | 1500 | ||
1494 | read_lock(&bond->curr_slave_lock); | 1501 | read_lock(&bond->curr_slave_lock); |
1495 | 1502 | ||
1496 | bond_for_each_slave(bond, slave) { | 1503 | bond_for_each_slave(bond, slave, iter) { |
1497 | tlb_clear_slave(bond, slave, 1); | 1504 | tlb_clear_slave(bond, slave, 1); |
1498 | if (slave == bond->curr_active_slave) { | 1505 | if (slave == bond->curr_active_slave) { |
1499 | SLAVE_TLB_INFO(slave).load = | 1506 | SLAVE_TLB_INFO(slave).load = |
@@ -1599,13 +1606,13 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave) | |||
1599 | */ | 1606 | */ |
1600 | void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave) | 1607 | void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave) |
1601 | { | 1608 | { |
1602 | if (!list_empty(&bond->slave_list)) | 1609 | if (bond_has_slaves(bond)) |
1603 | alb_change_hw_addr_on_detach(bond, slave); | 1610 | alb_change_hw_addr_on_detach(bond, slave); |
1604 | 1611 | ||
1605 | tlb_clear_slave(bond, slave, 0); | 1612 | tlb_clear_slave(bond, slave, 0); |
1606 | 1613 | ||
1607 | if (bond->alb_info.rlb_enabled) { | 1614 | if (bond->alb_info.rlb_enabled) { |
1608 | bond->alb_info.next_rx_slave = NULL; | 1615 | bond->alb_info.rx_slave = NULL; |
1609 | rlb_clear_slave(bond, slave); | 1616 | rlb_clear_slave(bond, slave); |
1610 | } | 1617 | } |
1611 | } | 1618 | } |
@@ -1669,7 +1676,7 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave | |||
1669 | swap_slave = bond->curr_active_slave; | 1676 | swap_slave = bond->curr_active_slave; |
1670 | rcu_assign_pointer(bond->curr_active_slave, new_slave); | 1677 | rcu_assign_pointer(bond->curr_active_slave, new_slave); |
1671 | 1678 | ||
1672 | if (!new_slave || list_empty(&bond->slave_list)) | 1679 | if (!new_slave || !bond_has_slaves(bond)) |
1673 | return; | 1680 | return; |
1674 | 1681 | ||
1675 | /* set the new curr_active_slave to the bonds mac address | 1682 | /* set the new curr_active_slave to the bonds mac address |
diff --git a/drivers/net/bonding/bond_alb.h b/drivers/net/bonding/bond_alb.h index c5eff5dafdfe..4226044efd08 100644 --- a/drivers/net/bonding/bond_alb.h +++ b/drivers/net/bonding/bond_alb.h | |||
@@ -154,9 +154,7 @@ struct alb_bond_info { | |||
154 | u8 rx_ntt; /* flag - need to transmit | 154 | u8 rx_ntt; /* flag - need to transmit |
155 | * to all rx clients | 155 | * to all rx clients |
156 | */ | 156 | */ |
157 | struct slave *next_rx_slave;/* next slave to be assigned | 157 | struct slave *rx_slave;/* last slave to xmit from */ |
158 | * to a new rx client for | ||
159 | */ | ||
160 | u8 primary_is_promisc; /* boolean */ | 158 | u8 primary_is_promisc; /* boolean */ |
161 | u32 rlb_promisc_timeout_counter;/* counts primary | 159 | u32 rlb_promisc_timeout_counter;/* counts primary |
162 | * promiscuity time | 160 | * promiscuity time |
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index e883bfe2e727..fe8a94f9d7db 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c | |||
@@ -332,10 +332,11 @@ static int bond_vlan_rx_add_vid(struct net_device *bond_dev, | |||
332 | __be16 proto, u16 vid) | 332 | __be16 proto, u16 vid) |
333 | { | 333 | { |
334 | struct bonding *bond = netdev_priv(bond_dev); | 334 | struct bonding *bond = netdev_priv(bond_dev); |
335 | struct slave *slave; | 335 | struct slave *slave, *rollback_slave; |
336 | struct list_head *iter; | ||
336 | int res; | 337 | int res; |
337 | 338 | ||
338 | bond_for_each_slave(bond, slave) { | 339 | bond_for_each_slave(bond, slave, iter) { |
339 | res = vlan_vid_add(slave->dev, proto, vid); | 340 | res = vlan_vid_add(slave->dev, proto, vid); |
340 | if (res) | 341 | if (res) |
341 | goto unwind; | 342 | goto unwind; |
@@ -344,9 +345,13 @@ static int bond_vlan_rx_add_vid(struct net_device *bond_dev, | |||
344 | return 0; | 345 | return 0; |
345 | 346 | ||
346 | unwind: | 347 | unwind: |
347 | /* unwind from the slave that failed */ | 348 | /* unwind to the slave that failed */ |
348 | bond_for_each_slave_continue_reverse(bond, slave) | 349 | bond_for_each_slave(bond, rollback_slave, iter) { |
349 | vlan_vid_del(slave->dev, proto, vid); | 350 | if (rollback_slave == slave) |
351 | break; | ||
352 | |||
353 | vlan_vid_del(rollback_slave->dev, proto, vid); | ||
354 | } | ||
350 | 355 | ||
351 | return res; | 356 | return res; |
352 | } | 357 | } |
@@ -360,9 +365,10 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev, | |||
360 | __be16 proto, u16 vid) | 365 | __be16 proto, u16 vid) |
361 | { | 366 | { |
362 | struct bonding *bond = netdev_priv(bond_dev); | 367 | struct bonding *bond = netdev_priv(bond_dev); |
368 | struct list_head *iter; | ||
363 | struct slave *slave; | 369 | struct slave *slave; |
364 | 370 | ||
365 | bond_for_each_slave(bond, slave) | 371 | bond_for_each_slave(bond, slave, iter) |
366 | vlan_vid_del(slave->dev, proto, vid); | 372 | vlan_vid_del(slave->dev, proto, vid); |
367 | 373 | ||
368 | if (bond_is_lb(bond)) | 374 | if (bond_is_lb(bond)) |
@@ -382,15 +388,16 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev, | |||
382 | */ | 388 | */ |
383 | static int bond_set_carrier(struct bonding *bond) | 389 | static int bond_set_carrier(struct bonding *bond) |
384 | { | 390 | { |
391 | struct list_head *iter; | ||
385 | struct slave *slave; | 392 | struct slave *slave; |
386 | 393 | ||
387 | if (list_empty(&bond->slave_list)) | 394 | if (!bond_has_slaves(bond)) |
388 | goto down; | 395 | goto down; |
389 | 396 | ||
390 | if (bond->params.mode == BOND_MODE_8023AD) | 397 | if (bond->params.mode == BOND_MODE_8023AD) |
391 | return bond_3ad_set_carrier(bond); | 398 | return bond_3ad_set_carrier(bond); |
392 | 399 | ||
393 | bond_for_each_slave(bond, slave) { | 400 | bond_for_each_slave(bond, slave, iter) { |
394 | if (slave->link == BOND_LINK_UP) { | 401 | if (slave->link == BOND_LINK_UP) { |
395 | if (!netif_carrier_ok(bond->dev)) { | 402 | if (!netif_carrier_ok(bond->dev)) { |
396 | netif_carrier_on(bond->dev); | 403 | netif_carrier_on(bond->dev); |
@@ -522,7 +529,9 @@ static int bond_check_dev_link(struct bonding *bond, | |||
522 | */ | 529 | */ |
523 | static int bond_set_promiscuity(struct bonding *bond, int inc) | 530 | static int bond_set_promiscuity(struct bonding *bond, int inc) |
524 | { | 531 | { |
532 | struct list_head *iter; | ||
525 | int err = 0; | 533 | int err = 0; |
534 | |||
526 | if (USES_PRIMARY(bond->params.mode)) { | 535 | if (USES_PRIMARY(bond->params.mode)) { |
527 | /* write lock already acquired */ | 536 | /* write lock already acquired */ |
528 | if (bond->curr_active_slave) { | 537 | if (bond->curr_active_slave) { |
@@ -532,7 +541,7 @@ static int bond_set_promiscuity(struct bonding *bond, int inc) | |||
532 | } else { | 541 | } else { |
533 | struct slave *slave; | 542 | struct slave *slave; |
534 | 543 | ||
535 | bond_for_each_slave(bond, slave) { | 544 | bond_for_each_slave(bond, slave, iter) { |
536 | err = dev_set_promiscuity(slave->dev, inc); | 545 | err = dev_set_promiscuity(slave->dev, inc); |
537 | if (err) | 546 | if (err) |
538 | return err; | 547 | return err; |
@@ -546,7 +555,9 @@ static int bond_set_promiscuity(struct bonding *bond, int inc) | |||
546 | */ | 555 | */ |
547 | static int bond_set_allmulti(struct bonding *bond, int inc) | 556 | static int bond_set_allmulti(struct bonding *bond, int inc) |
548 | { | 557 | { |
558 | struct list_head *iter; | ||
549 | int err = 0; | 559 | int err = 0; |
560 | |||
550 | if (USES_PRIMARY(bond->params.mode)) { | 561 | if (USES_PRIMARY(bond->params.mode)) { |
551 | /* write lock already acquired */ | 562 | /* write lock already acquired */ |
552 | if (bond->curr_active_slave) { | 563 | if (bond->curr_active_slave) { |
@@ -556,7 +567,7 @@ static int bond_set_allmulti(struct bonding *bond, int inc) | |||
556 | } else { | 567 | } else { |
557 | struct slave *slave; | 568 | struct slave *slave; |
558 | 569 | ||
559 | bond_for_each_slave(bond, slave) { | 570 | bond_for_each_slave(bond, slave, iter) { |
560 | err = dev_set_allmulti(slave->dev, inc); | 571 | err = dev_set_allmulti(slave->dev, inc); |
561 | if (err) | 572 | if (err) |
562 | return err; | 573 | return err; |
@@ -774,43 +785,24 @@ static bool bond_should_change_active(struct bonding *bond) | |||
774 | /** | 785 | /** |
775 | * 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 |
776 | * @bond: our bonding struct | 787 | * @bond: our bonding struct |
777 | * | ||
778 | * Warning: Caller must hold curr_slave_lock for writing. | ||
779 | */ | 788 | */ |
780 | static struct slave *bond_find_best_slave(struct bonding *bond) | 789 | static struct slave *bond_find_best_slave(struct bonding *bond) |
781 | { | 790 | { |
782 | struct slave *new_active, *old_active; | 791 | struct slave *slave, *bestslave = NULL; |
783 | struct slave *bestslave = NULL; | 792 | struct list_head *iter; |
784 | int mintime = bond->params.updelay; | 793 | int mintime = bond->params.updelay; |
785 | int i; | ||
786 | |||
787 | new_active = bond->curr_active_slave; | ||
788 | |||
789 | if (!new_active) { /* there were no active slaves left */ | ||
790 | new_active = bond_first_slave(bond); | ||
791 | if (!new_active) | ||
792 | return NULL; /* still no slave, return NULL */ | ||
793 | } | ||
794 | |||
795 | if ((bond->primary_slave) && | ||
796 | bond->primary_slave->link == BOND_LINK_UP && | ||
797 | bond_should_change_active(bond)) { | ||
798 | new_active = bond->primary_slave; | ||
799 | } | ||
800 | 794 | ||
801 | /* remember where to stop iterating over the slaves */ | 795 | if (bond->primary_slave && bond->primary_slave->link == BOND_LINK_UP && |
802 | old_active = new_active; | 796 | bond_should_change_active(bond)) |
803 | 797 | return bond->primary_slave; | |
804 | bond_for_each_slave_from(bond, new_active, i, old_active) { | 798 | |
805 | if (new_active->link == BOND_LINK_UP) { | 799 | bond_for_each_slave(bond, slave, iter) { |
806 | return new_active; | 800 | if (slave->link == BOND_LINK_UP) |
807 | } else if (new_active->link == BOND_LINK_BACK && | 801 | return slave; |
808 | IS_UP(new_active->dev)) { | 802 | if (slave->link == BOND_LINK_BACK && IS_UP(slave->dev) && |
809 | /* link up, but waiting for stabilization */ | 803 | slave->delay < mintime) { |
810 | if (new_active->delay < mintime) { | 804 | mintime = slave->delay; |
811 | mintime = new_active->delay; | 805 | bestslave = slave; |
812 | bestslave = new_active; | ||
813 | } | ||
814 | } | 806 | } |
815 | } | 807 | } |
816 | 808 | ||
@@ -980,7 +972,6 @@ void bond_select_active_slave(struct bonding *bond) | |||
980 | */ | 972 | */ |
981 | static void bond_attach_slave(struct bonding *bond, struct slave *new_slave) | 973 | static void bond_attach_slave(struct bonding *bond, struct slave *new_slave) |
982 | { | 974 | { |
983 | list_add_tail_rcu(&new_slave->list, &bond->slave_list); | ||
984 | bond->slave_cnt++; | 975 | bond->slave_cnt++; |
985 | } | 976 | } |
986 | 977 | ||
@@ -996,7 +987,6 @@ static void bond_attach_slave(struct bonding *bond, struct slave *new_slave) | |||
996 | */ | 987 | */ |
997 | static void bond_detach_slave(struct bonding *bond, struct slave *slave) | 988 | static void bond_detach_slave(struct bonding *bond, struct slave *slave) |
998 | { | 989 | { |
999 | list_del_rcu(&slave->list); | ||
1000 | bond->slave_cnt--; | 990 | bond->slave_cnt--; |
1001 | } | 991 | } |
1002 | 992 | ||
@@ -1046,9 +1036,10 @@ static void bond_poll_controller(struct net_device *bond_dev) | |||
1046 | static void bond_netpoll_cleanup(struct net_device *bond_dev) | 1036 | static void bond_netpoll_cleanup(struct net_device *bond_dev) |
1047 | { | 1037 | { |
1048 | struct bonding *bond = netdev_priv(bond_dev); | 1038 | struct bonding *bond = netdev_priv(bond_dev); |
1039 | struct list_head *iter; | ||
1049 | struct slave *slave; | 1040 | struct slave *slave; |
1050 | 1041 | ||
1051 | bond_for_each_slave(bond, slave) | 1042 | bond_for_each_slave(bond, slave, iter) |
1052 | if (IS_UP(slave->dev)) | 1043 | if (IS_UP(slave->dev)) |
1053 | slave_disable_netpoll(slave); | 1044 | slave_disable_netpoll(slave); |
1054 | } | 1045 | } |
@@ -1056,10 +1047,11 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev) | |||
1056 | static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni, gfp_t gfp) | 1047 | static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni, gfp_t gfp) |
1057 | { | 1048 | { |
1058 | struct bonding *bond = netdev_priv(dev); | 1049 | struct bonding *bond = netdev_priv(dev); |
1050 | struct list_head *iter; | ||
1059 | struct slave *slave; | 1051 | struct slave *slave; |
1060 | int err = 0; | 1052 | int err = 0; |
1061 | 1053 | ||
1062 | bond_for_each_slave(bond, slave) { | 1054 | bond_for_each_slave(bond, slave, iter) { |
1063 | err = slave_enable_netpoll(slave); | 1055 | err = slave_enable_netpoll(slave); |
1064 | if (err) { | 1056 | if (err) { |
1065 | bond_netpoll_cleanup(dev); | 1057 | bond_netpoll_cleanup(dev); |
@@ -1087,10 +1079,11 @@ static netdev_features_t bond_fix_features(struct net_device *dev, | |||
1087 | netdev_features_t features) | 1079 | netdev_features_t features) |
1088 | { | 1080 | { |
1089 | struct bonding *bond = netdev_priv(dev); | 1081 | struct bonding *bond = netdev_priv(dev); |
1082 | struct list_head *iter; | ||
1090 | netdev_features_t mask; | 1083 | netdev_features_t mask; |
1091 | struct slave *slave; | 1084 | struct slave *slave; |
1092 | 1085 | ||
1093 | if (list_empty(&bond->slave_list)) { | 1086 | if (!bond_has_slaves(bond)) { |
1094 | /* Disable adding VLANs to empty bond. But why? --mq */ | 1087 | /* Disable adding VLANs to empty bond. But why? --mq */ |
1095 | features |= NETIF_F_VLAN_CHALLENGED; | 1088 | features |= NETIF_F_VLAN_CHALLENGED; |
1096 | return features; | 1089 | return features; |
@@ -1100,7 +1093,7 @@ static netdev_features_t bond_fix_features(struct net_device *dev, | |||
1100 | features &= ~NETIF_F_ONE_FOR_ALL; | 1093 | features &= ~NETIF_F_ONE_FOR_ALL; |
1101 | features |= NETIF_F_ALL_FOR_ALL; | 1094 | features |= NETIF_F_ALL_FOR_ALL; |
1102 | 1095 | ||
1103 | bond_for_each_slave(bond, slave) { | 1096 | bond_for_each_slave(bond, slave, iter) { |
1104 | features = netdev_increment_features(features, | 1097 | features = netdev_increment_features(features, |
1105 | slave->dev->features, | 1098 | slave->dev->features, |
1106 | mask); | 1099 | mask); |
@@ -1118,16 +1111,17 @@ static void bond_compute_features(struct bonding *bond) | |||
1118 | { | 1111 | { |
1119 | unsigned int flags, dst_release_flag = IFF_XMIT_DST_RELEASE; | 1112 | unsigned int flags, dst_release_flag = IFF_XMIT_DST_RELEASE; |
1120 | netdev_features_t vlan_features = BOND_VLAN_FEATURES; | 1113 | netdev_features_t vlan_features = BOND_VLAN_FEATURES; |
1114 | struct net_device *bond_dev = bond->dev; | ||
1115 | struct list_head *iter; | ||
1116 | struct slave *slave; | ||
1121 | unsigned short max_hard_header_len = ETH_HLEN; | 1117 | unsigned short max_hard_header_len = ETH_HLEN; |
1122 | unsigned int gso_max_size = GSO_MAX_SIZE; | 1118 | unsigned int gso_max_size = GSO_MAX_SIZE; |
1123 | struct net_device *bond_dev = bond->dev; | ||
1124 | u16 gso_max_segs = GSO_MAX_SEGS; | 1119 | u16 gso_max_segs = GSO_MAX_SEGS; |
1125 | struct slave *slave; | ||
1126 | 1120 | ||
1127 | if (list_empty(&bond->slave_list)) | 1121 | if (!bond_has_slaves(bond)) |
1128 | goto done; | 1122 | goto done; |
1129 | 1123 | ||
1130 | bond_for_each_slave(bond, slave) { | 1124 | bond_for_each_slave(bond, slave, iter) { |
1131 | vlan_features = netdev_increment_features(vlan_features, | 1125 | vlan_features = netdev_increment_features(vlan_features, |
1132 | slave->dev->vlan_features, BOND_VLAN_FEATURES); | 1126 | slave->dev->vlan_features, BOND_VLAN_FEATURES); |
1133 | 1127 | ||
@@ -1233,11 +1227,12 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb) | |||
1233 | } | 1227 | } |
1234 | 1228 | ||
1235 | static int bond_master_upper_dev_link(struct net_device *bond_dev, | 1229 | static int bond_master_upper_dev_link(struct net_device *bond_dev, |
1236 | struct net_device *slave_dev) | 1230 | struct net_device *slave_dev, |
1231 | struct slave *slave) | ||
1237 | { | 1232 | { |
1238 | int err; | 1233 | int err; |
1239 | 1234 | ||
1240 | err = netdev_master_upper_dev_link(slave_dev, bond_dev); | 1235 | err = netdev_master_upper_dev_link_private(slave_dev, bond_dev, slave); |
1241 | if (err) | 1236 | if (err) |
1242 | return err; | 1237 | return err; |
1243 | slave_dev->flags |= IFF_SLAVE; | 1238 | slave_dev->flags |= IFF_SLAVE; |
@@ -1258,7 +1253,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1258 | { | 1253 | { |
1259 | struct bonding *bond = netdev_priv(bond_dev); | 1254 | struct bonding *bond = netdev_priv(bond_dev); |
1260 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; | 1255 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
1261 | struct slave *new_slave = NULL; | 1256 | struct slave *new_slave = NULL, *prev_slave; |
1262 | struct sockaddr addr; | 1257 | struct sockaddr addr; |
1263 | int link_reporting; | 1258 | int link_reporting; |
1264 | int res = 0, i; | 1259 | int res = 0, i; |
@@ -1313,7 +1308,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1313 | * bond ether type mutual exclusion - don't allow slaves of dissimilar | 1308 | * bond ether type mutual exclusion - don't allow slaves of dissimilar |
1314 | * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond | 1309 | * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond |
1315 | */ | 1310 | */ |
1316 | if (list_empty(&bond->slave_list)) { | 1311 | if (!bond_has_slaves(bond)) { |
1317 | if (bond_dev->type != slave_dev->type) { | 1312 | if (bond_dev->type != slave_dev->type) { |
1318 | pr_debug("%s: change device type from %d to %d\n", | 1313 | pr_debug("%s: change device type from %d to %d\n", |
1319 | bond_dev->name, | 1314 | bond_dev->name, |
@@ -1352,7 +1347,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1352 | } | 1347 | } |
1353 | 1348 | ||
1354 | if (slave_ops->ndo_set_mac_address == NULL) { | 1349 | if (slave_ops->ndo_set_mac_address == NULL) { |
1355 | if (list_empty(&bond->slave_list)) { | 1350 | if (!bond_has_slaves(bond)) { |
1356 | pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.", | 1351 | pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.", |
1357 | bond_dev->name); | 1352 | bond_dev->name); |
1358 | bond->params.fail_over_mac = BOND_FOM_ACTIVE; | 1353 | bond->params.fail_over_mac = BOND_FOM_ACTIVE; |
@@ -1368,7 +1363,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1368 | 1363 | ||
1369 | /* If this is the first slave, then we need to set the master's hardware | 1364 | /* If this is the first slave, then we need to set the master's hardware |
1370 | * address to be the same as the slave's. */ | 1365 | * address to be the same as the slave's. */ |
1371 | if (list_empty(&bond->slave_list) && | 1366 | if (!bond_has_slaves(bond) && |
1372 | bond->dev->addr_assign_type == NET_ADDR_RANDOM) | 1367 | bond->dev->addr_assign_type == NET_ADDR_RANDOM) |
1373 | bond_set_dev_addr(bond->dev, slave_dev); | 1368 | bond_set_dev_addr(bond->dev, slave_dev); |
1374 | 1369 | ||
@@ -1377,7 +1372,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1377 | res = -ENOMEM; | 1372 | res = -ENOMEM; |
1378 | goto err_undo_flags; | 1373 | goto err_undo_flags; |
1379 | } | 1374 | } |
1380 | INIT_LIST_HEAD(&new_slave->list); | ||
1381 | /* | 1375 | /* |
1382 | * Set the new_slave's queue_id to be zero. Queue ID mapping | 1376 | * Set the new_slave's queue_id to be zero. Queue ID mapping |
1383 | * is set via sysfs or module option if desired. | 1377 | * is set via sysfs or module option if desired. |
@@ -1413,17 +1407,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1413 | } | 1407 | } |
1414 | } | 1408 | } |
1415 | 1409 | ||
1416 | res = bond_master_upper_dev_link(bond_dev, slave_dev); | ||
1417 | if (res) { | ||
1418 | pr_debug("Error %d calling bond_master_upper_dev_link\n", res); | ||
1419 | goto err_restore_mac; | ||
1420 | } | ||
1421 | |||
1422 | /* open the slave since the application closed it */ | 1410 | /* open the slave since the application closed it */ |
1423 | res = dev_open(slave_dev); | 1411 | res = dev_open(slave_dev); |
1424 | if (res) { | 1412 | if (res) { |
1425 | pr_debug("Opening slave %s failed\n", slave_dev->name); | 1413 | pr_debug("Opening slave %s failed\n", slave_dev->name); |
1426 | goto err_unset_master; | 1414 | goto err_restore_mac; |
1427 | } | 1415 | } |
1428 | 1416 | ||
1429 | new_slave->bond = bond; | 1417 | new_slave->bond = bond; |
@@ -1481,6 +1469,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1481 | 1469 | ||
1482 | write_lock_bh(&bond->lock); | 1470 | write_lock_bh(&bond->lock); |
1483 | 1471 | ||
1472 | prev_slave = bond_last_slave(bond); | ||
1484 | bond_attach_slave(bond, new_slave); | 1473 | bond_attach_slave(bond, new_slave); |
1485 | 1474 | ||
1486 | new_slave->delay = 0; | 1475 | new_slave->delay = 0; |
@@ -1568,16 +1557,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1568 | */ | 1557 | */ |
1569 | bond_set_slave_inactive_flags(new_slave); | 1558 | bond_set_slave_inactive_flags(new_slave); |
1570 | /* if this is the first slave */ | 1559 | /* if this is the first slave */ |
1571 | if (bond_first_slave(bond) == new_slave) { | 1560 | if (!prev_slave) { |
1572 | SLAVE_AD_INFO(new_slave).id = 1; | 1561 | SLAVE_AD_INFO(new_slave).id = 1; |
1573 | /* Initialize AD with the number of times that the AD timer is called in 1 second | 1562 | /* Initialize AD with the number of times that the AD timer is called in 1 second |
1574 | * can be called only after the mac address of the bond is set | 1563 | * can be called only after the mac address of the bond is set |
1575 | */ | 1564 | */ |
1576 | bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL); | 1565 | bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL); |
1577 | } else { | 1566 | } else { |
1578 | struct slave *prev_slave; | ||
1579 | |||
1580 | prev_slave = bond_prev_slave(bond, new_slave); | ||
1581 | SLAVE_AD_INFO(new_slave).id = | 1567 | SLAVE_AD_INFO(new_slave).id = |
1582 | SLAVE_AD_INFO(prev_slave).id + 1; | 1568 | SLAVE_AD_INFO(prev_slave).id + 1; |
1583 | } | 1569 | } |
@@ -1626,17 +1612,20 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1626 | 1612 | ||
1627 | read_unlock(&bond->lock); | 1613 | read_unlock(&bond->lock); |
1628 | 1614 | ||
1629 | res = bond_create_slave_symlinks(bond_dev, slave_dev); | ||
1630 | if (res) | ||
1631 | goto err_detach; | ||
1632 | |||
1633 | res = netdev_rx_handler_register(slave_dev, bond_handle_frame, | 1615 | res = netdev_rx_handler_register(slave_dev, bond_handle_frame, |
1634 | new_slave); | 1616 | new_slave); |
1635 | if (res) { | 1617 | if (res) { |
1636 | pr_debug("Error %d calling netdev_rx_handler_register\n", res); | 1618 | pr_debug("Error %d calling netdev_rx_handler_register\n", res); |
1637 | goto err_dest_symlinks; | 1619 | goto err_detach; |
1638 | } | 1620 | } |
1639 | 1621 | ||
1622 | res = bond_master_upper_dev_link(bond_dev, slave_dev, new_slave); | ||
1623 | if (res) { | ||
1624 | pr_debug("Error %d calling bond_master_upper_dev_link\n", res); | ||
1625 | goto err_unregister; | ||
1626 | } | ||
1627 | |||
1628 | |||
1640 | pr_info("%s: enslaving %s as a%s interface with a%s link.\n", | 1629 | pr_info("%s: enslaving %s as a%s interface with a%s link.\n", |
1641 | bond_dev->name, slave_dev->name, | 1630 | bond_dev->name, slave_dev->name, |
1642 | bond_is_active_slave(new_slave) ? "n active" : " backup", | 1631 | bond_is_active_slave(new_slave) ? "n active" : " backup", |
@@ -1646,8 +1635,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
1646 | return 0; | 1635 | return 0; |
1647 | 1636 | ||
1648 | /* Undo stages on error */ | 1637 | /* Undo stages on error */ |
1649 | err_dest_symlinks: | 1638 | err_unregister: |
1650 | bond_destroy_slave_symlinks(bond_dev, slave_dev); | 1639 | netdev_rx_handler_unregister(slave_dev); |
1651 | 1640 | ||
1652 | err_detach: | 1641 | err_detach: |
1653 | if (!USES_PRIMARY(bond->params.mode)) | 1642 | if (!USES_PRIMARY(bond->params.mode)) |
@@ -1675,9 +1664,6 @@ err_close: | |||
1675 | slave_dev->priv_flags &= ~IFF_BONDING; | 1664 | slave_dev->priv_flags &= ~IFF_BONDING; |
1676 | dev_close(slave_dev); | 1665 | dev_close(slave_dev); |
1677 | 1666 | ||
1678 | err_unset_master: | ||
1679 | bond_upper_dev_unlink(bond_dev, slave_dev); | ||
1680 | |||
1681 | err_restore_mac: | 1667 | err_restore_mac: |
1682 | if (!bond->params.fail_over_mac) { | 1668 | if (!bond->params.fail_over_mac) { |
1683 | /* XXX TODO - fom follow mode needs to change master's | 1669 | /* XXX TODO - fom follow mode needs to change master's |
@@ -1698,7 +1684,7 @@ err_free: | |||
1698 | err_undo_flags: | 1684 | err_undo_flags: |
1699 | bond_compute_features(bond); | 1685 | bond_compute_features(bond); |
1700 | /* Enslave of first slave has failed and we need to fix master's mac */ | 1686 | /* Enslave of first slave has failed and we need to fix master's mac */ |
1701 | if (list_empty(&bond->slave_list) && | 1687 | if (!bond_has_slaves(bond) && |
1702 | ether_addr_equal(bond_dev->dev_addr, slave_dev->dev_addr)) | 1688 | ether_addr_equal(bond_dev->dev_addr, slave_dev->dev_addr)) |
1703 | eth_hw_addr_random(bond_dev); | 1689 | eth_hw_addr_random(bond_dev); |
1704 | 1690 | ||
@@ -1749,6 +1735,8 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
1749 | } | 1735 | } |
1750 | 1736 | ||
1751 | write_unlock_bh(&bond->lock); | 1737 | write_unlock_bh(&bond->lock); |
1738 | |||
1739 | bond_upper_dev_unlink(bond_dev, slave_dev); | ||
1752 | /* unregister rx_handler early so bond_handle_frame wouldn't be called | 1740 | /* unregister rx_handler early so bond_handle_frame wouldn't be called |
1753 | * for this slave anymore. | 1741 | * for this slave anymore. |
1754 | */ | 1742 | */ |
@@ -1777,7 +1765,7 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
1777 | 1765 | ||
1778 | if (!all && !bond->params.fail_over_mac) { | 1766 | if (!all && !bond->params.fail_over_mac) { |
1779 | if (ether_addr_equal(bond_dev->dev_addr, slave->perm_hwaddr) && | 1767 | if (ether_addr_equal(bond_dev->dev_addr, slave->perm_hwaddr) && |
1780 | !list_empty(&bond->slave_list)) | 1768 | bond_has_slaves(bond)) |
1781 | pr_warn("%s: Warning: the permanent HWaddr of %s - %pM - is still in use by %s. Set the HWaddr of %s to a different address to avoid conflicts.\n", | 1769 | pr_warn("%s: Warning: the permanent HWaddr of %s - %pM - is still in use by %s. Set the HWaddr of %s to a different address to avoid conflicts.\n", |
1782 | bond_dev->name, slave_dev->name, | 1770 | bond_dev->name, slave_dev->name, |
1783 | slave->perm_hwaddr, | 1771 | slave->perm_hwaddr, |
@@ -1820,7 +1808,7 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
1820 | write_lock_bh(&bond->lock); | 1808 | write_lock_bh(&bond->lock); |
1821 | } | 1809 | } |
1822 | 1810 | ||
1823 | if (list_empty(&bond->slave_list)) { | 1811 | if (!bond_has_slaves(bond)) { |
1824 | bond_set_carrier(bond); | 1812 | bond_set_carrier(bond); |
1825 | eth_hw_addr_random(bond_dev); | 1813 | eth_hw_addr_random(bond_dev); |
1826 | 1814 | ||
@@ -1836,7 +1824,7 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
1836 | unblock_netpoll_tx(); | 1824 | unblock_netpoll_tx(); |
1837 | synchronize_rcu(); | 1825 | synchronize_rcu(); |
1838 | 1826 | ||
1839 | if (list_empty(&bond->slave_list)) { | 1827 | if (!bond_has_slaves(bond)) { |
1840 | call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev); | 1828 | call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev); |
1841 | call_netdevice_notifiers(NETDEV_RELEASE, bond->dev); | 1829 | call_netdevice_notifiers(NETDEV_RELEASE, bond->dev); |
1842 | } | 1830 | } |
@@ -1848,8 +1836,6 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
1848 | bond_dev->name, slave_dev->name, bond_dev->name); | 1836 | bond_dev->name, slave_dev->name, bond_dev->name); |
1849 | 1837 | ||
1850 | /* must do this from outside any spinlocks */ | 1838 | /* must do this from outside any spinlocks */ |
1851 | bond_destroy_slave_symlinks(bond_dev, slave_dev); | ||
1852 | |||
1853 | vlan_vids_del_by_dev(slave_dev, bond_dev); | 1839 | vlan_vids_del_by_dev(slave_dev, bond_dev); |
1854 | 1840 | ||
1855 | /* If the mode USES_PRIMARY, then this cases was handled above by | 1841 | /* If the mode USES_PRIMARY, then this cases was handled above by |
@@ -1873,8 +1859,6 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
1873 | bond_hw_addr_flush(bond_dev, slave_dev); | 1859 | bond_hw_addr_flush(bond_dev, slave_dev); |
1874 | } | 1860 | } |
1875 | 1861 | ||
1876 | bond_upper_dev_unlink(bond_dev, slave_dev); | ||
1877 | |||
1878 | slave_disable_netpoll(slave); | 1862 | slave_disable_netpoll(slave); |
1879 | 1863 | ||
1880 | /* close slave before restoring its mac address */ | 1864 | /* close slave before restoring its mac address */ |
@@ -1913,7 +1897,7 @@ static int bond_release_and_destroy(struct net_device *bond_dev, | |||
1913 | int ret; | 1897 | int ret; |
1914 | 1898 | ||
1915 | ret = bond_release(bond_dev, slave_dev); | 1899 | ret = bond_release(bond_dev, slave_dev); |
1916 | if (ret == 0 && list_empty(&bond->slave_list)) { | 1900 | if (ret == 0 && !bond_has_slaves(bond)) { |
1917 | bond_dev->priv_flags |= IFF_DISABLE_NETPOLL; | 1901 | bond_dev->priv_flags |= IFF_DISABLE_NETPOLL; |
1918 | pr_info("%s: destroying bond %s.\n", | 1902 | pr_info("%s: destroying bond %s.\n", |
1919 | bond_dev->name, bond_dev->name); | 1903 | bond_dev->name, bond_dev->name); |
@@ -1994,11 +1978,12 @@ static int bond_info_query(struct net_device *bond_dev, struct ifbond *info) | |||
1994 | static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info) | 1978 | static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info) |
1995 | { | 1979 | { |
1996 | struct bonding *bond = netdev_priv(bond_dev); | 1980 | struct bonding *bond = netdev_priv(bond_dev); |
1981 | struct list_head *iter; | ||
1997 | int i = 0, res = -ENODEV; | 1982 | int i = 0, res = -ENODEV; |
1998 | struct slave *slave; | 1983 | struct slave *slave; |
1999 | 1984 | ||
2000 | read_lock(&bond->lock); | 1985 | read_lock(&bond->lock); |
2001 | bond_for_each_slave(bond, slave) { | 1986 | bond_for_each_slave(bond, slave, iter) { |
2002 | if (i++ == (int)info->slave_id) { | 1987 | if (i++ == (int)info->slave_id) { |
2003 | res = 0; | 1988 | res = 0; |
2004 | strcpy(info->slave_name, slave->dev->name); | 1989 | strcpy(info->slave_name, slave->dev->name); |
@@ -2019,12 +2004,13 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in | |||
2019 | static int bond_miimon_inspect(struct bonding *bond) | 2004 | static int bond_miimon_inspect(struct bonding *bond) |
2020 | { | 2005 | { |
2021 | int link_state, commit = 0; | 2006 | int link_state, commit = 0; |
2007 | struct list_head *iter; | ||
2022 | struct slave *slave; | 2008 | struct slave *slave; |
2023 | bool ignore_updelay; | 2009 | bool ignore_updelay; |
2024 | 2010 | ||
2025 | ignore_updelay = !bond->curr_active_slave ? true : false; | 2011 | ignore_updelay = !bond->curr_active_slave ? true : false; |
2026 | 2012 | ||
2027 | bond_for_each_slave(bond, slave) { | 2013 | bond_for_each_slave(bond, slave, iter) { |
2028 | slave->new_link = BOND_LINK_NOCHANGE; | 2014 | slave->new_link = BOND_LINK_NOCHANGE; |
2029 | 2015 | ||
2030 | link_state = bond_check_dev_link(bond, slave->dev, 0); | 2016 | link_state = bond_check_dev_link(bond, slave->dev, 0); |
@@ -2118,9 +2104,10 @@ static int bond_miimon_inspect(struct bonding *bond) | |||
2118 | 2104 | ||
2119 | static void bond_miimon_commit(struct bonding *bond) | 2105 | static void bond_miimon_commit(struct bonding *bond) |
2120 | { | 2106 | { |
2107 | struct list_head *iter; | ||
2121 | struct slave *slave; | 2108 | struct slave *slave; |
2122 | 2109 | ||
2123 | bond_for_each_slave(bond, slave) { | 2110 | bond_for_each_slave(bond, slave, iter) { |
2124 | switch (slave->new_link) { | 2111 | switch (slave->new_link) { |
2125 | case BOND_LINK_NOCHANGE: | 2112 | case BOND_LINK_NOCHANGE: |
2126 | continue; | 2113 | continue; |
@@ -2225,7 +2212,7 @@ void bond_mii_monitor(struct work_struct *work) | |||
2225 | 2212 | ||
2226 | delay = msecs_to_jiffies(bond->params.miimon); | 2213 | delay = msecs_to_jiffies(bond->params.miimon); |
2227 | 2214 | ||
2228 | if (list_empty(&bond->slave_list)) | 2215 | if (!bond_has_slaves(bond)) |
2229 | goto re_arm; | 2216 | goto re_arm; |
2230 | 2217 | ||
2231 | should_notify_peers = bond_should_notify_peers(bond); | 2218 | should_notify_peers = bond_should_notify_peers(bond); |
@@ -2274,7 +2261,7 @@ static bool bond_has_this_ip(struct bonding *bond, __be32 ip) | |||
2274 | return true; | 2261 | return true; |
2275 | 2262 | ||
2276 | rcu_read_lock(); | 2263 | rcu_read_lock(); |
2277 | netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) { | 2264 | netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) { |
2278 | if (ip == bond_confirm_addr(upper, 0, ip)) { | 2265 | if (ip == bond_confirm_addr(upper, 0, ip)) { |
2279 | ret = true; | 2266 | ret = true; |
2280 | break; | 2267 | break; |
@@ -2349,10 +2336,12 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave) | |||
2349 | * | 2336 | * |
2350 | * TODO: QinQ? | 2337 | * TODO: QinQ? |
2351 | */ | 2338 | */ |
2352 | netdev_for_each_upper_dev_rcu(bond->dev, vlan_upper, vlan_iter) { | 2339 | netdev_for_each_all_upper_dev_rcu(bond->dev, vlan_upper, |
2340 | vlan_iter) { | ||
2353 | if (!is_vlan_dev(vlan_upper)) | 2341 | if (!is_vlan_dev(vlan_upper)) |
2354 | continue; | 2342 | continue; |
2355 | netdev_for_each_upper_dev_rcu(vlan_upper, upper, iter) { | 2343 | netdev_for_each_all_upper_dev_rcu(vlan_upper, upper, |
2344 | iter) { | ||
2356 | if (upper == rt->dst.dev) { | 2345 | if (upper == rt->dst.dev) { |
2357 | vlan_id = vlan_dev_vlan_id(vlan_upper); | 2346 | vlan_id = vlan_dev_vlan_id(vlan_upper); |
2358 | rcu_read_unlock(); | 2347 | rcu_read_unlock(); |
@@ -2365,7 +2354,7 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave) | |||
2365 | * our upper vlans, then just search for any dev that | 2354 | * our upper vlans, then just search for any dev that |
2366 | * matches, and in case it's a vlan - save the id | 2355 | * matches, and in case it's a vlan - save the id |
2367 | */ | 2356 | */ |
2368 | netdev_for_each_upper_dev_rcu(bond->dev, upper, iter) { | 2357 | netdev_for_each_all_upper_dev_rcu(bond->dev, upper, iter) { |
2369 | if (upper == rt->dst.dev) { | 2358 | if (upper == rt->dst.dev) { |
2370 | /* if it's a vlan - get its VID */ | 2359 | /* if it's a vlan - get its VID */ |
2371 | if (is_vlan_dev(upper)) | 2360 | if (is_vlan_dev(upper)) |
@@ -2512,11 +2501,12 @@ void bond_loadbalance_arp_mon(struct work_struct *work) | |||
2512 | struct bonding *bond = container_of(work, struct bonding, | 2501 | struct bonding *bond = container_of(work, struct bonding, |
2513 | arp_work.work); | 2502 | arp_work.work); |
2514 | struct slave *slave, *oldcurrent; | 2503 | struct slave *slave, *oldcurrent; |
2504 | struct list_head *iter; | ||
2515 | int do_failover = 0; | 2505 | int do_failover = 0; |
2516 | 2506 | ||
2517 | read_lock(&bond->lock); | 2507 | read_lock(&bond->lock); |
2518 | 2508 | ||
2519 | if (list_empty(&bond->slave_list)) | 2509 | if (!bond_has_slaves(bond)) |
2520 | goto re_arm; | 2510 | goto re_arm; |
2521 | 2511 | ||
2522 | oldcurrent = bond->curr_active_slave; | 2512 | oldcurrent = bond->curr_active_slave; |
@@ -2528,7 +2518,7 @@ void bond_loadbalance_arp_mon(struct work_struct *work) | |||
2528 | * TODO: what about up/down delay in arp mode? it wasn't here before | 2518 | * TODO: what about up/down delay in arp mode? it wasn't here before |
2529 | * so it can wait | 2519 | * so it can wait |
2530 | */ | 2520 | */ |
2531 | bond_for_each_slave(bond, slave) { | 2521 | bond_for_each_slave(bond, slave, iter) { |
2532 | unsigned long trans_start = dev_trans_start(slave->dev); | 2522 | unsigned long trans_start = dev_trans_start(slave->dev); |
2533 | 2523 | ||
2534 | if (slave->link != BOND_LINK_UP) { | 2524 | if (slave->link != BOND_LINK_UP) { |
@@ -2619,10 +2609,11 @@ re_arm: | |||
2619 | static int bond_ab_arp_inspect(struct bonding *bond) | 2609 | static int bond_ab_arp_inspect(struct bonding *bond) |
2620 | { | 2610 | { |
2621 | unsigned long trans_start, last_rx; | 2611 | unsigned long trans_start, last_rx; |
2612 | struct list_head *iter; | ||
2622 | struct slave *slave; | 2613 | struct slave *slave; |
2623 | int commit = 0; | 2614 | int commit = 0; |
2624 | 2615 | ||
2625 | bond_for_each_slave(bond, slave) { | 2616 | bond_for_each_slave(bond, slave, iter) { |
2626 | slave->new_link = BOND_LINK_NOCHANGE; | 2617 | slave->new_link = BOND_LINK_NOCHANGE; |
2627 | last_rx = slave_last_rx(bond, slave); | 2618 | last_rx = slave_last_rx(bond, slave); |
2628 | 2619 | ||
@@ -2689,9 +2680,10 @@ static int bond_ab_arp_inspect(struct bonding *bond) | |||
2689 | static void bond_ab_arp_commit(struct bonding *bond) | 2680 | static void bond_ab_arp_commit(struct bonding *bond) |
2690 | { | 2681 | { |
2691 | unsigned long trans_start; | 2682 | unsigned long trans_start; |
2683 | struct list_head *iter; | ||
2692 | struct slave *slave; | 2684 | struct slave *slave; |
2693 | 2685 | ||
2694 | bond_for_each_slave(bond, slave) { | 2686 | bond_for_each_slave(bond, slave, iter) { |
2695 | switch (slave->new_link) { | 2687 | switch (slave->new_link) { |
2696 | case BOND_LINK_NOCHANGE: | 2688 | case BOND_LINK_NOCHANGE: |
2697 | continue; | 2689 | continue; |
@@ -2762,8 +2754,9 @@ do_failover: | |||
2762 | */ | 2754 | */ |
2763 | static void bond_ab_arp_probe(struct bonding *bond) | 2755 | static void bond_ab_arp_probe(struct bonding *bond) |
2764 | { | 2756 | { |
2765 | struct slave *slave, *next_slave; | 2757 | struct slave *slave, *before = NULL, *new_slave = NULL; |
2766 | int i; | 2758 | struct list_head *iter; |
2759 | bool found = false; | ||
2767 | 2760 | ||
2768 | read_lock(&bond->curr_slave_lock); | 2761 | read_lock(&bond->curr_slave_lock); |
2769 | 2762 | ||
@@ -2793,18 +2786,12 @@ static void bond_ab_arp_probe(struct bonding *bond) | |||
2793 | 2786 | ||
2794 | bond_set_slave_inactive_flags(bond->current_arp_slave); | 2787 | bond_set_slave_inactive_flags(bond->current_arp_slave); |
2795 | 2788 | ||
2796 | /* search for next candidate */ | 2789 | bond_for_each_slave(bond, slave, iter) { |
2797 | next_slave = bond_next_slave(bond, bond->current_arp_slave); | 2790 | if (!found && !before && IS_UP(slave->dev)) |
2798 | bond_for_each_slave_from(bond, slave, i, next_slave) { | 2791 | before = slave; |
2799 | if (IS_UP(slave->dev)) { | ||
2800 | slave->link = BOND_LINK_BACK; | ||
2801 | bond_set_slave_active_flags(slave); | ||
2802 | bond_arp_send_all(bond, slave); | ||
2803 | slave->jiffies = jiffies; | ||
2804 | bond->current_arp_slave = slave; | ||
2805 | break; | ||
2806 | } | ||
2807 | 2792 | ||
2793 | if (found && !new_slave && IS_UP(slave->dev)) | ||
2794 | new_slave = slave; | ||
2808 | /* if the link state is up at this point, we | 2795 | /* if the link state is up at this point, we |
2809 | * mark it down - this can happen if we have | 2796 | * mark it down - this can happen if we have |
2810 | * simultaneous link failures and | 2797 | * simultaneous link failures and |
@@ -2812,7 +2799,7 @@ static void bond_ab_arp_probe(struct bonding *bond) | |||
2812 | * one the current slave so it is still marked | 2799 | * one the current slave so it is still marked |
2813 | * up when it is actually down | 2800 | * up when it is actually down |
2814 | */ | 2801 | */ |
2815 | if (slave->link == BOND_LINK_UP) { | 2802 | if (!IS_UP(slave->dev) && slave->link == BOND_LINK_UP) { |
2816 | slave->link = BOND_LINK_DOWN; | 2803 | slave->link = BOND_LINK_DOWN; |
2817 | if (slave->link_failure_count < UINT_MAX) | 2804 | if (slave->link_failure_count < UINT_MAX) |
2818 | slave->link_failure_count++; | 2805 | slave->link_failure_count++; |
@@ -2822,7 +2809,22 @@ static void bond_ab_arp_probe(struct bonding *bond) | |||
2822 | pr_info("%s: backup interface %s is now down.\n", | 2809 | pr_info("%s: backup interface %s is now down.\n", |
2823 | bond->dev->name, slave->dev->name); | 2810 | bond->dev->name, slave->dev->name); |
2824 | } | 2811 | } |
2812 | if (slave == bond->current_arp_slave) | ||
2813 | found = true; | ||
2825 | } | 2814 | } |
2815 | |||
2816 | if (!new_slave && before) | ||
2817 | new_slave = before; | ||
2818 | |||
2819 | if (!new_slave) | ||
2820 | return; | ||
2821 | |||
2822 | new_slave->link = BOND_LINK_BACK; | ||
2823 | bond_set_slave_active_flags(new_slave); | ||
2824 | bond_arp_send_all(bond, new_slave); | ||
2825 | new_slave->jiffies = jiffies; | ||
2826 | bond->current_arp_slave = new_slave; | ||
2827 | |||
2826 | } | 2828 | } |
2827 | 2829 | ||
2828 | void bond_activebackup_arp_mon(struct work_struct *work) | 2830 | void bond_activebackup_arp_mon(struct work_struct *work) |
@@ -2836,7 +2838,7 @@ void bond_activebackup_arp_mon(struct work_struct *work) | |||
2836 | 2838 | ||
2837 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); | 2839 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); |
2838 | 2840 | ||
2839 | if (list_empty(&bond->slave_list)) | 2841 | if (!bond_has_slaves(bond)) |
2840 | goto re_arm; | 2842 | goto re_arm; |
2841 | 2843 | ||
2842 | should_notify_peers = bond_should_notify_peers(bond); | 2844 | should_notify_peers = bond_should_notify_peers(bond); |
@@ -3155,13 +3157,14 @@ static void bond_work_cancel_all(struct bonding *bond) | |||
3155 | static int bond_open(struct net_device *bond_dev) | 3157 | static int bond_open(struct net_device *bond_dev) |
3156 | { | 3158 | { |
3157 | struct bonding *bond = netdev_priv(bond_dev); | 3159 | struct bonding *bond = netdev_priv(bond_dev); |
3160 | struct list_head *iter; | ||
3158 | struct slave *slave; | 3161 | struct slave *slave; |
3159 | 3162 | ||
3160 | /* reset slave->backup and slave->inactive */ | 3163 | /* reset slave->backup and slave->inactive */ |
3161 | read_lock(&bond->lock); | 3164 | read_lock(&bond->lock); |
3162 | if (!list_empty(&bond->slave_list)) { | 3165 | if (bond_has_slaves(bond)) { |
3163 | read_lock(&bond->curr_slave_lock); | 3166 | read_lock(&bond->curr_slave_lock); |
3164 | bond_for_each_slave(bond, slave) { | 3167 | bond_for_each_slave(bond, slave, iter) { |
3165 | if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP) | 3168 | if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP) |
3166 | && (slave != bond->curr_active_slave)) { | 3169 | && (slave != bond->curr_active_slave)) { |
3167 | bond_set_slave_inactive_flags(slave); | 3170 | bond_set_slave_inactive_flags(slave); |
@@ -3221,12 +3224,13 @@ static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev, | |||
3221 | { | 3224 | { |
3222 | struct bonding *bond = netdev_priv(bond_dev); | 3225 | struct bonding *bond = netdev_priv(bond_dev); |
3223 | struct rtnl_link_stats64 temp; | 3226 | struct rtnl_link_stats64 temp; |
3227 | struct list_head *iter; | ||
3224 | struct slave *slave; | 3228 | struct slave *slave; |
3225 | 3229 | ||
3226 | memset(stats, 0, sizeof(*stats)); | 3230 | memset(stats, 0, sizeof(*stats)); |
3227 | 3231 | ||
3228 | read_lock_bh(&bond->lock); | 3232 | read_lock_bh(&bond->lock); |
3229 | bond_for_each_slave(bond, slave) { | 3233 | bond_for_each_slave(bond, slave, iter) { |
3230 | const struct rtnl_link_stats64 *sstats = | 3234 | const struct rtnl_link_stats64 *sstats = |
3231 | dev_get_stats(slave->dev, &temp); | 3235 | dev_get_stats(slave->dev, &temp); |
3232 | 3236 | ||
@@ -3393,22 +3397,24 @@ static void bond_change_rx_flags(struct net_device *bond_dev, int change) | |||
3393 | static void bond_set_rx_mode(struct net_device *bond_dev) | 3397 | static void bond_set_rx_mode(struct net_device *bond_dev) |
3394 | { | 3398 | { |
3395 | struct bonding *bond = netdev_priv(bond_dev); | 3399 | struct bonding *bond = netdev_priv(bond_dev); |
3400 | struct list_head *iter; | ||
3396 | struct slave *slave; | 3401 | struct slave *slave; |
3397 | 3402 | ||
3398 | ASSERT_RTNL(); | ||
3399 | 3403 | ||
3404 | rcu_read_lock(); | ||
3400 | if (USES_PRIMARY(bond->params.mode)) { | 3405 | if (USES_PRIMARY(bond->params.mode)) { |
3401 | slave = rtnl_dereference(bond->curr_active_slave); | 3406 | slave = rcu_dereference(bond->curr_active_slave); |
3402 | if (slave) { | 3407 | if (slave) { |
3403 | dev_uc_sync(slave->dev, bond_dev); | 3408 | dev_uc_sync(slave->dev, bond_dev); |
3404 | dev_mc_sync(slave->dev, bond_dev); | 3409 | dev_mc_sync(slave->dev, bond_dev); |
3405 | } | 3410 | } |
3406 | } else { | 3411 | } else { |
3407 | bond_for_each_slave(bond, slave) { | 3412 | bond_for_each_slave_rcu(bond, slave, iter) { |
3408 | dev_uc_sync_multiple(slave->dev, bond_dev); | 3413 | dev_uc_sync_multiple(slave->dev, bond_dev); |
3409 | dev_mc_sync_multiple(slave->dev, bond_dev); | 3414 | dev_mc_sync_multiple(slave->dev, bond_dev); |
3410 | } | 3415 | } |
3411 | } | 3416 | } |
3417 | rcu_read_unlock(); | ||
3412 | } | 3418 | } |
3413 | 3419 | ||
3414 | static int bond_neigh_init(struct neighbour *n) | 3420 | static int bond_neigh_init(struct neighbour *n) |
@@ -3471,7 +3477,8 @@ static int bond_neigh_setup(struct net_device *dev, | |||
3471 | static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) | 3477 | static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) |
3472 | { | 3478 | { |
3473 | struct bonding *bond = netdev_priv(bond_dev); | 3479 | struct bonding *bond = netdev_priv(bond_dev); |
3474 | struct slave *slave; | 3480 | struct slave *slave, *rollback_slave; |
3481 | struct list_head *iter; | ||
3475 | int res = 0; | 3482 | int res = 0; |
3476 | 3483 | ||
3477 | pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond, | 3484 | pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond, |
@@ -3492,10 +3499,9 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) | |||
3492 | * call to the base driver. | 3499 | * call to the base driver. |
3493 | */ | 3500 | */ |
3494 | 3501 | ||
3495 | bond_for_each_slave(bond, slave) { | 3502 | bond_for_each_slave(bond, slave, iter) { |
3496 | pr_debug("s %p s->p %p c_m %p\n", | 3503 | pr_debug("s %p c_m %p\n", |
3497 | slave, | 3504 | slave, |
3498 | bond_prev_slave(bond, slave), | ||
3499 | slave->dev->netdev_ops->ndo_change_mtu); | 3505 | slave->dev->netdev_ops->ndo_change_mtu); |
3500 | 3506 | ||
3501 | res = dev_set_mtu(slave->dev, new_mtu); | 3507 | res = dev_set_mtu(slave->dev, new_mtu); |
@@ -3520,13 +3526,16 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) | |||
3520 | 3526 | ||
3521 | unwind: | 3527 | unwind: |
3522 | /* unwind from head to the slave that failed */ | 3528 | /* unwind from head to the slave that failed */ |
3523 | bond_for_each_slave_continue_reverse(bond, slave) { | 3529 | bond_for_each_slave(bond, rollback_slave, iter) { |
3524 | int tmp_res; | 3530 | int tmp_res; |
3525 | 3531 | ||
3526 | tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu); | 3532 | if (rollback_slave == slave) |
3533 | break; | ||
3534 | |||
3535 | tmp_res = dev_set_mtu(rollback_slave->dev, bond_dev->mtu); | ||
3527 | if (tmp_res) { | 3536 | if (tmp_res) { |
3528 | pr_debug("unwind err %d dev %s\n", | 3537 | pr_debug("unwind err %d dev %s\n", |
3529 | tmp_res, slave->dev->name); | 3538 | tmp_res, rollback_slave->dev->name); |
3530 | } | 3539 | } |
3531 | } | 3540 | } |
3532 | 3541 | ||
@@ -3543,8 +3552,9 @@ unwind: | |||
3543 | static int bond_set_mac_address(struct net_device *bond_dev, void *addr) | 3552 | static int bond_set_mac_address(struct net_device *bond_dev, void *addr) |
3544 | { | 3553 | { |
3545 | struct bonding *bond = netdev_priv(bond_dev); | 3554 | struct bonding *bond = netdev_priv(bond_dev); |
3555 | struct slave *slave, *rollback_slave; | ||
3546 | struct sockaddr *sa = addr, tmp_sa; | 3556 | struct sockaddr *sa = addr, tmp_sa; |
3547 | struct slave *slave; | 3557 | struct list_head *iter; |
3548 | int res = 0; | 3558 | int res = 0; |
3549 | 3559 | ||
3550 | if (bond->params.mode == BOND_MODE_ALB) | 3560 | if (bond->params.mode == BOND_MODE_ALB) |
@@ -3578,7 +3588,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr) | |||
3578 | * call to the base driver. | 3588 | * call to the base driver. |
3579 | */ | 3589 | */ |
3580 | 3590 | ||
3581 | bond_for_each_slave(bond, slave) { | 3591 | bond_for_each_slave(bond, slave, iter) { |
3582 | const struct net_device_ops *slave_ops = slave->dev->netdev_ops; | 3592 | const struct net_device_ops *slave_ops = slave->dev->netdev_ops; |
3583 | pr_debug("slave %p %s\n", slave, slave->dev->name); | 3593 | pr_debug("slave %p %s\n", slave, slave->dev->name); |
3584 | 3594 | ||
@@ -3610,13 +3620,16 @@ unwind: | |||
3610 | tmp_sa.sa_family = bond_dev->type; | 3620 | tmp_sa.sa_family = bond_dev->type; |
3611 | 3621 | ||
3612 | /* unwind from head to the slave that failed */ | 3622 | /* unwind from head to the slave that failed */ |
3613 | bond_for_each_slave_continue_reverse(bond, slave) { | 3623 | bond_for_each_slave(bond, rollback_slave, iter) { |
3614 | int tmp_res; | 3624 | int tmp_res; |
3615 | 3625 | ||
3616 | tmp_res = dev_set_mac_address(slave->dev, &tmp_sa); | 3626 | if (rollback_slave == slave) |
3627 | break; | ||
3628 | |||
3629 | tmp_res = dev_set_mac_address(rollback_slave->dev, &tmp_sa); | ||
3617 | if (tmp_res) { | 3630 | if (tmp_res) { |
3618 | pr_debug("unwind err %d dev %s\n", | 3631 | pr_debug("unwind err %d dev %s\n", |
3619 | tmp_res, slave->dev->name); | 3632 | tmp_res, rollback_slave->dev->name); |
3620 | } | 3633 | } |
3621 | } | 3634 | } |
3622 | 3635 | ||
@@ -3635,11 +3648,12 @@ unwind: | |||
3635 | */ | 3648 | */ |
3636 | void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id) | 3649 | void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id) |
3637 | { | 3650 | { |
3651 | struct list_head *iter; | ||
3638 | struct slave *slave; | 3652 | struct slave *slave; |
3639 | int i = slave_id; | 3653 | int i = slave_id; |
3640 | 3654 | ||
3641 | /* Here we start from the slave with slave_id */ | 3655 | /* Here we start from the slave with slave_id */ |
3642 | bond_for_each_slave_rcu(bond, slave) { | 3656 | bond_for_each_slave_rcu(bond, slave, iter) { |
3643 | if (--i < 0) { | 3657 | if (--i < 0) { |
3644 | if (slave_can_tx(slave)) { | 3658 | if (slave_can_tx(slave)) { |
3645 | bond_dev_queue_xmit(bond, skb, slave->dev); | 3659 | bond_dev_queue_xmit(bond, skb, slave->dev); |
@@ -3650,7 +3664,7 @@ void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id) | |||
3650 | 3664 | ||
3651 | /* Here we start from the first slave up to slave_id */ | 3665 | /* Here we start from the first slave up to slave_id */ |
3652 | i = slave_id; | 3666 | i = slave_id; |
3653 | bond_for_each_slave_rcu(bond, slave) { | 3667 | bond_for_each_slave_rcu(bond, slave, iter) { |
3654 | if (--i < 0) | 3668 | if (--i < 0) |
3655 | break; | 3669 | break; |
3656 | if (slave_can_tx(slave)) { | 3670 | if (slave_can_tx(slave)) { |
@@ -3727,8 +3741,9 @@ static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev) | |||
3727 | { | 3741 | { |
3728 | struct bonding *bond = netdev_priv(bond_dev); | 3742 | struct bonding *bond = netdev_priv(bond_dev); |
3729 | struct slave *slave = NULL; | 3743 | struct slave *slave = NULL; |
3744 | struct list_head *iter; | ||
3730 | 3745 | ||
3731 | bond_for_each_slave_rcu(bond, slave) { | 3746 | bond_for_each_slave_rcu(bond, slave, iter) { |
3732 | if (bond_is_last_slave(bond, slave)) | 3747 | if (bond_is_last_slave(bond, slave)) |
3733 | break; | 3748 | break; |
3734 | if (IS_UP(slave->dev) && slave->link == BOND_LINK_UP) { | 3749 | if (IS_UP(slave->dev) && slave->link == BOND_LINK_UP) { |
@@ -3777,13 +3792,14 @@ static inline int bond_slave_override(struct bonding *bond, | |||
3777 | { | 3792 | { |
3778 | struct slave *slave = NULL; | 3793 | struct slave *slave = NULL; |
3779 | struct slave *check_slave; | 3794 | struct slave *check_slave; |
3795 | struct list_head *iter; | ||
3780 | int res = 1; | 3796 | int res = 1; |
3781 | 3797 | ||
3782 | if (!skb->queue_mapping) | 3798 | if (!skb->queue_mapping) |
3783 | return 1; | 3799 | return 1; |
3784 | 3800 | ||
3785 | /* Find out if any slaves have the same mapping as this skb. */ | 3801 | /* Find out if any slaves have the same mapping as this skb. */ |
3786 | bond_for_each_slave_rcu(bond, check_slave) { | 3802 | bond_for_each_slave_rcu(bond, check_slave, iter) { |
3787 | if (check_slave->queue_id == skb->queue_mapping) { | 3803 | if (check_slave->queue_id == skb->queue_mapping) { |
3788 | slave = check_slave; | 3804 | slave = check_slave; |
3789 | break; | 3805 | break; |
@@ -3869,7 +3885,7 @@ static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
3869 | return NETDEV_TX_BUSY; | 3885 | return NETDEV_TX_BUSY; |
3870 | 3886 | ||
3871 | rcu_read_lock(); | 3887 | rcu_read_lock(); |
3872 | if (!list_empty(&bond->slave_list)) | 3888 | if (bond_has_slaves(bond)) |
3873 | ret = __bond_start_xmit(skb, dev); | 3889 | ret = __bond_start_xmit(skb, dev); |
3874 | else | 3890 | else |
3875 | kfree_skb(skb); | 3891 | kfree_skb(skb); |
@@ -3915,6 +3931,7 @@ static int bond_ethtool_get_settings(struct net_device *bond_dev, | |||
3915 | { | 3931 | { |
3916 | struct bonding *bond = netdev_priv(bond_dev); | 3932 | struct bonding *bond = netdev_priv(bond_dev); |
3917 | unsigned long speed = 0; | 3933 | unsigned long speed = 0; |
3934 | struct list_head *iter; | ||
3918 | struct slave *slave; | 3935 | struct slave *slave; |
3919 | 3936 | ||
3920 | ecmd->duplex = DUPLEX_UNKNOWN; | 3937 | ecmd->duplex = DUPLEX_UNKNOWN; |
@@ -3926,7 +3943,7 @@ static int bond_ethtool_get_settings(struct net_device *bond_dev, | |||
3926 | * this is an accurate maximum. | 3943 | * this is an accurate maximum. |
3927 | */ | 3944 | */ |
3928 | read_lock(&bond->lock); | 3945 | read_lock(&bond->lock); |
3929 | bond_for_each_slave(bond, slave) { | 3946 | bond_for_each_slave(bond, slave, iter) { |
3930 | if (SLAVE_IS_OK(slave)) { | 3947 | if (SLAVE_IS_OK(slave)) { |
3931 | if (slave->speed != SPEED_UNKNOWN) | 3948 | if (slave->speed != SPEED_UNKNOWN) |
3932 | speed += slave->speed; | 3949 | speed += slave->speed; |
@@ -4001,7 +4018,6 @@ static void bond_setup(struct net_device *bond_dev) | |||
4001 | /* initialize rwlocks */ | 4018 | /* initialize rwlocks */ |
4002 | rwlock_init(&bond->lock); | 4019 | rwlock_init(&bond->lock); |
4003 | rwlock_init(&bond->curr_slave_lock); | 4020 | rwlock_init(&bond->curr_slave_lock); |
4004 | INIT_LIST_HEAD(&bond->slave_list); | ||
4005 | bond->params = bonding_defaults; | 4021 | bond->params = bonding_defaults; |
4006 | 4022 | ||
4007 | /* Initialize pointers */ | 4023 | /* Initialize pointers */ |
@@ -4057,12 +4073,13 @@ static void bond_setup(struct net_device *bond_dev) | |||
4057 | static void bond_uninit(struct net_device *bond_dev) | 4073 | static void bond_uninit(struct net_device *bond_dev) |
4058 | { | 4074 | { |
4059 | struct bonding *bond = netdev_priv(bond_dev); | 4075 | struct bonding *bond = netdev_priv(bond_dev); |
4060 | struct slave *slave, *tmp_slave; | 4076 | struct list_head *iter; |
4077 | struct slave *slave; | ||
4061 | 4078 | ||
4062 | bond_netpoll_cleanup(bond_dev); | 4079 | bond_netpoll_cleanup(bond_dev); |
4063 | 4080 | ||
4064 | /* Release the bonded slaves */ | 4081 | /* Release the bonded slaves */ |
4065 | list_for_each_entry_safe(slave, tmp_slave, &bond->slave_list, list) | 4082 | bond_for_each_slave(bond, slave, iter) |
4066 | __bond_release_one(bond_dev, slave->dev, true); | 4083 | __bond_release_one(bond_dev, slave->dev, true); |
4067 | pr_info("%s: released all slaves\n", bond_dev->name); | 4084 | pr_info("%s: released all slaves\n", bond_dev->name); |
4068 | 4085 | ||
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c index 20a6ee25bb63..fb868d6c22da 100644 --- a/drivers/net/bonding/bond_procfs.c +++ b/drivers/net/bonding/bond_procfs.c | |||
@@ -10,8 +10,9 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) | |||
10 | __acquires(&bond->lock) | 10 | __acquires(&bond->lock) |
11 | { | 11 | { |
12 | struct bonding *bond = seq->private; | 12 | struct bonding *bond = seq->private; |
13 | loff_t off = 0; | 13 | struct list_head *iter; |
14 | struct slave *slave; | 14 | struct slave *slave; |
15 | loff_t off = 0; | ||
15 | 16 | ||
16 | /* make sure the bond won't be taken away */ | 17 | /* make sure the bond won't be taken away */ |
17 | rcu_read_lock(); | 18 | rcu_read_lock(); |
@@ -20,7 +21,7 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) | |||
20 | if (*pos == 0) | 21 | if (*pos == 0) |
21 | return SEQ_START_TOKEN; | 22 | return SEQ_START_TOKEN; |
22 | 23 | ||
23 | bond_for_each_slave(bond, slave) | 24 | bond_for_each_slave(bond, slave, iter) |
24 | if (++off == *pos) | 25 | if (++off == *pos) |
25 | return slave; | 26 | return slave; |
26 | 27 | ||
@@ -30,17 +31,25 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) | |||
30 | static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 31 | static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
31 | { | 32 | { |
32 | struct bonding *bond = seq->private; | 33 | struct bonding *bond = seq->private; |
33 | struct slave *slave = v; | 34 | struct list_head *iter; |
35 | struct slave *slave; | ||
36 | bool found = false; | ||
34 | 37 | ||
35 | ++*pos; | 38 | ++*pos; |
36 | if (v == SEQ_START_TOKEN) | 39 | if (v == SEQ_START_TOKEN) |
37 | return bond_first_slave(bond); | 40 | return bond_first_slave(bond); |
38 | 41 | ||
39 | if (bond_is_last_slave(bond, slave)) | 42 | if (bond_is_last_slave(bond, v)) |
40 | return NULL; | 43 | return NULL; |
41 | slave = bond_next_slave(bond, slave); | ||
42 | 44 | ||
43 | return slave; | 45 | bond_for_each_slave(bond, slave, iter) { |
46 | if (found) | ||
47 | return slave; | ||
48 | if (slave == v) | ||
49 | found = true; | ||
50 | } | ||
51 | |||
52 | return NULL; | ||
44 | } | 53 | } |
45 | 54 | ||
46 | static void bond_info_seq_stop(struct seq_file *seq, void *v) | 55 | static void bond_info_seq_stop(struct seq_file *seq, void *v) |
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c index c29b836749b6..e06c644470b1 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c | |||
@@ -168,41 +168,6 @@ static const struct class_attribute class_attr_bonding_masters = { | |||
168 | .namespace = bonding_namespace, | 168 | .namespace = bonding_namespace, |
169 | }; | 169 | }; |
170 | 170 | ||
171 | int bond_create_slave_symlinks(struct net_device *master, | ||
172 | struct net_device *slave) | ||
173 | { | ||
174 | char linkname[IFNAMSIZ+7]; | ||
175 | int ret = 0; | ||
176 | |||
177 | /* first, create a link from the slave back to the master */ | ||
178 | ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj), | ||
179 | "master"); | ||
180 | if (ret) | ||
181 | return ret; | ||
182 | /* next, create a link from the master to the slave */ | ||
183 | sprintf(linkname, "slave_%s", slave->name); | ||
184 | ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj), | ||
185 | linkname); | ||
186 | |||
187 | /* free the master link created earlier in case of error */ | ||
188 | if (ret) | ||
189 | sysfs_remove_link(&(slave->dev.kobj), "master"); | ||
190 | |||
191 | return ret; | ||
192 | |||
193 | } | ||
194 | |||
195 | void bond_destroy_slave_symlinks(struct net_device *master, | ||
196 | struct net_device *slave) | ||
197 | { | ||
198 | char linkname[IFNAMSIZ+7]; | ||
199 | |||
200 | sysfs_remove_link(&(slave->dev.kobj), "master"); | ||
201 | sprintf(linkname, "slave_%s", slave->name); | ||
202 | sysfs_remove_link(&(master->dev.kobj), linkname); | ||
203 | } | ||
204 | |||
205 | |||
206 | /* | 171 | /* |
207 | * Show the slaves in the current bond. | 172 | * Show the slaves in the current bond. |
208 | */ | 173 | */ |
@@ -210,11 +175,12 @@ static ssize_t bonding_show_slaves(struct device *d, | |||
210 | struct device_attribute *attr, char *buf) | 175 | struct device_attribute *attr, char *buf) |
211 | { | 176 | { |
212 | struct bonding *bond = to_bond(d); | 177 | struct bonding *bond = to_bond(d); |
178 | struct list_head *iter; | ||
213 | struct slave *slave; | 179 | struct slave *slave; |
214 | int res = 0; | 180 | int res = 0; |
215 | 181 | ||
216 | read_lock(&bond->lock); | 182 | read_lock(&bond->lock); |
217 | bond_for_each_slave(bond, slave) { | 183 | bond_for_each_slave(bond, slave, iter) { |
218 | if (res > (PAGE_SIZE - IFNAMSIZ)) { | 184 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
219 | /* not enough space for another interface name */ | 185 | /* not enough space for another interface name */ |
220 | if ((PAGE_SIZE - res) > 10) | 186 | if ((PAGE_SIZE - res) > 10) |
@@ -326,7 +292,7 @@ static ssize_t bonding_store_mode(struct device *d, | |||
326 | goto out; | 292 | goto out; |
327 | } | 293 | } |
328 | 294 | ||
329 | if (!list_empty(&bond->slave_list)) { | 295 | if (bond_has_slaves(bond)) { |
330 | pr_err("unable to update mode of %s because it has slaves.\n", | 296 | pr_err("unable to update mode of %s because it has slaves.\n", |
331 | bond->dev->name); | 297 | bond->dev->name); |
332 | ret = -EPERM; | 298 | ret = -EPERM; |
@@ -522,7 +488,7 @@ static ssize_t bonding_store_fail_over_mac(struct device *d, | |||
522 | if (!rtnl_trylock()) | 488 | if (!rtnl_trylock()) |
523 | return restart_syscall(); | 489 | return restart_syscall(); |
524 | 490 | ||
525 | if (!list_empty(&bond->slave_list)) { | 491 | if (bond_has_slaves(bond)) { |
526 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", | 492 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", |
527 | bond->dev->name); | 493 | bond->dev->name); |
528 | ret = -EPERM; | 494 | ret = -EPERM; |
@@ -656,6 +622,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, | |||
656 | const char *buf, size_t count) | 622 | const char *buf, size_t count) |
657 | { | 623 | { |
658 | struct bonding *bond = to_bond(d); | 624 | struct bonding *bond = to_bond(d); |
625 | struct list_head *iter; | ||
659 | struct slave *slave; | 626 | struct slave *slave; |
660 | __be32 newtarget, *targets; | 627 | __be32 newtarget, *targets; |
661 | unsigned long *targets_rx; | 628 | unsigned long *targets_rx; |
@@ -688,7 +655,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, | |||
688 | &newtarget); | 655 | &newtarget); |
689 | /* not to race with bond_arp_rcv */ | 656 | /* not to race with bond_arp_rcv */ |
690 | write_lock_bh(&bond->lock); | 657 | write_lock_bh(&bond->lock); |
691 | bond_for_each_slave(bond, slave) | 658 | bond_for_each_slave(bond, slave, iter) |
692 | slave->target_last_arp_rx[ind] = jiffies; | 659 | slave->target_last_arp_rx[ind] = jiffies; |
693 | targets[ind] = newtarget; | 660 | targets[ind] = newtarget; |
694 | write_unlock_bh(&bond->lock); | 661 | write_unlock_bh(&bond->lock); |
@@ -714,7 +681,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, | |||
714 | &newtarget); | 681 | &newtarget); |
715 | 682 | ||
716 | write_lock_bh(&bond->lock); | 683 | write_lock_bh(&bond->lock); |
717 | bond_for_each_slave(bond, slave) { | 684 | bond_for_each_slave(bond, slave, iter) { |
718 | targets_rx = slave->target_last_arp_rx; | 685 | targets_rx = slave->target_last_arp_rx; |
719 | j = ind; | 686 | j = ind; |
720 | for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++) | 687 | for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++) |
@@ -1111,6 +1078,7 @@ static ssize_t bonding_store_primary(struct device *d, | |||
1111 | const char *buf, size_t count) | 1078 | const char *buf, size_t count) |
1112 | { | 1079 | { |
1113 | struct bonding *bond = to_bond(d); | 1080 | struct bonding *bond = to_bond(d); |
1081 | struct list_head *iter; | ||
1114 | char ifname[IFNAMSIZ]; | 1082 | char ifname[IFNAMSIZ]; |
1115 | struct slave *slave; | 1083 | struct slave *slave; |
1116 | 1084 | ||
@@ -1138,7 +1106,7 @@ static ssize_t bonding_store_primary(struct device *d, | |||
1138 | goto out; | 1106 | goto out; |
1139 | } | 1107 | } |
1140 | 1108 | ||
1141 | bond_for_each_slave(bond, slave) { | 1109 | bond_for_each_slave(bond, slave, iter) { |
1142 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | 1110 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
1143 | pr_info("%s: Setting %s as primary slave.\n", | 1111 | pr_info("%s: Setting %s as primary slave.\n", |
1144 | bond->dev->name, slave->dev->name); | 1112 | bond->dev->name, slave->dev->name); |
@@ -1286,6 +1254,7 @@ static ssize_t bonding_store_active_slave(struct device *d, | |||
1286 | { | 1254 | { |
1287 | struct slave *slave, *old_active, *new_active; | 1255 | struct slave *slave, *old_active, *new_active; |
1288 | struct bonding *bond = to_bond(d); | 1256 | struct bonding *bond = to_bond(d); |
1257 | struct list_head *iter; | ||
1289 | char ifname[IFNAMSIZ]; | 1258 | char ifname[IFNAMSIZ]; |
1290 | 1259 | ||
1291 | if (!rtnl_trylock()) | 1260 | if (!rtnl_trylock()) |
@@ -1313,7 +1282,7 @@ static ssize_t bonding_store_active_slave(struct device *d, | |||
1313 | goto out; | 1282 | goto out; |
1314 | } | 1283 | } |
1315 | 1284 | ||
1316 | bond_for_each_slave(bond, slave) { | 1285 | bond_for_each_slave(bond, slave, iter) { |
1317 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | 1286 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
1318 | old_active = bond->curr_active_slave; | 1287 | old_active = bond->curr_active_slave; |
1319 | new_active = slave; | 1288 | new_active = slave; |
@@ -1493,6 +1462,7 @@ static ssize_t bonding_show_queue_id(struct device *d, | |||
1493 | char *buf) | 1462 | char *buf) |
1494 | { | 1463 | { |
1495 | struct bonding *bond = to_bond(d); | 1464 | struct bonding *bond = to_bond(d); |
1465 | struct list_head *iter; | ||
1496 | struct slave *slave; | 1466 | struct slave *slave; |
1497 | int res = 0; | 1467 | int res = 0; |
1498 | 1468 | ||
@@ -1500,7 +1470,7 @@ static ssize_t bonding_show_queue_id(struct device *d, | |||
1500 | return restart_syscall(); | 1470 | return restart_syscall(); |
1501 | 1471 | ||
1502 | read_lock(&bond->lock); | 1472 | read_lock(&bond->lock); |
1503 | bond_for_each_slave(bond, slave) { | 1473 | bond_for_each_slave(bond, slave, iter) { |
1504 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { | 1474 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
1505 | /* not enough space for another interface_name:queue_id pair */ | 1475 | /* not enough space for another interface_name:queue_id pair */ |
1506 | if ((PAGE_SIZE - res) > 10) | 1476 | if ((PAGE_SIZE - res) > 10) |
@@ -1529,6 +1499,7 @@ static ssize_t bonding_store_queue_id(struct device *d, | |||
1529 | { | 1499 | { |
1530 | struct slave *slave, *update_slave; | 1500 | struct slave *slave, *update_slave; |
1531 | struct bonding *bond = to_bond(d); | 1501 | struct bonding *bond = to_bond(d); |
1502 | struct list_head *iter; | ||
1532 | u16 qid; | 1503 | u16 qid; |
1533 | int ret = count; | 1504 | int ret = count; |
1534 | char *delim; | 1505 | char *delim; |
@@ -1565,7 +1536,7 @@ static ssize_t bonding_store_queue_id(struct device *d, | |||
1565 | 1536 | ||
1566 | /* Search for thes slave and check for duplicate qids */ | 1537 | /* Search for thes slave and check for duplicate qids */ |
1567 | update_slave = NULL; | 1538 | update_slave = NULL; |
1568 | bond_for_each_slave(bond, slave) { | 1539 | bond_for_each_slave(bond, slave, iter) { |
1569 | if (sdev == slave->dev) | 1540 | if (sdev == slave->dev) |
1570 | /* | 1541 | /* |
1571 | * We don't need to check the matching | 1542 | * We don't need to check the matching |
@@ -1619,6 +1590,7 @@ static ssize_t bonding_store_slaves_active(struct device *d, | |||
1619 | { | 1590 | { |
1620 | struct bonding *bond = to_bond(d); | 1591 | struct bonding *bond = to_bond(d); |
1621 | int new_value, ret = count; | 1592 | int new_value, ret = count; |
1593 | struct list_head *iter; | ||
1622 | struct slave *slave; | 1594 | struct slave *slave; |
1623 | 1595 | ||
1624 | if (sscanf(buf, "%d", &new_value) != 1) { | 1596 | if (sscanf(buf, "%d", &new_value) != 1) { |
@@ -1641,7 +1613,7 @@ static ssize_t bonding_store_slaves_active(struct device *d, | |||
1641 | } | 1613 | } |
1642 | 1614 | ||
1643 | read_lock(&bond->lock); | 1615 | read_lock(&bond->lock); |
1644 | bond_for_each_slave(bond, slave) { | 1616 | bond_for_each_slave(bond, slave, iter) { |
1645 | if (!bond_is_active_slave(slave)) { | 1617 | if (!bond_is_active_slave(slave)) { |
1646 | if (new_value) | 1618 | if (new_value) |
1647 | slave->inactive = 0; | 1619 | slave->inactive = 0; |
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index 03cf3fd14490..9a26fbd82645 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h | |||
@@ -72,63 +72,37 @@ | |||
72 | res; }) | 72 | res; }) |
73 | 73 | ||
74 | /* slave list primitives */ | 74 | /* slave list primitives */ |
75 | #define bond_to_slave(ptr) list_entry(ptr, struct slave, list) | 75 | #define bond_slave_list(bond) (&(bond)->dev->adj_list.lower) |
76 | |||
77 | #define bond_has_slaves(bond) !list_empty(bond_slave_list(bond)) | ||
76 | 78 | ||
77 | /* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */ | 79 | /* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */ |
78 | #define bond_first_slave(bond) \ | 80 | #define bond_first_slave(bond) \ |
79 | list_first_entry_or_null(&(bond)->slave_list, struct slave, list) | 81 | (bond_has_slaves(bond) ? \ |
82 | netdev_adjacent_get_private(bond_slave_list(bond)->next) : \ | ||
83 | NULL) | ||
80 | #define bond_last_slave(bond) \ | 84 | #define bond_last_slave(bond) \ |
81 | (list_empty(&(bond)->slave_list) ? NULL : \ | 85 | (bond_has_slaves(bond) ? \ |
82 | bond_to_slave((bond)->slave_list.prev)) | 86 | netdev_adjacent_get_private(bond_slave_list(bond)->prev) : \ |
83 | 87 | NULL) | |
84 | #define bond_is_first_slave(bond, pos) ((pos)->list.prev == &(bond)->slave_list) | ||
85 | #define bond_is_last_slave(bond, pos) ((pos)->list.next == &(bond)->slave_list) | ||
86 | |||
87 | /* Since bond_first/last_slave can return NULL, these can return NULL too */ | ||
88 | #define bond_next_slave(bond, pos) \ | ||
89 | (bond_is_last_slave(bond, pos) ? bond_first_slave(bond) : \ | ||
90 | bond_to_slave((pos)->list.next)) | ||
91 | 88 | ||
92 | #define bond_prev_slave(bond, pos) \ | 89 | #define bond_is_first_slave(bond, pos) (pos == bond_first_slave(bond)) |
93 | (bond_is_first_slave(bond, pos) ? bond_last_slave(bond) : \ | 90 | #define bond_is_last_slave(bond, pos) (pos == bond_last_slave(bond)) |
94 | bond_to_slave((pos)->list.prev)) | ||
95 | |||
96 | /** | ||
97 | * bond_for_each_slave_from - iterate the slaves list from a starting point | ||
98 | * @bond: the bond holding this list. | ||
99 | * @pos: current slave. | ||
100 | * @cnt: counter for max number of moves | ||
101 | * @start: starting point. | ||
102 | * | ||
103 | * Caller must hold bond->lock | ||
104 | */ | ||
105 | #define bond_for_each_slave_from(bond, pos, cnt, start) \ | ||
106 | for (cnt = 0, pos = start; pos && cnt < (bond)->slave_cnt; \ | ||
107 | cnt++, pos = bond_next_slave(bond, pos)) | ||
108 | 91 | ||
109 | /** | 92 | /** |
110 | * bond_for_each_slave - iterate over all slaves | 93 | * bond_for_each_slave - iterate over all slaves |
111 | * @bond: the bond holding this list | 94 | * @bond: the bond holding this list |
112 | * @pos: current slave | 95 | * @pos: current slave |
96 | * @iter: list_head * iterator | ||
113 | * | 97 | * |
114 | * Caller must hold bond->lock | 98 | * Caller must hold bond->lock |
115 | */ | 99 | */ |
116 | #define bond_for_each_slave(bond, pos) \ | 100 | #define bond_for_each_slave(bond, pos, iter) \ |
117 | list_for_each_entry(pos, &(bond)->slave_list, list) | 101 | netdev_for_each_lower_private((bond)->dev, pos, iter) |
118 | 102 | ||
119 | /* Caller must have rcu_read_lock */ | 103 | /* Caller must have rcu_read_lock */ |
120 | #define bond_for_each_slave_rcu(bond, pos) \ | 104 | #define bond_for_each_slave_rcu(bond, pos, iter) \ |
121 | list_for_each_entry_rcu(pos, &(bond)->slave_list, list) | 105 | netdev_for_each_lower_private_rcu((bond)->dev, pos, iter) |
122 | |||
123 | /** | ||
124 | * bond_for_each_slave_reverse - iterate in reverse from a given position | ||
125 | * @bond: the bond holding this list | ||
126 | * @pos: slave to continue from | ||
127 | * | ||
128 | * Caller must hold bond->lock | ||
129 | */ | ||
130 | #define bond_for_each_slave_continue_reverse(bond, pos) \ | ||
131 | list_for_each_entry_continue_reverse(pos, &(bond)->slave_list, list) | ||
132 | 106 | ||
133 | #ifdef CONFIG_NET_POLL_CONTROLLER | 107 | #ifdef CONFIG_NET_POLL_CONTROLLER |
134 | extern atomic_t netpoll_block_tx; | 108 | extern atomic_t netpoll_block_tx; |
@@ -188,7 +162,6 @@ struct bond_parm_tbl { | |||
188 | 162 | ||
189 | struct slave { | 163 | struct slave { |
190 | struct net_device *dev; /* first - useful for panic debug */ | 164 | struct net_device *dev; /* first - useful for panic debug */ |
191 | struct list_head list; | ||
192 | struct bonding *bond; /* our master */ | 165 | struct bonding *bond; /* our master */ |
193 | int delay; | 166 | int delay; |
194 | unsigned long jiffies; | 167 | unsigned long jiffies; |
@@ -228,7 +201,6 @@ struct slave { | |||
228 | */ | 201 | */ |
229 | struct bonding { | 202 | struct bonding { |
230 | struct net_device *dev; /* first - useful for panic debug */ | 203 | struct net_device *dev; /* first - useful for panic debug */ |
231 | struct list_head slave_list; | ||
232 | struct slave *curr_active_slave; | 204 | struct slave *curr_active_slave; |
233 | struct slave *current_arp_slave; | 205 | struct slave *current_arp_slave; |
234 | struct slave *primary_slave; | 206 | struct slave *primary_slave; |
@@ -276,13 +248,7 @@ struct bonding { | |||
276 | static inline struct slave *bond_get_slave_by_dev(struct bonding *bond, | 248 | static inline struct slave *bond_get_slave_by_dev(struct bonding *bond, |
277 | struct net_device *slave_dev) | 249 | struct net_device *slave_dev) |
278 | { | 250 | { |
279 | struct slave *slave = NULL; | 251 | return netdev_lower_dev_get_private(bond->dev, slave_dev); |
280 | |||
281 | bond_for_each_slave(bond, slave) | ||
282 | if (slave->dev == slave_dev) | ||
283 | return slave; | ||
284 | |||
285 | return NULL; | ||
286 | } | 252 | } |
287 | 253 | ||
288 | static inline struct bonding *bond_get_bond_by_slave(struct slave *slave) | 254 | static inline struct bonding *bond_get_bond_by_slave(struct slave *slave) |
@@ -432,15 +398,12 @@ static inline bool slave_can_tx(struct slave *slave) | |||
432 | struct bond_net; | 398 | struct bond_net; |
433 | 399 | ||
434 | int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave); | 400 | int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave); |
435 | struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr); | ||
436 | int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev); | 401 | int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev); |
437 | void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id); | 402 | void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id); |
438 | int bond_create(struct net *net, const char *name); | 403 | int bond_create(struct net *net, const char *name); |
439 | int bond_create_sysfs(struct bond_net *net); | 404 | int bond_create_sysfs(struct bond_net *net); |
440 | void bond_destroy_sysfs(struct bond_net *net); | 405 | void bond_destroy_sysfs(struct bond_net *net); |
441 | void bond_prepare_sysfs_group(struct bonding *bond); | 406 | void bond_prepare_sysfs_group(struct bonding *bond); |
442 | int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave); | ||
443 | void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave); | ||
444 | int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev); | 407 | int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev); |
445 | int bond_release(struct net_device *bond_dev, struct net_device *slave_dev); | 408 | int bond_release(struct net_device *bond_dev, struct net_device *slave_dev); |
446 | void bond_mii_monitor(struct work_struct *); | 409 | void bond_mii_monitor(struct work_struct *); |
@@ -492,9 +455,10 @@ static inline void bond_destroy_proc_dir(struct bond_net *bn) | |||
492 | static inline struct slave *bond_slave_has_mac(struct bonding *bond, | 455 | static inline struct slave *bond_slave_has_mac(struct bonding *bond, |
493 | const u8 *mac) | 456 | const u8 *mac) |
494 | { | 457 | { |
458 | struct list_head *iter; | ||
495 | struct slave *tmp; | 459 | struct slave *tmp; |
496 | 460 | ||
497 | bond_for_each_slave(bond, tmp) | 461 | bond_for_each_slave(bond, tmp, iter) |
498 | if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr)) | 462 | if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr)) |
499 | return tmp; | 463 | return tmp; |
500 | 464 | ||