diff options
| -rw-r--r-- | drivers/net/bonding/bond_3ad.c | 44 | ||||
| -rw-r--r-- | drivers/net/bonding/bond_alb.c | 57 | ||||
| -rw-r--r-- | drivers/net/bonding/bond_main.c | 433 | ||||
| -rw-r--r-- | drivers/net/bonding/bond_procfs.c | 12 | ||||
| -rw-r--r-- | drivers/net/bonding/bond_sysfs.c | 62 | ||||
| -rw-r--r-- | drivers/net/bonding/bonding.h | 85 |
6 files changed, 310 insertions, 383 deletions
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index 390061d09693..90102652c82a 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c | |||
| @@ -143,10 +143,9 @@ static inline struct bonding *__get_bond_by_port(struct port *port) | |||
| 143 | */ | 143 | */ |
| 144 | static inline struct port *__get_first_port(struct bonding *bond) | 144 | static inline struct port *__get_first_port(struct bonding *bond) |
| 145 | { | 145 | { |
| 146 | if (bond->slave_cnt == 0) | 146 | struct slave *first_slave = bond_first_slave(bond); |
| 147 | return NULL; | ||
| 148 | 147 | ||
| 149 | return &(SLAVE_AD_INFO(bond->first_slave).port); | 148 | return first_slave ? &(SLAVE_AD_INFO(first_slave).port) : NULL; |
| 150 | } | 149 | } |
| 151 | 150 | ||
| 152 | /** | 151 | /** |
| @@ -159,13 +158,16 @@ static inline struct port *__get_first_port(struct bonding *bond) | |||
| 159 | static inline struct port *__get_next_port(struct port *port) | 158 | static inline struct port *__get_next_port(struct port *port) |
| 160 | { | 159 | { |
| 161 | struct bonding *bond = __get_bond_by_port(port); | 160 | struct bonding *bond = __get_bond_by_port(port); |
| 162 | struct slave *slave = port->slave; | 161 | struct slave *slave = port->slave, *slave_next; |
| 163 | 162 | ||
| 164 | // If there's no bond for this port, or this is the last slave | 163 | // If there's no bond for this port, or this is the last slave |
| 165 | if ((bond == NULL) || (slave->next == bond->first_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)) | ||
| 166 | return NULL; | 168 | return NULL; |
| 167 | 169 | ||
| 168 | return &(SLAVE_AD_INFO(slave->next).port); | 170 | return &(SLAVE_AD_INFO(slave_next).port); |
| 169 | } | 171 | } |
| 170 | 172 | ||
| 171 | /** | 173 | /** |
| @@ -178,12 +180,14 @@ static inline struct port *__get_next_port(struct port *port) | |||
| 178 | static inline struct aggregator *__get_first_agg(struct port *port) | 180 | static inline struct aggregator *__get_first_agg(struct port *port) |
| 179 | { | 181 | { |
| 180 | struct bonding *bond = __get_bond_by_port(port); | 182 | struct bonding *bond = __get_bond_by_port(port); |
| 183 | struct slave *first_slave; | ||
| 181 | 184 | ||
| 182 | // If there's no bond for this port, or bond has no slaves | 185 | // If there's no bond for this port, or bond has no slaves |
| 183 | if ((bond == NULL) || (bond->slave_cnt == 0)) | 186 | if (bond == NULL) |
| 184 | return NULL; | 187 | return NULL; |
| 188 | first_slave = bond_first_slave(bond); | ||
| 185 | 189 | ||
| 186 | return &(SLAVE_AD_INFO(bond->first_slave).aggregator); | 190 | return first_slave ? &(SLAVE_AD_INFO(first_slave).aggregator) : NULL; |
| 187 | } | 191 | } |
| 188 | 192 | ||
| 189 | /** | 193 | /** |
| @@ -195,14 +199,17 @@ static inline struct aggregator *__get_first_agg(struct port *port) | |||
| 195 | */ | 199 | */ |
| 196 | static inline struct aggregator *__get_next_agg(struct aggregator *aggregator) | 200 | static inline struct aggregator *__get_next_agg(struct aggregator *aggregator) |
| 197 | { | 201 | { |
| 198 | struct slave *slave = aggregator->slave; | 202 | struct slave *slave = aggregator->slave, *slave_next; |
| 199 | struct bonding *bond = bond_get_bond_by_slave(slave); | 203 | struct bonding *bond = bond_get_bond_by_slave(slave); |
| 200 | 204 | ||
| 201 | // If there's no bond for this aggregator, or this is the last slave | 205 | // If there's no bond for this aggregator, or this is the last slave |
| 202 | if ((bond == NULL) || (slave->next == bond->first_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)) | ||
| 203 | return NULL; | 210 | return NULL; |
| 204 | 211 | ||
| 205 | return &(SLAVE_AD_INFO(slave->next).aggregator); | 212 | return &(SLAVE_AD_INFO(slave_next).aggregator); |
| 206 | } | 213 | } |
| 207 | 214 | ||
| 208 | /* | 215 | /* |
| @@ -2110,7 +2117,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work) | |||
| 2110 | read_lock(&bond->lock); | 2117 | read_lock(&bond->lock); |
| 2111 | 2118 | ||
| 2112 | //check if there are any slaves | 2119 | //check if there are any slaves |
| 2113 | if (bond->slave_cnt == 0) | 2120 | if (list_empty(&bond->slave_list)) |
| 2114 | goto re_arm; | 2121 | goto re_arm; |
| 2115 | 2122 | ||
| 2116 | // check if agg_select_timer timer after initialize is timed out | 2123 | // check if agg_select_timer timer after initialize is timed out |
| @@ -2336,8 +2343,12 @@ void bond_3ad_handle_link_change(struct slave *slave, char link) | |||
| 2336 | int bond_3ad_set_carrier(struct bonding *bond) | 2343 | int bond_3ad_set_carrier(struct bonding *bond) |
| 2337 | { | 2344 | { |
| 2338 | struct aggregator *active; | 2345 | struct aggregator *active; |
| 2346 | struct slave *first_slave; | ||
| 2339 | 2347 | ||
| 2340 | active = __get_active_agg(&(SLAVE_AD_INFO(bond->first_slave).aggregator)); | 2348 | first_slave = bond_first_slave(bond); |
| 2349 | if (!first_slave) | ||
| 2350 | return 0; | ||
| 2351 | active = __get_active_agg(&(SLAVE_AD_INFO(first_slave).aggregator)); | ||
| 2341 | if (active) { | 2352 | if (active) { |
| 2342 | /* are enough slaves available to consider link up? */ | 2353 | /* are enough slaves available to consider link up? */ |
| 2343 | if (active->num_of_ports < bond->params.min_links) { | 2354 | if (active->num_of_ports < bond->params.min_links) { |
| @@ -2415,6 +2426,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) | |||
| 2415 | struct ad_info ad_info; | 2426 | struct ad_info ad_info; |
| 2416 | int res = 1; | 2427 | int res = 1; |
| 2417 | 2428 | ||
| 2429 | read_lock(&bond->lock); | ||
| 2418 | if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { | 2430 | if (__bond_3ad_get_active_agg_info(bond, &ad_info)) { |
| 2419 | pr_debug("%s: Error: __bond_3ad_get_active_agg_info failed\n", | 2431 | pr_debug("%s: Error: __bond_3ad_get_active_agg_info failed\n", |
| 2420 | dev->name); | 2432 | dev->name); |
| @@ -2432,7 +2444,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) | |||
| 2432 | 2444 | ||
| 2433 | slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg); | 2445 | slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg); |
| 2434 | 2446 | ||
| 2435 | bond_for_each_slave(bond, slave, i) { | 2447 | bond_for_each_slave(bond, slave) { |
| 2436 | struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; | 2448 | struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; |
| 2437 | 2449 | ||
| 2438 | if (agg && (agg->aggregator_identifier == agg_id)) { | 2450 | if (agg && (agg->aggregator_identifier == agg_id)) { |
| @@ -2464,6 +2476,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) | |||
| 2464 | } | 2476 | } |
| 2465 | 2477 | ||
| 2466 | out: | 2478 | out: |
| 2479 | read_unlock(&bond->lock); | ||
| 2467 | if (res) { | 2480 | if (res) { |
| 2468 | /* no suitable interface, frame not sent */ | 2481 | /* no suitable interface, frame not sent */ |
| 2469 | kfree_skb(skb); | 2482 | kfree_skb(skb); |
| @@ -2501,7 +2514,6 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond, | |||
| 2501 | */ | 2514 | */ |
| 2502 | void bond_3ad_update_lacp_rate(struct bonding *bond) | 2515 | void bond_3ad_update_lacp_rate(struct bonding *bond) |
| 2503 | { | 2516 | { |
| 2504 | int i; | ||
| 2505 | struct slave *slave; | 2517 | struct slave *slave; |
| 2506 | struct port *port = NULL; | 2518 | struct port *port = NULL; |
| 2507 | int lacp_fast; | 2519 | int lacp_fast; |
| @@ -2509,7 +2521,7 @@ void bond_3ad_update_lacp_rate(struct bonding *bond) | |||
| 2509 | write_lock_bh(&bond->lock); | 2521 | write_lock_bh(&bond->lock); |
| 2510 | lacp_fast = bond->params.lacp_fast; | 2522 | lacp_fast = bond->params.lacp_fast; |
| 2511 | 2523 | ||
| 2512 | bond_for_each_slave(bond, slave, i) { | 2524 | bond_for_each_slave(bond, slave) { |
| 2513 | port = &(SLAVE_AD_INFO(slave).port); | 2525 | port = &(SLAVE_AD_INFO(slave).port); |
| 2514 | if (port->slave == NULL) | 2526 | if (port->slave == NULL) |
| 2515 | continue; | 2527 | continue; |
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c index 4ea8ed150d46..3a5db7b1df68 100644 --- a/drivers/net/bonding/bond_alb.c +++ b/drivers/net/bonding/bond_alb.c | |||
| @@ -224,13 +224,12 @@ 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 | long long max_gap; | 226 | long long max_gap; |
| 227 | int i; | ||
| 228 | 227 | ||
| 229 | least_loaded = NULL; | 228 | least_loaded = NULL; |
| 230 | max_gap = LLONG_MIN; | 229 | max_gap = LLONG_MIN; |
| 231 | 230 | ||
| 232 | /* Find the slave with the largest gap */ | 231 | /* Find the slave with the largest gap */ |
| 233 | bond_for_each_slave(bond, slave, i) { | 232 | bond_for_each_slave(bond, slave) { |
| 234 | if (SLAVE_IS_OK(slave)) { | 233 | if (SLAVE_IS_OK(slave)) { |
| 235 | long long gap = compute_gap(slave); | 234 | long long gap = compute_gap(slave); |
| 236 | 235 | ||
| @@ -386,11 +385,10 @@ static struct slave *rlb_next_rx_slave(struct bonding *bond) | |||
| 386 | struct slave *rx_slave, *slave, *start_at; | 385 | struct slave *rx_slave, *slave, *start_at; |
| 387 | int i = 0; | 386 | int i = 0; |
| 388 | 387 | ||
| 389 | if (bond_info->next_rx_slave) { | 388 | if (bond_info->next_rx_slave) |
| 390 | start_at = bond_info->next_rx_slave; | 389 | start_at = bond_info->next_rx_slave; |
| 391 | } else { | 390 | else |
| 392 | start_at = bond->first_slave; | 391 | start_at = bond_first_slave(bond); |
| 393 | } | ||
| 394 | 392 | ||
| 395 | rx_slave = NULL; | 393 | rx_slave = NULL; |
| 396 | 394 | ||
| @@ -405,7 +403,8 @@ static struct slave *rlb_next_rx_slave(struct bonding *bond) | |||
| 405 | } | 403 | } |
| 406 | 404 | ||
| 407 | if (rx_slave) { | 405 | if (rx_slave) { |
| 408 | bond_info->next_rx_slave = rx_slave->next; | 406 | slave = bond_next_slave(bond, rx_slave); |
| 407 | bond_info->next_rx_slave = slave; | ||
| 409 | } | 408 | } |
| 410 | 409 | ||
| 411 | return rx_slave; | 410 | return rx_slave; |
| @@ -1173,9 +1172,8 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav | |||
| 1173 | { | 1172 | { |
| 1174 | struct slave *tmp_slave1, *free_mac_slave = NULL; | 1173 | struct slave *tmp_slave1, *free_mac_slave = NULL; |
| 1175 | struct slave *has_bond_addr = bond->curr_active_slave; | 1174 | struct slave *has_bond_addr = bond->curr_active_slave; |
| 1176 | int i; | ||
| 1177 | 1175 | ||
| 1178 | if (bond->slave_cnt == 0) { | 1176 | if (list_empty(&bond->slave_list)) { |
| 1179 | /* this is the first slave */ | 1177 | /* this is the first slave */ |
| 1180 | return 0; | 1178 | return 0; |
| 1181 | } | 1179 | } |
| @@ -1196,7 +1194,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. | 1194 | /* The slave's address is equal to the address of the bond. |
| 1197 | * Search for a spare address in the bond for this slave. | 1195 | * Search for a spare address in the bond for this slave. |
| 1198 | */ | 1196 | */ |
| 1199 | bond_for_each_slave(bond, tmp_slave1, i) { | 1197 | bond_for_each_slave(bond, tmp_slave1) { |
| 1200 | if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) { | 1198 | if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) { |
| 1201 | /* no slave has tmp_slave1's perm addr | 1199 | /* no slave has tmp_slave1's perm addr |
| 1202 | * as its curr addr | 1200 | * as its curr addr |
| @@ -1246,17 +1244,15 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav | |||
| 1246 | */ | 1244 | */ |
| 1247 | static int alb_set_mac_address(struct bonding *bond, void *addr) | 1245 | static int alb_set_mac_address(struct bonding *bond, void *addr) |
| 1248 | { | 1246 | { |
| 1249 | struct sockaddr sa; | ||
| 1250 | struct slave *slave, *stop_at; | ||
| 1251 | char tmp_addr[ETH_ALEN]; | 1247 | char tmp_addr[ETH_ALEN]; |
| 1248 | struct slave *slave; | ||
| 1249 | struct sockaddr sa; | ||
| 1252 | int res; | 1250 | int res; |
| 1253 | int i; | ||
| 1254 | 1251 | ||
| 1255 | if (bond->alb_info.rlb_enabled) { | 1252 | if (bond->alb_info.rlb_enabled) |
| 1256 | return 0; | 1253 | return 0; |
| 1257 | } | ||
| 1258 | 1254 | ||
| 1259 | bond_for_each_slave(bond, slave, i) { | 1255 | bond_for_each_slave(bond, slave) { |
| 1260 | /* save net_device's current hw address */ | 1256 | /* save net_device's current hw address */ |
| 1261 | memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN); | 1257 | memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN); |
| 1262 | 1258 | ||
| @@ -1276,8 +1272,7 @@ unwind: | |||
| 1276 | sa.sa_family = bond->dev->type; | 1272 | sa.sa_family = bond->dev->type; |
| 1277 | 1273 | ||
| 1278 | /* unwind from head to the slave that failed */ | 1274 | /* unwind from head to the slave that failed */ |
| 1279 | stop_at = slave; | 1275 | bond_for_each_slave_continue_reverse(bond, slave) { |
| 1280 | bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) { | ||
| 1281 | memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN); | 1276 | memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN); |
| 1282 | dev_set_mac_address(slave->dev, &sa); | 1277 | dev_set_mac_address(slave->dev, &sa); |
| 1283 | memcpy(slave->dev->dev_addr, tmp_addr, ETH_ALEN); | 1278 | memcpy(slave->dev->dev_addr, tmp_addr, ETH_ALEN); |
| @@ -1342,6 +1337,7 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) | |||
| 1342 | 1337 | ||
| 1343 | /* make sure that the curr_active_slave do not change during tx | 1338 | /* make sure that the curr_active_slave do not change during tx |
| 1344 | */ | 1339 | */ |
| 1340 | read_lock(&bond->lock); | ||
| 1345 | read_lock(&bond->curr_slave_lock); | 1341 | read_lock(&bond->curr_slave_lock); |
| 1346 | 1342 | ||
| 1347 | switch (ntohs(skb->protocol)) { | 1343 | switch (ntohs(skb->protocol)) { |
| @@ -1446,11 +1442,12 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) | |||
| 1446 | } | 1442 | } |
| 1447 | 1443 | ||
| 1448 | read_unlock(&bond->curr_slave_lock); | 1444 | read_unlock(&bond->curr_slave_lock); |
| 1449 | 1445 | read_unlock(&bond->lock); | |
| 1450 | if (res) { | 1446 | if (res) { |
| 1451 | /* no suitable interface, frame not sent */ | 1447 | /* no suitable interface, frame not sent */ |
| 1452 | kfree_skb(skb); | 1448 | kfree_skb(skb); |
| 1453 | } | 1449 | } |
| 1450 | |||
| 1454 | return NETDEV_TX_OK; | 1451 | return NETDEV_TX_OK; |
| 1455 | } | 1452 | } |
| 1456 | 1453 | ||
| @@ -1460,11 +1457,10 @@ void bond_alb_monitor(struct work_struct *work) | |||
| 1460 | alb_work.work); | 1457 | alb_work.work); |
| 1461 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); | 1458 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
| 1462 | struct slave *slave; | 1459 | struct slave *slave; |
| 1463 | int i; | ||
| 1464 | 1460 | ||
| 1465 | read_lock(&bond->lock); | 1461 | read_lock(&bond->lock); |
| 1466 | 1462 | ||
| 1467 | if (bond->slave_cnt == 0) { | 1463 | if (list_empty(&bond->slave_list)) { |
| 1468 | bond_info->tx_rebalance_counter = 0; | 1464 | bond_info->tx_rebalance_counter = 0; |
| 1469 | bond_info->lp_counter = 0; | 1465 | bond_info->lp_counter = 0; |
| 1470 | goto re_arm; | 1466 | goto re_arm; |
| @@ -1482,9 +1478,8 @@ void bond_alb_monitor(struct work_struct *work) | |||
| 1482 | */ | 1478 | */ |
| 1483 | read_lock(&bond->curr_slave_lock); | 1479 | read_lock(&bond->curr_slave_lock); |
| 1484 | 1480 | ||
| 1485 | bond_for_each_slave(bond, slave, i) { | 1481 | bond_for_each_slave(bond, slave) |
| 1486 | alb_send_learning_packets(slave, slave->dev->dev_addr); | 1482 | alb_send_learning_packets(slave, slave->dev->dev_addr); |
| 1487 | } | ||
| 1488 | 1483 | ||
| 1489 | read_unlock(&bond->curr_slave_lock); | 1484 | read_unlock(&bond->curr_slave_lock); |
| 1490 | 1485 | ||
| @@ -1496,7 +1491,7 @@ void bond_alb_monitor(struct work_struct *work) | |||
| 1496 | 1491 | ||
| 1497 | read_lock(&bond->curr_slave_lock); | 1492 | read_lock(&bond->curr_slave_lock); |
| 1498 | 1493 | ||
| 1499 | bond_for_each_slave(bond, slave, i) { | 1494 | bond_for_each_slave(bond, slave) { |
| 1500 | tlb_clear_slave(bond, slave, 1); | 1495 | tlb_clear_slave(bond, slave, 1); |
| 1501 | if (slave == bond->curr_active_slave) { | 1496 | if (slave == bond->curr_active_slave) { |
| 1502 | SLAVE_TLB_INFO(slave).load = | 1497 | SLAVE_TLB_INFO(slave).load = |
| @@ -1602,9 +1597,8 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave) | |||
| 1602 | */ | 1597 | */ |
| 1603 | void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave) | 1598 | void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave) |
| 1604 | { | 1599 | { |
| 1605 | if (bond->slave_cnt > 1) { | 1600 | if (!list_empty(&bond->slave_list)) |
| 1606 | alb_change_hw_addr_on_detach(bond, slave); | 1601 | alb_change_hw_addr_on_detach(bond, slave); |
| 1607 | } | ||
| 1608 | 1602 | ||
| 1609 | tlb_clear_slave(bond, slave, 0); | 1603 | tlb_clear_slave(bond, slave, 0); |
| 1610 | 1604 | ||
| @@ -1661,9 +1655,8 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave | |||
| 1661 | { | 1655 | { |
| 1662 | struct slave *swap_slave; | 1656 | struct slave *swap_slave; |
| 1663 | 1657 | ||
| 1664 | if (bond->curr_active_slave == new_slave) { | 1658 | if (bond->curr_active_slave == new_slave) |
| 1665 | return; | 1659 | return; |
| 1666 | } | ||
| 1667 | 1660 | ||
| 1668 | if (bond->curr_active_slave && bond->alb_info.primary_is_promisc) { | 1661 | if (bond->curr_active_slave && bond->alb_info.primary_is_promisc) { |
| 1669 | dev_set_promiscuity(bond->curr_active_slave->dev, -1); | 1662 | dev_set_promiscuity(bond->curr_active_slave->dev, -1); |
| @@ -1672,11 +1665,10 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave | |||
| 1672 | } | 1665 | } |
| 1673 | 1666 | ||
| 1674 | swap_slave = bond->curr_active_slave; | 1667 | swap_slave = bond->curr_active_slave; |
| 1675 | bond->curr_active_slave = new_slave; | 1668 | rcu_assign_pointer(bond->curr_active_slave, new_slave); |
| 1676 | 1669 | ||
| 1677 | if (!new_slave || (bond->slave_cnt == 0)) { | 1670 | if (!new_slave || list_empty(&bond->slave_list)) |
| 1678 | return; | 1671 | return; |
| 1679 | } | ||
| 1680 | 1672 | ||
| 1681 | /* set the new curr_active_slave to the bonds mac address | 1673 | /* set the new curr_active_slave to the bonds mac address |
| 1682 | * i.e. swap mac addresses of old curr_active_slave and new curr_active_slave | 1674 | * i.e. swap mac addresses of old curr_active_slave and new curr_active_slave |
| @@ -1689,9 +1681,8 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave | |||
| 1689 | * ignored so we can mess with their MAC addresses without | 1681 | * ignored so we can mess with their MAC addresses without |
| 1690 | * fear of interference from transmit activity. | 1682 | * fear of interference from transmit activity. |
| 1691 | */ | 1683 | */ |
| 1692 | if (swap_slave) { | 1684 | if (swap_slave) |
| 1693 | tlb_clear_slave(bond, swap_slave, 1); | 1685 | tlb_clear_slave(bond, swap_slave, 1); |
| 1694 | } | ||
| 1695 | tlb_clear_slave(bond, new_slave, 1); | 1686 | tlb_clear_slave(bond, new_slave, 1); |
| 1696 | 1687 | ||
| 1697 | write_unlock_bh(&bond->curr_slave_lock); | 1688 | write_unlock_bh(&bond->curr_slave_lock); |
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index bc3578e4980a..1d37a9657e0d 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c | |||
| @@ -77,6 +77,7 @@ | |||
| 77 | #include <net/net_namespace.h> | 77 | #include <net/net_namespace.h> |
| 78 | #include <net/netns/generic.h> | 78 | #include <net/netns/generic.h> |
| 79 | #include <net/pkt_sched.h> | 79 | #include <net/pkt_sched.h> |
| 80 | #include <linux/rculist.h> | ||
| 80 | #include "bonding.h" | 81 | #include "bonding.h" |
| 81 | #include "bond_3ad.h" | 82 | #include "bond_3ad.h" |
| 82 | #include "bond_alb.h" | 83 | #include "bond_alb.h" |
| @@ -441,10 +442,10 @@ static int bond_vlan_rx_add_vid(struct net_device *bond_dev, | |||
| 441 | __be16 proto, u16 vid) | 442 | __be16 proto, u16 vid) |
| 442 | { | 443 | { |
| 443 | struct bonding *bond = netdev_priv(bond_dev); | 444 | struct bonding *bond = netdev_priv(bond_dev); |
| 444 | struct slave *slave, *stop_at; | 445 | struct slave *slave; |
| 445 | int i, res; | 446 | int res; |
| 446 | 447 | ||
| 447 | bond_for_each_slave(bond, slave, i) { | 448 | bond_for_each_slave(bond, slave) { |
| 448 | res = vlan_vid_add(slave->dev, proto, vid); | 449 | res = vlan_vid_add(slave->dev, proto, vid); |
| 449 | if (res) | 450 | if (res) |
| 450 | goto unwind; | 451 | goto unwind; |
| @@ -461,8 +462,7 @@ static int bond_vlan_rx_add_vid(struct net_device *bond_dev, | |||
| 461 | 462 | ||
| 462 | unwind: | 463 | unwind: |
| 463 | /* unwind from head to the slave that failed */ | 464 | /* unwind from head to the slave that failed */ |
| 464 | stop_at = slave; | 465 | bond_for_each_slave_continue_reverse(bond, slave) |
| 465 | bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) | ||
| 466 | vlan_vid_del(slave->dev, proto, vid); | 466 | vlan_vid_del(slave->dev, proto, vid); |
| 467 | 467 | ||
| 468 | return res; | 468 | return res; |
| @@ -478,9 +478,9 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev, | |||
| 478 | { | 478 | { |
| 479 | struct bonding *bond = netdev_priv(bond_dev); | 479 | struct bonding *bond = netdev_priv(bond_dev); |
| 480 | struct slave *slave; | 480 | struct slave *slave; |
| 481 | int i, res; | 481 | int res; |
| 482 | 482 | ||
| 483 | bond_for_each_slave(bond, slave, i) | 483 | bond_for_each_slave(bond, slave) |
| 484 | vlan_vid_del(slave->dev, proto, vid); | 484 | vlan_vid_del(slave->dev, proto, vid); |
| 485 | 485 | ||
| 486 | res = bond_del_vlan(bond, vid); | 486 | res = bond_del_vlan(bond, vid); |
| @@ -532,15 +532,14 @@ static void bond_del_vlans_from_slave(struct bonding *bond, | |||
| 532 | static int bond_set_carrier(struct bonding *bond) | 532 | static int bond_set_carrier(struct bonding *bond) |
| 533 | { | 533 | { |
| 534 | struct slave *slave; | 534 | struct slave *slave; |
| 535 | int i; | ||
| 536 | 535 | ||
| 537 | if (bond->slave_cnt == 0) | 536 | if (list_empty(&bond->slave_list)) |
| 538 | goto down; | 537 | goto down; |
| 539 | 538 | ||
| 540 | if (bond->params.mode == BOND_MODE_8023AD) | 539 | if (bond->params.mode == BOND_MODE_8023AD) |
| 541 | return bond_3ad_set_carrier(bond); | 540 | return bond_3ad_set_carrier(bond); |
| 542 | 541 | ||
| 543 | bond_for_each_slave(bond, slave, i) { | 542 | bond_for_each_slave(bond, slave) { |
| 544 | if (slave->link == BOND_LINK_UP) { | 543 | if (slave->link == BOND_LINK_UP) { |
| 545 | if (!netif_carrier_ok(bond->dev)) { | 544 | if (!netif_carrier_ok(bond->dev)) { |
| 546 | netif_carrier_on(bond->dev); | 545 | netif_carrier_on(bond->dev); |
| @@ -681,8 +680,8 @@ static int bond_set_promiscuity(struct bonding *bond, int inc) | |||
| 681 | } | 680 | } |
| 682 | } else { | 681 | } else { |
| 683 | struct slave *slave; | 682 | struct slave *slave; |
| 684 | int i; | 683 | |
| 685 | bond_for_each_slave(bond, slave, i) { | 684 | bond_for_each_slave(bond, slave) { |
| 686 | err = dev_set_promiscuity(slave->dev, inc); | 685 | err = dev_set_promiscuity(slave->dev, inc); |
| 687 | if (err) | 686 | if (err) |
| 688 | return err; | 687 | return err; |
| @@ -705,8 +704,8 @@ static int bond_set_allmulti(struct bonding *bond, int inc) | |||
| 705 | } | 704 | } |
| 706 | } else { | 705 | } else { |
| 707 | struct slave *slave; | 706 | struct slave *slave; |
| 708 | int i; | 707 | |
| 709 | bond_for_each_slave(bond, slave, i) { | 708 | bond_for_each_slave(bond, slave) { |
| 710 | err = dev_set_allmulti(slave->dev, inc); | 709 | err = dev_set_allmulti(slave->dev, inc); |
| 711 | if (err) | 710 | if (err) |
| 712 | return err; | 711 | return err; |
| @@ -935,9 +934,8 @@ static struct slave *bond_find_best_slave(struct bonding *bond) | |||
| 935 | new_active = bond->curr_active_slave; | 934 | new_active = bond->curr_active_slave; |
| 936 | 935 | ||
| 937 | if (!new_active) { /* there were no active slaves left */ | 936 | if (!new_active) { /* there were no active slaves left */ |
| 938 | if (bond->slave_cnt > 0) /* found one slave */ | 937 | new_active = bond_first_slave(bond); |
| 939 | new_active = bond->first_slave; | 938 | if (!new_active) |
| 940 | else | ||
| 941 | return NULL; /* still no slave, return NULL */ | 939 | return NULL; /* still no slave, return NULL */ |
| 942 | } | 940 | } |
| 943 | 941 | ||
| @@ -1040,7 +1038,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active) | |||
| 1040 | if (new_active) | 1038 | if (new_active) |
| 1041 | bond_set_slave_active_flags(new_active); | 1039 | bond_set_slave_active_flags(new_active); |
| 1042 | } else { | 1040 | } else { |
| 1043 | bond->curr_active_slave = new_active; | 1041 | rcu_assign_pointer(bond->curr_active_slave, new_active); |
| 1044 | } | 1042 | } |
| 1045 | 1043 | ||
| 1046 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) { | 1044 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) { |
| @@ -1130,17 +1128,7 @@ void bond_select_active_slave(struct bonding *bond) | |||
| 1130 | */ | 1128 | */ |
| 1131 | static void bond_attach_slave(struct bonding *bond, struct slave *new_slave) | 1129 | static void bond_attach_slave(struct bonding *bond, struct slave *new_slave) |
| 1132 | { | 1130 | { |
| 1133 | if (bond->first_slave == NULL) { /* attaching the first slave */ | 1131 | list_add_tail_rcu(&new_slave->list, &bond->slave_list); |
| 1134 | new_slave->next = new_slave; | ||
| 1135 | new_slave->prev = new_slave; | ||
| 1136 | bond->first_slave = new_slave; | ||
| 1137 | } else { | ||
| 1138 | new_slave->next = bond->first_slave; | ||
| 1139 | new_slave->prev = bond->first_slave->prev; | ||
| 1140 | new_slave->next->prev = new_slave; | ||
| 1141 | new_slave->prev->next = new_slave; | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | bond->slave_cnt++; | 1132 | bond->slave_cnt++; |
| 1145 | } | 1133 | } |
| 1146 | 1134 | ||
| @@ -1156,22 +1144,7 @@ static void bond_attach_slave(struct bonding *bond, struct slave *new_slave) | |||
| 1156 | */ | 1144 | */ |
| 1157 | static void bond_detach_slave(struct bonding *bond, struct slave *slave) | 1145 | static void bond_detach_slave(struct bonding *bond, struct slave *slave) |
| 1158 | { | 1146 | { |
| 1159 | if (slave->next) | 1147 | list_del_rcu(&slave->list); |
| 1160 | slave->next->prev = slave->prev; | ||
| 1161 | |||
| 1162 | if (slave->prev) | ||
| 1163 | slave->prev->next = slave->next; | ||
| 1164 | |||
| 1165 | if (bond->first_slave == slave) { /* slave is the first slave */ | ||
| 1166 | if (bond->slave_cnt > 1) { /* there are more slave */ | ||
| 1167 | bond->first_slave = slave->next; | ||
| 1168 | } else { | ||
| 1169 | bond->first_slave = NULL; /* slave was the last one */ | ||
| 1170 | } | ||
| 1171 | } | ||
| 1172 | |||
| 1173 | slave->next = NULL; | ||
| 1174 | slave->prev = NULL; | ||
| 1175 | bond->slave_cnt--; | 1148 | bond->slave_cnt--; |
| 1176 | } | 1149 | } |
| 1177 | 1150 | ||
| @@ -1222,9 +1195,8 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev) | |||
| 1222 | { | 1195 | { |
| 1223 | struct bonding *bond = netdev_priv(bond_dev); | 1196 | struct bonding *bond = netdev_priv(bond_dev); |
| 1224 | struct slave *slave; | 1197 | struct slave *slave; |
| 1225 | int i; | ||
| 1226 | 1198 | ||
| 1227 | bond_for_each_slave(bond, slave, i) | 1199 | bond_for_each_slave(bond, slave) |
| 1228 | if (IS_UP(slave->dev)) | 1200 | if (IS_UP(slave->dev)) |
| 1229 | slave_disable_netpoll(slave); | 1201 | slave_disable_netpoll(slave); |
| 1230 | } | 1202 | } |
| @@ -1233,9 +1205,9 @@ static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni, g | |||
| 1233 | { | 1205 | { |
| 1234 | struct bonding *bond = netdev_priv(dev); | 1206 | struct bonding *bond = netdev_priv(dev); |
| 1235 | struct slave *slave; | 1207 | struct slave *slave; |
| 1236 | int i, err = 0; | 1208 | int err = 0; |
| 1237 | 1209 | ||
| 1238 | bond_for_each_slave(bond, slave, i) { | 1210 | bond_for_each_slave(bond, slave) { |
| 1239 | err = slave_enable_netpoll(slave); | 1211 | err = slave_enable_netpoll(slave); |
| 1240 | if (err) { | 1212 | if (err) { |
| 1241 | bond_netpoll_cleanup(dev); | 1213 | bond_netpoll_cleanup(dev); |
| @@ -1265,11 +1237,10 @@ static netdev_features_t bond_fix_features(struct net_device *dev, | |||
| 1265 | struct slave *slave; | 1237 | struct slave *slave; |
| 1266 | struct bonding *bond = netdev_priv(dev); | 1238 | struct bonding *bond = netdev_priv(dev); |
| 1267 | netdev_features_t mask; | 1239 | netdev_features_t mask; |
| 1268 | int i; | ||
| 1269 | 1240 | ||
| 1270 | read_lock(&bond->lock); | 1241 | read_lock(&bond->lock); |
| 1271 | 1242 | ||
| 1272 | if (!bond->first_slave) { | 1243 | if (list_empty(&bond->slave_list)) { |
| 1273 | /* Disable adding VLANs to empty bond. But why? --mq */ | 1244 | /* Disable adding VLANs to empty bond. But why? --mq */ |
| 1274 | features |= NETIF_F_VLAN_CHALLENGED; | 1245 | features |= NETIF_F_VLAN_CHALLENGED; |
| 1275 | goto out; | 1246 | goto out; |
| @@ -1279,7 +1250,7 @@ static netdev_features_t bond_fix_features(struct net_device *dev, | |||
| 1279 | features &= ~NETIF_F_ONE_FOR_ALL; | 1250 | features &= ~NETIF_F_ONE_FOR_ALL; |
| 1280 | features |= NETIF_F_ALL_FOR_ALL; | 1251 | features |= NETIF_F_ALL_FOR_ALL; |
| 1281 | 1252 | ||
| 1282 | bond_for_each_slave(bond, slave, i) { | 1253 | bond_for_each_slave(bond, slave) { |
| 1283 | features = netdev_increment_features(features, | 1254 | features = netdev_increment_features(features, |
| 1284 | slave->dev->features, | 1255 | slave->dev->features, |
| 1285 | mask); | 1256 | mask); |
| @@ -1303,15 +1274,14 @@ static void bond_compute_features(struct bonding *bond) | |||
| 1303 | unsigned short max_hard_header_len = ETH_HLEN; | 1274 | unsigned short max_hard_header_len = ETH_HLEN; |
| 1304 | unsigned int gso_max_size = GSO_MAX_SIZE; | 1275 | unsigned int gso_max_size = GSO_MAX_SIZE; |
| 1305 | u16 gso_max_segs = GSO_MAX_SEGS; | 1276 | u16 gso_max_segs = GSO_MAX_SEGS; |
| 1306 | int i; | ||
| 1307 | unsigned int flags, dst_release_flag = IFF_XMIT_DST_RELEASE; | 1277 | unsigned int flags, dst_release_flag = IFF_XMIT_DST_RELEASE; |
| 1308 | 1278 | ||
| 1309 | read_lock(&bond->lock); | 1279 | read_lock(&bond->lock); |
| 1310 | 1280 | ||
| 1311 | if (!bond->first_slave) | 1281 | if (list_empty(&bond->slave_list)) |
| 1312 | goto done; | 1282 | goto done; |
| 1313 | 1283 | ||
| 1314 | bond_for_each_slave(bond, slave, i) { | 1284 | bond_for_each_slave(bond, slave) { |
| 1315 | vlan_features = netdev_increment_features(vlan_features, | 1285 | vlan_features = netdev_increment_features(vlan_features, |
| 1316 | slave->dev->vlan_features, BOND_VLAN_FEATURES); | 1286 | slave->dev->vlan_features, BOND_VLAN_FEATURES); |
| 1317 | 1287 | ||
| @@ -1499,7 +1469,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
| 1499 | * bond ether type mutual exclusion - don't allow slaves of dissimilar | 1469 | * bond ether type mutual exclusion - don't allow slaves of dissimilar |
| 1500 | * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond | 1470 | * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond |
| 1501 | */ | 1471 | */ |
| 1502 | if (bond->slave_cnt == 0) { | 1472 | if (list_empty(&bond->slave_list)) { |
| 1503 | if (bond_dev->type != slave_dev->type) { | 1473 | if (bond_dev->type != slave_dev->type) { |
| 1504 | pr_debug("%s: change device type from %d to %d\n", | 1474 | pr_debug("%s: change device type from %d to %d\n", |
| 1505 | bond_dev->name, | 1475 | bond_dev->name, |
| @@ -1538,7 +1508,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
| 1538 | } | 1508 | } |
| 1539 | 1509 | ||
| 1540 | if (slave_ops->ndo_set_mac_address == NULL) { | 1510 | if (slave_ops->ndo_set_mac_address == NULL) { |
| 1541 | if (bond->slave_cnt == 0) { | 1511 | if (list_empty(&bond->slave_list)) { |
| 1542 | pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.", | 1512 | pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.", |
| 1543 | bond_dev->name); | 1513 | bond_dev->name); |
| 1544 | bond->params.fail_over_mac = BOND_FOM_ACTIVE; | 1514 | bond->params.fail_over_mac = BOND_FOM_ACTIVE; |
| @@ -1554,7 +1524,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
| 1554 | 1524 | ||
| 1555 | /* If this is the first slave, then we need to set the master's hardware | 1525 | /* If this is the first slave, then we need to set the master's hardware |
| 1556 | * address to be the same as the slave's. */ | 1526 | * address to be the same as the slave's. */ |
| 1557 | if (!bond->slave_cnt && bond->dev->addr_assign_type == NET_ADDR_RANDOM) | 1527 | if (list_empty(&bond->slave_list) && |
| 1528 | bond->dev->addr_assign_type == NET_ADDR_RANDOM) | ||
| 1558 | bond_set_dev_addr(bond->dev, slave_dev); | 1529 | bond_set_dev_addr(bond->dev, slave_dev); |
| 1559 | 1530 | ||
| 1560 | new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL); | 1531 | new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL); |
| @@ -1562,7 +1533,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
| 1562 | res = -ENOMEM; | 1533 | res = -ENOMEM; |
| 1563 | goto err_undo_flags; | 1534 | goto err_undo_flags; |
| 1564 | } | 1535 | } |
| 1565 | 1536 | INIT_LIST_HEAD(&new_slave->list); | |
| 1566 | /* | 1537 | /* |
| 1567 | * Set the new_slave's queue_id to be zero. Queue ID mapping | 1538 | * Set the new_slave's queue_id to be zero. Queue ID mapping |
| 1568 | * is set via sysfs or module option if desired. | 1539 | * is set via sysfs or module option if desired. |
| @@ -1748,15 +1719,18 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
| 1748 | */ | 1719 | */ |
| 1749 | bond_set_slave_inactive_flags(new_slave); | 1720 | bond_set_slave_inactive_flags(new_slave); |
| 1750 | /* if this is the first slave */ | 1721 | /* if this is the first slave */ |
| 1751 | if (bond->slave_cnt == 1) { | 1722 | if (bond_first_slave(bond) == new_slave) { |
| 1752 | SLAVE_AD_INFO(new_slave).id = 1; | 1723 | SLAVE_AD_INFO(new_slave).id = 1; |
| 1753 | /* Initialize AD with the number of times that the AD timer is called in 1 second | 1724 | /* Initialize AD with the number of times that the AD timer is called in 1 second |
| 1754 | * can be called only after the mac address of the bond is set | 1725 | * can be called only after the mac address of the bond is set |
| 1755 | */ | 1726 | */ |
| 1756 | bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL); | 1727 | bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL); |
| 1757 | } else { | 1728 | } else { |
| 1729 | struct slave *prev_slave; | ||
| 1730 | |||
| 1731 | prev_slave = bond_prev_slave(bond, new_slave); | ||
| 1758 | SLAVE_AD_INFO(new_slave).id = | 1732 | SLAVE_AD_INFO(new_slave).id = |
| 1759 | SLAVE_AD_INFO(new_slave->prev).id + 1; | 1733 | SLAVE_AD_INFO(prev_slave).id + 1; |
| 1760 | } | 1734 | } |
| 1761 | 1735 | ||
| 1762 | bond_3ad_bind_slave(new_slave); | 1736 | bond_3ad_bind_slave(new_slave); |
| @@ -1778,7 +1752,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) | |||
| 1778 | * so we can change it without calling change_active_interface() | 1752 | * so we can change it without calling change_active_interface() |
| 1779 | */ | 1753 | */ |
| 1780 | if (!bond->curr_active_slave && new_slave->link == BOND_LINK_UP) | 1754 | if (!bond->curr_active_slave && new_slave->link == BOND_LINK_UP) |
| 1781 | bond->curr_active_slave = new_slave; | 1755 | rcu_assign_pointer(bond->curr_active_slave, new_slave); |
| 1782 | 1756 | ||
| 1783 | break; | 1757 | break; |
| 1784 | } /* switch(bond_mode) */ | 1758 | } /* switch(bond_mode) */ |
| @@ -1875,7 +1849,7 @@ err_free: | |||
| 1875 | err_undo_flags: | 1849 | err_undo_flags: |
| 1876 | bond_compute_features(bond); | 1850 | bond_compute_features(bond); |
| 1877 | /* Enslave of first slave has failed and we need to fix master's mac */ | 1851 | /* Enslave of first slave has failed and we need to fix master's mac */ |
| 1878 | if (bond->slave_cnt == 0 && | 1852 | if (list_empty(&bond->slave_list) && |
| 1879 | ether_addr_equal(bond_dev->dev_addr, slave_dev->dev_addr)) | 1853 | ether_addr_equal(bond_dev->dev_addr, slave_dev->dev_addr)) |
| 1880 | eth_hw_addr_random(bond_dev); | 1854 | eth_hw_addr_random(bond_dev); |
| 1881 | 1855 | ||
| @@ -1931,15 +1905,6 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
| 1931 | netdev_rx_handler_unregister(slave_dev); | 1905 | netdev_rx_handler_unregister(slave_dev); |
| 1932 | write_lock_bh(&bond->lock); | 1906 | write_lock_bh(&bond->lock); |
| 1933 | 1907 | ||
| 1934 | if (!all && !bond->params.fail_over_mac) { | ||
| 1935 | if (ether_addr_equal(bond_dev->dev_addr, slave->perm_hwaddr) && | ||
| 1936 | bond->slave_cnt > 1) | ||
| 1937 | pr_warning("%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", | ||
| 1938 | bond_dev->name, slave_dev->name, | ||
| 1939 | slave->perm_hwaddr, | ||
| 1940 | bond_dev->name, slave_dev->name); | ||
| 1941 | } | ||
| 1942 | |||
| 1943 | /* Inform AD package of unbinding of slave. */ | 1908 | /* Inform AD package of unbinding of slave. */ |
| 1944 | if (bond->params.mode == BOND_MODE_8023AD) { | 1909 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1945 | /* must be called before the slave is | 1910 | /* must be called before the slave is |
| @@ -1960,6 +1925,15 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
| 1960 | /* release the slave from its bond */ | 1925 | /* release the slave from its bond */ |
| 1961 | bond_detach_slave(bond, slave); | 1926 | bond_detach_slave(bond, slave); |
| 1962 | 1927 | ||
| 1928 | if (!all && !bond->params.fail_over_mac) { | ||
| 1929 | if (ether_addr_equal(bond_dev->dev_addr, slave->perm_hwaddr) && | ||
| 1930 | !list_empty(&bond->slave_list)) | ||
| 1931 | 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", | ||
| 1932 | bond_dev->name, slave_dev->name, | ||
| 1933 | slave->perm_hwaddr, | ||
| 1934 | bond_dev->name, slave_dev->name); | ||
| 1935 | } | ||
| 1936 | |||
| 1963 | if (bond->primary_slave == slave) | 1937 | if (bond->primary_slave == slave) |
| 1964 | bond->primary_slave = NULL; | 1938 | bond->primary_slave = NULL; |
| 1965 | 1939 | ||
| @@ -1978,7 +1952,7 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
| 1978 | } | 1952 | } |
| 1979 | 1953 | ||
| 1980 | if (all) { | 1954 | if (all) { |
| 1981 | bond->curr_active_slave = NULL; | 1955 | rcu_assign_pointer(bond->curr_active_slave, NULL); |
| 1982 | } else if (oldcurrent == slave) { | 1956 | } else if (oldcurrent == slave) { |
| 1983 | /* | 1957 | /* |
| 1984 | * Note that we hold RTNL over this sequence, so there | 1958 | * Note that we hold RTNL over this sequence, so there |
| @@ -1996,7 +1970,7 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
| 1996 | write_lock_bh(&bond->lock); | 1970 | write_lock_bh(&bond->lock); |
| 1997 | } | 1971 | } |
| 1998 | 1972 | ||
| 1999 | if (bond->slave_cnt == 0) { | 1973 | if (list_empty(&bond->slave_list)) { |
| 2000 | bond_set_carrier(bond); | 1974 | bond_set_carrier(bond); |
| 2001 | eth_hw_addr_random(bond_dev); | 1975 | eth_hw_addr_random(bond_dev); |
| 2002 | 1976 | ||
| @@ -2010,8 +1984,9 @@ static int __bond_release_one(struct net_device *bond_dev, | |||
| 2010 | 1984 | ||
| 2011 | write_unlock_bh(&bond->lock); | 1985 | write_unlock_bh(&bond->lock); |
| 2012 | unblock_netpoll_tx(); | 1986 | unblock_netpoll_tx(); |
| 1987 | synchronize_rcu(); | ||
| 2013 | 1988 | ||
| 2014 | if (bond->slave_cnt == 0) { | 1989 | if (list_empty(&bond->slave_list)) { |
| 2015 | call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev); | 1990 | call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev); |
| 2016 | call_netdevice_notifiers(NETDEV_RELEASE, bond->dev); | 1991 | call_netdevice_notifiers(NETDEV_RELEASE, bond->dev); |
| 2017 | } | 1992 | } |
| @@ -2082,7 +2057,7 @@ static int bond_release_and_destroy(struct net_device *bond_dev, | |||
| 2082 | int ret; | 2057 | int ret; |
| 2083 | 2058 | ||
| 2084 | ret = bond_release(bond_dev, slave_dev); | 2059 | ret = bond_release(bond_dev, slave_dev); |
| 2085 | if ((ret == 0) && (bond->slave_cnt == 0)) { | 2060 | if (ret == 0 && list_empty(&bond->slave_list)) { |
| 2086 | bond_dev->priv_flags |= IFF_DISABLE_NETPOLL; | 2061 | bond_dev->priv_flags |= IFF_DISABLE_NETPOLL; |
| 2087 | pr_info("%s: destroying bond %s.\n", | 2062 | pr_info("%s: destroying bond %s.\n", |
| 2088 | bond_dev->name, bond_dev->name); | 2063 | bond_dev->name, bond_dev->name); |
| @@ -2119,23 +2094,19 @@ static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_devi | |||
| 2119 | 2094 | ||
| 2120 | read_lock(&bond->lock); | 2095 | read_lock(&bond->lock); |
| 2121 | 2096 | ||
| 2122 | read_lock(&bond->curr_slave_lock); | ||
| 2123 | old_active = bond->curr_active_slave; | 2097 | old_active = bond->curr_active_slave; |
| 2124 | read_unlock(&bond->curr_slave_lock); | ||
| 2125 | |||
| 2126 | new_active = bond_get_slave_by_dev(bond, slave_dev); | 2098 | new_active = bond_get_slave_by_dev(bond, slave_dev); |
| 2127 | |||
| 2128 | /* | 2099 | /* |
| 2129 | * Changing to the current active: do nothing; return success. | 2100 | * Changing to the current active: do nothing; return success. |
| 2130 | */ | 2101 | */ |
| 2131 | if (new_active && (new_active == old_active)) { | 2102 | if (new_active && new_active == old_active) { |
| 2132 | read_unlock(&bond->lock); | 2103 | read_unlock(&bond->lock); |
| 2133 | return 0; | 2104 | return 0; |
| 2134 | } | 2105 | } |
| 2135 | 2106 | ||
| 2136 | if ((new_active) && | 2107 | if (new_active && |
| 2137 | (old_active) && | 2108 | old_active && |
| 2138 | (new_active->link == BOND_LINK_UP) && | 2109 | new_active->link == BOND_LINK_UP && |
| 2139 | IS_UP(new_active->dev)) { | 2110 | IS_UP(new_active->dev)) { |
| 2140 | block_netpoll_tx(); | 2111 | block_netpoll_tx(); |
| 2141 | write_lock_bh(&bond->curr_slave_lock); | 2112 | write_lock_bh(&bond->curr_slave_lock); |
| @@ -2167,13 +2138,12 @@ static int bond_info_query(struct net_device *bond_dev, struct ifbond *info) | |||
| 2167 | static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info) | 2138 | static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info) |
| 2168 | { | 2139 | { |
| 2169 | struct bonding *bond = netdev_priv(bond_dev); | 2140 | struct bonding *bond = netdev_priv(bond_dev); |
| 2141 | int i = 0, res = -ENODEV; | ||
| 2170 | struct slave *slave; | 2142 | struct slave *slave; |
| 2171 | int i, res = -ENODEV; | ||
| 2172 | 2143 | ||
| 2173 | read_lock(&bond->lock); | 2144 | read_lock(&bond->lock); |
| 2174 | 2145 | bond_for_each_slave(bond, slave) { | |
| 2175 | bond_for_each_slave(bond, slave, i) { | 2146 | if (i++ == (int)info->slave_id) { |
| 2176 | if (i == (int)info->slave_id) { | ||
| 2177 | res = 0; | 2147 | res = 0; |
| 2178 | strcpy(info->slave_name, slave->dev->name); | 2148 | strcpy(info->slave_name, slave->dev->name); |
| 2179 | info->link = slave->link; | 2149 | info->link = slave->link; |
| @@ -2182,7 +2152,6 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in | |||
| 2182 | break; | 2152 | break; |
| 2183 | } | 2153 | } |
| 2184 | } | 2154 | } |
| 2185 | |||
| 2186 | read_unlock(&bond->lock); | 2155 | read_unlock(&bond->lock); |
| 2187 | 2156 | ||
| 2188 | return res; | 2157 | return res; |
| @@ -2193,13 +2162,13 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in | |||
| 2193 | 2162 | ||
| 2194 | static int bond_miimon_inspect(struct bonding *bond) | 2163 | static int bond_miimon_inspect(struct bonding *bond) |
| 2195 | { | 2164 | { |
| 2165 | int link_state, commit = 0; | ||
| 2196 | struct slave *slave; | 2166 | struct slave *slave; |
| 2197 | int i, link_state, commit = 0; | ||
| 2198 | bool ignore_updelay; | 2167 | bool ignore_updelay; |
| 2199 | 2168 | ||
| 2200 | ignore_updelay = !bond->curr_active_slave ? true : false; | 2169 | ignore_updelay = !bond->curr_active_slave ? true : false; |
| 2201 | 2170 | ||
| 2202 | bond_for_each_slave(bond, slave, i) { | 2171 | bond_for_each_slave(bond, slave) { |
| 2203 | slave->new_link = BOND_LINK_NOCHANGE; | 2172 | slave->new_link = BOND_LINK_NOCHANGE; |
| 2204 | 2173 | ||
| 2205 | link_state = bond_check_dev_link(bond, slave->dev, 0); | 2174 | link_state = bond_check_dev_link(bond, slave->dev, 0); |
| @@ -2294,9 +2263,8 @@ static int bond_miimon_inspect(struct bonding *bond) | |||
| 2294 | static void bond_miimon_commit(struct bonding *bond) | 2263 | static void bond_miimon_commit(struct bonding *bond) |
| 2295 | { | 2264 | { |
| 2296 | struct slave *slave; | 2265 | struct slave *slave; |
| 2297 | int i; | ||
| 2298 | 2266 | ||
| 2299 | bond_for_each_slave(bond, slave, i) { | 2267 | bond_for_each_slave(bond, slave) { |
| 2300 | switch (slave->new_link) { | 2268 | switch (slave->new_link) { |
| 2301 | case BOND_LINK_NOCHANGE: | 2269 | case BOND_LINK_NOCHANGE: |
| 2302 | continue; | 2270 | continue; |
| @@ -2401,7 +2369,7 @@ void bond_mii_monitor(struct work_struct *work) | |||
| 2401 | 2369 | ||
| 2402 | delay = msecs_to_jiffies(bond->params.miimon); | 2370 | delay = msecs_to_jiffies(bond->params.miimon); |
| 2403 | 2371 | ||
| 2404 | if (bond->slave_cnt == 0) | 2372 | if (list_empty(&bond->slave_list)) |
| 2405 | goto re_arm; | 2373 | goto re_arm; |
| 2406 | 2374 | ||
| 2407 | should_notify_peers = bond_should_notify_peers(bond); | 2375 | should_notify_peers = bond_should_notify_peers(bond); |
| @@ -2681,20 +2649,16 @@ void bond_loadbalance_arp_mon(struct work_struct *work) | |||
| 2681 | struct slave *slave, *oldcurrent; | 2649 | struct slave *slave, *oldcurrent; |
| 2682 | int do_failover = 0; | 2650 | int do_failover = 0; |
| 2683 | int delta_in_ticks, extra_ticks; | 2651 | int delta_in_ticks, extra_ticks; |
| 2684 | int i; | ||
| 2685 | 2652 | ||
| 2686 | read_lock(&bond->lock); | 2653 | read_lock(&bond->lock); |
| 2687 | 2654 | ||
| 2688 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); | 2655 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); |
| 2689 | extra_ticks = delta_in_ticks / 2; | 2656 | extra_ticks = delta_in_ticks / 2; |
| 2690 | 2657 | ||
| 2691 | if (bond->slave_cnt == 0) | 2658 | if (list_empty(&bond->slave_list)) |
| 2692 | goto re_arm; | 2659 | goto re_arm; |
| 2693 | 2660 | ||
| 2694 | read_lock(&bond->curr_slave_lock); | ||
| 2695 | oldcurrent = bond->curr_active_slave; | 2661 | oldcurrent = bond->curr_active_slave; |
| 2696 | read_unlock(&bond->curr_slave_lock); | ||
| 2697 | |||
| 2698 | /* see if any of the previous devices are up now (i.e. they have | 2662 | /* see if any of the previous devices are up now (i.e. they have |
| 2699 | * xmt and rcv traffic). the curr_active_slave does not come into | 2663 | * xmt and rcv traffic). the curr_active_slave does not come into |
| 2700 | * the picture unless it is null. also, slave->jiffies is not needed | 2664 | * the picture unless it is null. also, slave->jiffies is not needed |
| @@ -2703,7 +2667,7 @@ void bond_loadbalance_arp_mon(struct work_struct *work) | |||
| 2703 | * TODO: what about up/down delay in arp mode? it wasn't here before | 2667 | * TODO: what about up/down delay in arp mode? it wasn't here before |
| 2704 | * so it can wait | 2668 | * so it can wait |
| 2705 | */ | 2669 | */ |
| 2706 | bond_for_each_slave(bond, slave, i) { | 2670 | bond_for_each_slave(bond, slave) { |
| 2707 | unsigned long trans_start = dev_trans_start(slave->dev); | 2671 | unsigned long trans_start = dev_trans_start(slave->dev); |
| 2708 | 2672 | ||
| 2709 | if (slave->link != BOND_LINK_UP) { | 2673 | if (slave->link != BOND_LINK_UP) { |
| @@ -2800,10 +2764,10 @@ re_arm: | |||
| 2800 | */ | 2764 | */ |
| 2801 | static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks) | 2765 | static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks) |
| 2802 | { | 2766 | { |
| 2803 | struct slave *slave; | ||
| 2804 | int i, commit = 0; | ||
| 2805 | unsigned long trans_start; | 2767 | unsigned long trans_start; |
| 2768 | struct slave *slave; | ||
| 2806 | int extra_ticks; | 2769 | int extra_ticks; |
| 2770 | int commit = 0; | ||
| 2807 | 2771 | ||
| 2808 | /* All the time comparisons below need some extra time. Otherwise, on | 2772 | /* All the time comparisons below need some extra time. Otherwise, on |
| 2809 | * fast networks the ARP probe/reply may arrive within the same jiffy | 2773 | * fast networks the ARP probe/reply may arrive within the same jiffy |
| @@ -2812,7 +2776,7 @@ static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks) | |||
| 2812 | */ | 2776 | */ |
| 2813 | extra_ticks = delta_in_ticks / 2; | 2777 | extra_ticks = delta_in_ticks / 2; |
| 2814 | 2778 | ||
| 2815 | bond_for_each_slave(bond, slave, i) { | 2779 | bond_for_each_slave(bond, slave) { |
| 2816 | slave->new_link = BOND_LINK_NOCHANGE; | 2780 | slave->new_link = BOND_LINK_NOCHANGE; |
| 2817 | 2781 | ||
| 2818 | if (slave->link != BOND_LINK_UP) { | 2782 | if (slave->link != BOND_LINK_UP) { |
| @@ -2891,11 +2855,10 @@ static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks) | |||
| 2891 | */ | 2855 | */ |
| 2892 | static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks) | 2856 | static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks) |
| 2893 | { | 2857 | { |
| 2894 | struct slave *slave; | ||
| 2895 | int i; | ||
| 2896 | unsigned long trans_start; | 2858 | unsigned long trans_start; |
| 2859 | struct slave *slave; | ||
| 2897 | 2860 | ||
| 2898 | bond_for_each_slave(bond, slave, i) { | 2861 | bond_for_each_slave(bond, slave) { |
| 2899 | switch (slave->new_link) { | 2862 | switch (slave->new_link) { |
| 2900 | case BOND_LINK_NOCHANGE: | 2863 | case BOND_LINK_NOCHANGE: |
| 2901 | continue; | 2864 | continue; |
| @@ -2968,7 +2931,7 @@ do_failover: | |||
| 2968 | */ | 2931 | */ |
| 2969 | static void bond_ab_arp_probe(struct bonding *bond) | 2932 | static void bond_ab_arp_probe(struct bonding *bond) |
| 2970 | { | 2933 | { |
| 2971 | struct slave *slave; | 2934 | struct slave *slave, *next_slave; |
| 2972 | int i; | 2935 | int i; |
| 2973 | 2936 | ||
| 2974 | read_lock(&bond->curr_slave_lock); | 2937 | read_lock(&bond->curr_slave_lock); |
| @@ -2992,7 +2955,7 @@ static void bond_ab_arp_probe(struct bonding *bond) | |||
| 2992 | */ | 2955 | */ |
| 2993 | 2956 | ||
| 2994 | if (!bond->current_arp_slave) { | 2957 | if (!bond->current_arp_slave) { |
| 2995 | bond->current_arp_slave = bond->first_slave; | 2958 | bond->current_arp_slave = bond_first_slave(bond); |
| 2996 | if (!bond->current_arp_slave) | 2959 | if (!bond->current_arp_slave) |
| 2997 | return; | 2960 | return; |
| 2998 | } | 2961 | } |
| @@ -3000,7 +2963,8 @@ static void bond_ab_arp_probe(struct bonding *bond) | |||
| 3000 | bond_set_slave_inactive_flags(bond->current_arp_slave); | 2963 | bond_set_slave_inactive_flags(bond->current_arp_slave); |
| 3001 | 2964 | ||
| 3002 | /* search for next candidate */ | 2965 | /* search for next candidate */ |
| 3003 | bond_for_each_slave_from(bond, slave, i, bond->current_arp_slave->next) { | 2966 | next_slave = bond_next_slave(bond, bond->current_arp_slave); |
| 2967 | bond_for_each_slave_from(bond, slave, i, next_slave) { | ||
| 3004 | if (IS_UP(slave->dev)) { | 2968 | if (IS_UP(slave->dev)) { |
| 3005 | slave->link = BOND_LINK_BACK; | 2969 | slave->link = BOND_LINK_BACK; |
| 3006 | bond_set_slave_active_flags(slave); | 2970 | bond_set_slave_active_flags(slave); |
| @@ -3041,7 +3005,7 @@ void bond_activebackup_arp_mon(struct work_struct *work) | |||
| 3041 | 3005 | ||
| 3042 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); | 3006 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); |
| 3043 | 3007 | ||
| 3044 | if (bond->slave_cnt == 0) | 3008 | if (list_empty(&bond->slave_list)) |
| 3045 | goto re_arm; | 3009 | goto re_arm; |
| 3046 | 3010 | ||
| 3047 | should_notify_peers = bond_should_notify_peers(bond); | 3011 | should_notify_peers = bond_should_notify_peers(bond); |
| @@ -3361,13 +3325,12 @@ static int bond_open(struct net_device *bond_dev) | |||
| 3361 | { | 3325 | { |
| 3362 | struct bonding *bond = netdev_priv(bond_dev); | 3326 | struct bonding *bond = netdev_priv(bond_dev); |
| 3363 | struct slave *slave; | 3327 | struct slave *slave; |
| 3364 | int i; | ||
| 3365 | 3328 | ||
| 3366 | /* reset slave->backup and slave->inactive */ | 3329 | /* reset slave->backup and slave->inactive */ |
| 3367 | read_lock(&bond->lock); | 3330 | read_lock(&bond->lock); |
| 3368 | if (bond->slave_cnt > 0) { | 3331 | if (!list_empty(&bond->slave_list)) { |
| 3369 | read_lock(&bond->curr_slave_lock); | 3332 | read_lock(&bond->curr_slave_lock); |
| 3370 | bond_for_each_slave(bond, slave, i) { | 3333 | bond_for_each_slave(bond, slave) { |
| 3371 | if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP) | 3334 | if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP) |
| 3372 | && (slave != bond->curr_active_slave)) { | 3335 | && (slave != bond->curr_active_slave)) { |
| 3373 | bond_set_slave_inactive_flags(slave); | 3336 | bond_set_slave_inactive_flags(slave); |
| @@ -3435,13 +3398,11 @@ static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev, | |||
| 3435 | struct bonding *bond = netdev_priv(bond_dev); | 3398 | struct bonding *bond = netdev_priv(bond_dev); |
| 3436 | struct rtnl_link_stats64 temp; | 3399 | struct rtnl_link_stats64 temp; |
| 3437 | struct slave *slave; | 3400 | struct slave *slave; |
| 3438 | int i; | ||
| 3439 | 3401 | ||
| 3440 | memset(stats, 0, sizeof(*stats)); | 3402 | memset(stats, 0, sizeof(*stats)); |
| 3441 | 3403 | ||
| 3442 | read_lock_bh(&bond->lock); | 3404 | read_lock_bh(&bond->lock); |
| 3443 | 3405 | bond_for_each_slave(bond, slave) { | |
| 3444 | bond_for_each_slave(bond, slave, i) { | ||
| 3445 | const struct rtnl_link_stats64 *sstats = | 3406 | const struct rtnl_link_stats64 *sstats = |
| 3446 | dev_get_stats(slave->dev, &temp); | 3407 | dev_get_stats(slave->dev, &temp); |
| 3447 | 3408 | ||
| @@ -3471,7 +3432,6 @@ static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev, | |||
| 3471 | stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors; | 3432 | stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors; |
| 3472 | stats->tx_window_errors += sstats->tx_window_errors; | 3433 | stats->tx_window_errors += sstats->tx_window_errors; |
| 3473 | } | 3434 | } |
| 3474 | |||
| 3475 | read_unlock_bh(&bond->lock); | 3435 | read_unlock_bh(&bond->lock); |
| 3476 | 3436 | ||
| 3477 | return stats; | 3437 | return stats; |
| @@ -3610,7 +3570,6 @@ static void bond_set_rx_mode(struct net_device *bond_dev) | |||
| 3610 | { | 3570 | { |
| 3611 | struct bonding *bond = netdev_priv(bond_dev); | 3571 | struct bonding *bond = netdev_priv(bond_dev); |
| 3612 | struct slave *slave; | 3572 | struct slave *slave; |
| 3613 | int i; | ||
| 3614 | 3573 | ||
| 3615 | read_lock(&bond->lock); | 3574 | read_lock(&bond->lock); |
| 3616 | 3575 | ||
| @@ -3623,7 +3582,7 @@ static void bond_set_rx_mode(struct net_device *bond_dev) | |||
| 3623 | } | 3582 | } |
| 3624 | read_unlock(&bond->curr_slave_lock); | 3583 | read_unlock(&bond->curr_slave_lock); |
| 3625 | } else { | 3584 | } else { |
| 3626 | bond_for_each_slave(bond, slave, i) { | 3585 | bond_for_each_slave(bond, slave) { |
| 3627 | dev_uc_sync_multiple(slave->dev, bond_dev); | 3586 | dev_uc_sync_multiple(slave->dev, bond_dev); |
| 3628 | dev_mc_sync_multiple(slave->dev, bond_dev); | 3587 | dev_mc_sync_multiple(slave->dev, bond_dev); |
| 3629 | } | 3588 | } |
| @@ -3635,16 +3594,15 @@ static void bond_set_rx_mode(struct net_device *bond_dev) | |||
| 3635 | static int bond_neigh_init(struct neighbour *n) | 3594 | static int bond_neigh_init(struct neighbour *n) |
| 3636 | { | 3595 | { |
| 3637 | struct bonding *bond = netdev_priv(n->dev); | 3596 | struct bonding *bond = netdev_priv(n->dev); |
| 3638 | struct slave *slave = bond->first_slave; | ||
| 3639 | const struct net_device_ops *slave_ops; | 3597 | const struct net_device_ops *slave_ops; |
| 3640 | struct neigh_parms parms; | 3598 | struct neigh_parms parms; |
| 3599 | struct slave *slave; | ||
| 3641 | int ret; | 3600 | int ret; |
| 3642 | 3601 | ||
| 3602 | slave = bond_first_slave(bond); | ||
| 3643 | if (!slave) | 3603 | if (!slave) |
| 3644 | return 0; | 3604 | return 0; |
| 3645 | |||
| 3646 | slave_ops = slave->dev->netdev_ops; | 3605 | slave_ops = slave->dev->netdev_ops; |
| 3647 | |||
| 3648 | if (!slave_ops->ndo_neigh_setup) | 3606 | if (!slave_ops->ndo_neigh_setup) |
| 3649 | return 0; | 3607 | return 0; |
| 3650 | 3608 | ||
| @@ -3687,9 +3645,8 @@ static int bond_neigh_setup(struct net_device *dev, | |||
| 3687 | static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) | 3645 | static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) |
| 3688 | { | 3646 | { |
| 3689 | struct bonding *bond = netdev_priv(bond_dev); | 3647 | struct bonding *bond = netdev_priv(bond_dev); |
| 3690 | struct slave *slave, *stop_at; | 3648 | struct slave *slave; |
| 3691 | int res = 0; | 3649 | int res = 0; |
| 3692 | int i; | ||
| 3693 | 3650 | ||
| 3694 | pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond, | 3651 | pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond, |
| 3695 | (bond_dev ? bond_dev->name : "None"), new_mtu); | 3652 | (bond_dev ? bond_dev->name : "None"), new_mtu); |
| @@ -3709,10 +3666,10 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) | |||
| 3709 | * call to the base driver. | 3666 | * call to the base driver. |
| 3710 | */ | 3667 | */ |
| 3711 | 3668 | ||
| 3712 | bond_for_each_slave(bond, slave, i) { | 3669 | bond_for_each_slave(bond, slave) { |
| 3713 | pr_debug("s %p s->p %p c_m %p\n", | 3670 | pr_debug("s %p s->p %p c_m %p\n", |
| 3714 | slave, | 3671 | slave, |
| 3715 | slave->prev, | 3672 | bond_prev_slave(bond, slave), |
| 3716 | slave->dev->netdev_ops->ndo_change_mtu); | 3673 | slave->dev->netdev_ops->ndo_change_mtu); |
| 3717 | 3674 | ||
| 3718 | res = dev_set_mtu(slave->dev, new_mtu); | 3675 | res = dev_set_mtu(slave->dev, new_mtu); |
| @@ -3737,8 +3694,7 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) | |||
| 3737 | 3694 | ||
| 3738 | unwind: | 3695 | unwind: |
| 3739 | /* unwind from head to the slave that failed */ | 3696 | /* unwind from head to the slave that failed */ |
| 3740 | stop_at = slave; | 3697 | bond_for_each_slave_continue_reverse(bond, slave) { |
| 3741 | bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) { | ||
| 3742 | int tmp_res; | 3698 | int tmp_res; |
| 3743 | 3699 | ||
| 3744 | tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu); | 3700 | tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu); |
| @@ -3762,9 +3718,8 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr) | |||
| 3762 | { | 3718 | { |
| 3763 | struct bonding *bond = netdev_priv(bond_dev); | 3719 | struct bonding *bond = netdev_priv(bond_dev); |
| 3764 | struct sockaddr *sa = addr, tmp_sa; | 3720 | struct sockaddr *sa = addr, tmp_sa; |
| 3765 | struct slave *slave, *stop_at; | 3721 | struct slave *slave; |
| 3766 | int res = 0; | 3722 | int res = 0; |
| 3767 | int i; | ||
| 3768 | 3723 | ||
| 3769 | if (bond->params.mode == BOND_MODE_ALB) | 3724 | if (bond->params.mode == BOND_MODE_ALB) |
| 3770 | return bond_alb_set_mac_address(bond_dev, addr); | 3725 | return bond_alb_set_mac_address(bond_dev, addr); |
| @@ -3797,7 +3752,7 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr) | |||
| 3797 | * call to the base driver. | 3752 | * call to the base driver. |
| 3798 | */ | 3753 | */ |
| 3799 | 3754 | ||
| 3800 | bond_for_each_slave(bond, slave, i) { | 3755 | bond_for_each_slave(bond, slave) { |
| 3801 | const struct net_device_ops *slave_ops = slave->dev->netdev_ops; | 3756 | const struct net_device_ops *slave_ops = slave->dev->netdev_ops; |
| 3802 | pr_debug("slave %p %s\n", slave, slave->dev->name); | 3757 | pr_debug("slave %p %s\n", slave, slave->dev->name); |
| 3803 | 3758 | ||
| @@ -3829,8 +3784,7 @@ unwind: | |||
| 3829 | tmp_sa.sa_family = bond_dev->type; | 3784 | tmp_sa.sa_family = bond_dev->type; |
| 3830 | 3785 | ||
| 3831 | /* unwind from head to the slave that failed */ | 3786 | /* unwind from head to the slave that failed */ |
| 3832 | stop_at = slave; | 3787 | bond_for_each_slave_continue_reverse(bond, slave) { |
| 3833 | bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) { | ||
| 3834 | int tmp_res; | 3788 | int tmp_res; |
| 3835 | 3789 | ||
| 3836 | tmp_res = dev_set_mac_address(slave->dev, &tmp_sa); | 3790 | tmp_res = dev_set_mac_address(slave->dev, &tmp_sa); |
| @@ -3843,12 +3797,50 @@ unwind: | |||
| 3843 | return res; | 3797 | return res; |
| 3844 | } | 3798 | } |
| 3845 | 3799 | ||
| 3800 | /** | ||
| 3801 | * bond_xmit_slave_id - transmit skb through slave with slave_id | ||
| 3802 | * @bond: bonding device that is transmitting | ||
| 3803 | * @skb: buffer to transmit | ||
| 3804 | * @slave_id: slave id up to slave_cnt-1 through which to transmit | ||
| 3805 | * | ||
| 3806 | * This function tries to transmit through slave with slave_id but in case | ||
| 3807 | * it fails, it tries to find the first available slave for transmission. | ||
| 3808 | * The skb is consumed in all cases, thus the function is void. | ||
| 3809 | */ | ||
| 3810 | void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id) | ||
| 3811 | { | ||
| 3812 | struct slave *slave; | ||
| 3813 | int i = slave_id; | ||
| 3814 | |||
| 3815 | /* Here we start from the slave with slave_id */ | ||
| 3816 | bond_for_each_slave_rcu(bond, slave) { | ||
| 3817 | if (--i < 0) { | ||
| 3818 | if (slave_can_tx(slave)) { | ||
| 3819 | bond_dev_queue_xmit(bond, skb, slave->dev); | ||
| 3820 | return; | ||
| 3821 | } | ||
| 3822 | } | ||
| 3823 | } | ||
| 3824 | |||
| 3825 | /* Here we start from the first slave up to slave_id */ | ||
| 3826 | i = slave_id; | ||
| 3827 | bond_for_each_slave_rcu(bond, slave) { | ||
| 3828 | if (--i < 0) | ||
| 3829 | break; | ||
| 3830 | if (slave_can_tx(slave)) { | ||
| 3831 | bond_dev_queue_xmit(bond, skb, slave->dev); | ||
| 3832 | return; | ||
| 3833 | } | ||
| 3834 | } | ||
| 3835 | /* no slave that can tx has been found */ | ||
| 3836 | kfree_skb(skb); | ||
| 3837 | } | ||
| 3838 | |||
| 3846 | static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev) | 3839 | static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev) |
| 3847 | { | 3840 | { |
| 3848 | struct bonding *bond = netdev_priv(bond_dev); | 3841 | struct bonding *bond = netdev_priv(bond_dev); |
| 3849 | struct slave *slave, *start_at; | ||
| 3850 | int i, slave_no, res = 1; | ||
| 3851 | struct iphdr *iph = ip_hdr(skb); | 3842 | struct iphdr *iph = ip_hdr(skb); |
| 3843 | struct slave *slave; | ||
| 3852 | 3844 | ||
| 3853 | /* | 3845 | /* |
| 3854 | * Start with the curr_active_slave that joined the bond as the | 3846 | * Start with the curr_active_slave that joined the bond as the |
| @@ -3857,50 +3849,20 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev | |||
| 3857 | * send the join/membership reports. The curr_active_slave found | 3849 | * send the join/membership reports. The curr_active_slave found |
| 3858 | * will send all of this type of traffic. | 3850 | * will send all of this type of traffic. |
| 3859 | */ | 3851 | */ |
| 3860 | if ((iph->protocol == IPPROTO_IGMP) && | 3852 | if (iph->protocol == IPPROTO_IGMP && skb->protocol == htons(ETH_P_IP)) { |
| 3861 | (skb->protocol == htons(ETH_P_IP))) { | 3853 | slave = rcu_dereference(bond->curr_active_slave); |
| 3862 | 3854 | if (slave && slave_can_tx(slave)) | |
| 3863 | read_lock(&bond->curr_slave_lock); | 3855 | bond_dev_queue_xmit(bond, skb, slave->dev); |
| 3864 | slave = bond->curr_active_slave; | 3856 | else |
| 3865 | read_unlock(&bond->curr_slave_lock); | 3857 | bond_xmit_slave_id(bond, skb, 0); |
| 3866 | |||
| 3867 | if (!slave) | ||
| 3868 | goto out; | ||
| 3869 | } else { | 3858 | } else { |
| 3870 | /* | 3859 | bond_xmit_slave_id(bond, skb, |
| 3871 | * Concurrent TX may collide on rr_tx_counter; we accept | 3860 | bond->rr_tx_counter++ % bond->slave_cnt); |
| 3872 | * that as being rare enough not to justify using an | ||
| 3873 | * atomic op here. | ||
| 3874 | */ | ||
| 3875 | slave_no = bond->rr_tx_counter++ % bond->slave_cnt; | ||
| 3876 | |||
| 3877 | bond_for_each_slave(bond, slave, i) { | ||
| 3878 | slave_no--; | ||
| 3879 | if (slave_no < 0) | ||
| 3880 | break; | ||
| 3881 | } | ||
| 3882 | } | ||
| 3883 | |||
| 3884 | start_at = slave; | ||
| 3885 | bond_for_each_slave_from(bond, slave, i, start_at) { | ||
| 3886 | if (IS_UP(slave->dev) && | ||
| 3887 | (slave->link == BOND_LINK_UP) && | ||
| 3888 | bond_is_active_slave(slave)) { | ||
| 3889 | res = bond_dev_queue_xmit(bond, skb, slave->dev); | ||
| 3890 | break; | ||
| 3891 | } | ||
| 3892 | } | ||
| 3893 | |||
| 3894 | out: | ||
| 3895 | if (res) { | ||
| 3896 | /* no suitable interface, frame not sent */ | ||
| 3897 | kfree_skb(skb); | ||
| 3898 | } | 3861 | } |
| 3899 | 3862 | ||
| 3900 | return NETDEV_TX_OK; | 3863 | return NETDEV_TX_OK; |
| 3901 | } | 3864 | } |
| 3902 | 3865 | ||
| 3903 | |||
| 3904 | /* | 3866 | /* |
| 3905 | * in active-backup mode, we know that bond->curr_active_slave is always valid if | 3867 | * in active-backup mode, we know that bond->curr_active_slave is always valid if |
| 3906 | * the bond has a usable interface. | 3868 | * the bond has a usable interface. |
| @@ -3908,18 +3870,12 @@ out: | |||
| 3908 | static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_dev) | 3870 | static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_dev) |
| 3909 | { | 3871 | { |
| 3910 | struct bonding *bond = netdev_priv(bond_dev); | 3872 | struct bonding *bond = netdev_priv(bond_dev); |
| 3911 | int res = 1; | 3873 | struct slave *slave; |
| 3912 | |||
| 3913 | read_lock(&bond->curr_slave_lock); | ||
| 3914 | |||
| 3915 | if (bond->curr_active_slave) | ||
| 3916 | res = bond_dev_queue_xmit(bond, skb, | ||
| 3917 | bond->curr_active_slave->dev); | ||
| 3918 | |||
| 3919 | read_unlock(&bond->curr_slave_lock); | ||
| 3920 | 3874 | ||
| 3921 | if (res) | 3875 | slave = rcu_dereference(bond->curr_active_slave); |
| 3922 | /* no suitable interface, frame not sent */ | 3876 | if (slave) |
| 3877 | bond_dev_queue_xmit(bond, skb, slave->dev); | ||
| 3878 | else | ||
| 3923 | kfree_skb(skb); | 3879 | kfree_skb(skb); |
| 3924 | 3880 | ||
| 3925 | return NETDEV_TX_OK; | 3881 | return NETDEV_TX_OK; |
| @@ -3933,87 +3889,39 @@ static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_d | |||
| 3933 | static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev) | 3889 | static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev) |
| 3934 | { | 3890 | { |
| 3935 | struct bonding *bond = netdev_priv(bond_dev); | 3891 | struct bonding *bond = netdev_priv(bond_dev); |
| 3936 | struct slave *slave, *start_at; | ||
| 3937 | int slave_no; | ||
| 3938 | int i; | ||
| 3939 | int res = 1; | ||
| 3940 | |||
| 3941 | slave_no = bond->xmit_hash_policy(skb, bond->slave_cnt); | ||
| 3942 | |||
| 3943 | bond_for_each_slave(bond, slave, i) { | ||
| 3944 | slave_no--; | ||
| 3945 | if (slave_no < 0) | ||
| 3946 | break; | ||
| 3947 | } | ||
| 3948 | |||
| 3949 | start_at = slave; | ||
| 3950 | |||
| 3951 | bond_for_each_slave_from(bond, slave, i, start_at) { | ||
| 3952 | if (IS_UP(slave->dev) && | ||
| 3953 | (slave->link == BOND_LINK_UP) && | ||
| 3954 | bond_is_active_slave(slave)) { | ||
| 3955 | res = bond_dev_queue_xmit(bond, skb, slave->dev); | ||
| 3956 | break; | ||
| 3957 | } | ||
| 3958 | } | ||
| 3959 | 3892 | ||
| 3960 | if (res) { | 3893 | bond_xmit_slave_id(bond, skb, |
| 3961 | /* no suitable interface, frame not sent */ | 3894 | bond->xmit_hash_policy(skb, bond->slave_cnt)); |
| 3962 | kfree_skb(skb); | ||
| 3963 | } | ||
| 3964 | 3895 | ||
| 3965 | return NETDEV_TX_OK; | 3896 | return NETDEV_TX_OK; |
| 3966 | } | 3897 | } |
| 3967 | 3898 | ||
| 3968 | /* | 3899 | /* in broadcast mode, we send everything to all usable interfaces. */ |
| 3969 | * in broadcast mode, we send everything to all usable interfaces. | ||
| 3970 | */ | ||
| 3971 | static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev) | 3900 | static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev) |
| 3972 | { | 3901 | { |
| 3973 | struct bonding *bond = netdev_priv(bond_dev); | 3902 | struct bonding *bond = netdev_priv(bond_dev); |
| 3974 | struct slave *slave, *start_at; | 3903 | struct slave *slave = NULL; |
| 3975 | struct net_device *tx_dev = NULL; | ||
| 3976 | int i; | ||
| 3977 | int res = 1; | ||
| 3978 | |||
| 3979 | read_lock(&bond->curr_slave_lock); | ||
| 3980 | start_at = bond->curr_active_slave; | ||
| 3981 | read_unlock(&bond->curr_slave_lock); | ||
| 3982 | |||
| 3983 | if (!start_at) | ||
| 3984 | goto out; | ||
| 3985 | 3904 | ||
| 3986 | bond_for_each_slave_from(bond, slave, i, start_at) { | 3905 | bond_for_each_slave_rcu(bond, slave) { |
| 3987 | if (IS_UP(slave->dev) && | 3906 | if (bond_is_last_slave(bond, slave)) |
| 3988 | (slave->link == BOND_LINK_UP) && | 3907 | break; |
| 3989 | bond_is_active_slave(slave)) { | 3908 | if (IS_UP(slave->dev) && slave->link == BOND_LINK_UP) { |
| 3990 | if (tx_dev) { | 3909 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
| 3991 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); | ||
| 3992 | if (!skb2) { | ||
| 3993 | pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n", | ||
| 3994 | bond_dev->name); | ||
| 3995 | continue; | ||
| 3996 | } | ||
| 3997 | 3910 | ||
| 3998 | res = bond_dev_queue_xmit(bond, skb2, tx_dev); | 3911 | if (!skb2) { |
| 3999 | if (res) { | 3912 | pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n", |
| 4000 | kfree_skb(skb2); | 3913 | bond_dev->name); |
| 4001 | continue; | 3914 | continue; |
| 4002 | } | ||
| 4003 | } | 3915 | } |
| 4004 | tx_dev = slave->dev; | 3916 | /* bond_dev_queue_xmit always returns 0 */ |
| 3917 | bond_dev_queue_xmit(bond, skb2, slave->dev); | ||
| 4005 | } | 3918 | } |
| 4006 | } | 3919 | } |
| 4007 | 3920 | if (slave && IS_UP(slave->dev) && slave->link == BOND_LINK_UP) | |
| 4008 | if (tx_dev) | 3921 | bond_dev_queue_xmit(bond, skb, slave->dev); |
| 4009 | res = bond_dev_queue_xmit(bond, skb, tx_dev); | 3922 | else |
| 4010 | |||
| 4011 | out: | ||
| 4012 | if (res) | ||
| 4013 | /* no suitable interface, frame not sent */ | ||
| 4014 | kfree_skb(skb); | 3923 | kfree_skb(skb); |
| 4015 | 3924 | ||
| 4016 | /* frame sent to all suitable interfaces */ | ||
| 4017 | return NETDEV_TX_OK; | 3925 | return NETDEV_TX_OK; |
| 4018 | } | 3926 | } |
| 4019 | 3927 | ||
| @@ -4041,15 +3949,15 @@ static void bond_set_xmit_hash_policy(struct bonding *bond) | |||
| 4041 | static inline int bond_slave_override(struct bonding *bond, | 3949 | static inline int bond_slave_override(struct bonding *bond, |
| 4042 | struct sk_buff *skb) | 3950 | struct sk_buff *skb) |
| 4043 | { | 3951 | { |
| 4044 | int i, res = 1; | ||
| 4045 | struct slave *slave = NULL; | 3952 | struct slave *slave = NULL; |
| 4046 | struct slave *check_slave; | 3953 | struct slave *check_slave; |
| 3954 | int res = 1; | ||
| 4047 | 3955 | ||
| 4048 | if (!skb->queue_mapping) | 3956 | if (!skb->queue_mapping) |
| 4049 | return 1; | 3957 | return 1; |
| 4050 | 3958 | ||
| 4051 | /* Find out if any slaves have the same mapping as this skb. */ | 3959 | /* Find out if any slaves have the same mapping as this skb. */ |
| 4052 | bond_for_each_slave(bond, check_slave, i) { | 3960 | bond_for_each_slave_rcu(bond, check_slave) { |
| 4053 | if (check_slave->queue_id == skb->queue_mapping) { | 3961 | if (check_slave->queue_id == skb->queue_mapping) { |
| 4054 | slave = check_slave; | 3962 | slave = check_slave; |
| 4055 | break; | 3963 | break; |
| @@ -4134,14 +4042,12 @@ static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
| 4134 | if (is_netpoll_tx_blocked(dev)) | 4042 | if (is_netpoll_tx_blocked(dev)) |
| 4135 | return NETDEV_TX_BUSY; | 4043 | return NETDEV_TX_BUSY; |
| 4136 | 4044 | ||
| 4137 | read_lock(&bond->lock); | 4045 | rcu_read_lock(); |
| 4138 | 4046 | if (!list_empty(&bond->slave_list)) | |
| 4139 | if (bond->slave_cnt) | ||
| 4140 | ret = __bond_start_xmit(skb, dev); | 4047 | ret = __bond_start_xmit(skb, dev); |
| 4141 | else | 4048 | else |
| 4142 | kfree_skb(skb); | 4049 | kfree_skb(skb); |
| 4143 | 4050 | rcu_read_unlock(); | |
| 4144 | read_unlock(&bond->lock); | ||
| 4145 | 4051 | ||
| 4146 | return ret; | 4052 | return ret; |
| 4147 | } | 4053 | } |
| @@ -4182,9 +4088,8 @@ static int bond_ethtool_get_settings(struct net_device *bond_dev, | |||
| 4182 | struct ethtool_cmd *ecmd) | 4088 | struct ethtool_cmd *ecmd) |
| 4183 | { | 4089 | { |
| 4184 | struct bonding *bond = netdev_priv(bond_dev); | 4090 | struct bonding *bond = netdev_priv(bond_dev); |
| 4185 | struct slave *slave; | ||
| 4186 | int i; | ||
| 4187 | unsigned long speed = 0; | 4091 | unsigned long speed = 0; |
| 4092 | struct slave *slave; | ||
| 4188 | 4093 | ||
| 4189 | ecmd->duplex = DUPLEX_UNKNOWN; | 4094 | ecmd->duplex = DUPLEX_UNKNOWN; |
| 4190 | ecmd->port = PORT_OTHER; | 4095 | ecmd->port = PORT_OTHER; |
| @@ -4195,7 +4100,7 @@ static int bond_ethtool_get_settings(struct net_device *bond_dev, | |||
| 4195 | * this is an accurate maximum. | 4100 | * this is an accurate maximum. |
| 4196 | */ | 4101 | */ |
| 4197 | read_lock(&bond->lock); | 4102 | read_lock(&bond->lock); |
| 4198 | bond_for_each_slave(bond, slave, i) { | 4103 | bond_for_each_slave(bond, slave) { |
| 4199 | if (SLAVE_IS_OK(slave)) { | 4104 | if (SLAVE_IS_OK(slave)) { |
| 4200 | if (slave->speed != SPEED_UNKNOWN) | 4105 | if (slave->speed != SPEED_UNKNOWN) |
| 4201 | speed += slave->speed; | 4106 | speed += slave->speed; |
| @@ -4206,6 +4111,7 @@ static int bond_ethtool_get_settings(struct net_device *bond_dev, | |||
| 4206 | } | 4111 | } |
| 4207 | ethtool_cmd_speed_set(ecmd, speed ? : SPEED_UNKNOWN); | 4112 | ethtool_cmd_speed_set(ecmd, speed ? : SPEED_UNKNOWN); |
| 4208 | read_unlock(&bond->lock); | 4113 | read_unlock(&bond->lock); |
| 4114 | |||
| 4209 | return 0; | 4115 | return 0; |
| 4210 | } | 4116 | } |
| 4211 | 4117 | ||
| @@ -4269,7 +4175,7 @@ static void bond_setup(struct net_device *bond_dev) | |||
| 4269 | /* initialize rwlocks */ | 4175 | /* initialize rwlocks */ |
| 4270 | rwlock_init(&bond->lock); | 4176 | rwlock_init(&bond->lock); |
| 4271 | rwlock_init(&bond->curr_slave_lock); | 4177 | rwlock_init(&bond->curr_slave_lock); |
| 4272 | 4178 | INIT_LIST_HEAD(&bond->slave_list); | |
| 4273 | bond->params = bonding_defaults; | 4179 | bond->params = bonding_defaults; |
| 4274 | 4180 | ||
| 4275 | /* Initialize pointers */ | 4181 | /* Initialize pointers */ |
| @@ -4326,13 +4232,14 @@ static void bond_setup(struct net_device *bond_dev) | |||
| 4326 | static void bond_uninit(struct net_device *bond_dev) | 4232 | static void bond_uninit(struct net_device *bond_dev) |
| 4327 | { | 4233 | { |
| 4328 | struct bonding *bond = netdev_priv(bond_dev); | 4234 | struct bonding *bond = netdev_priv(bond_dev); |
| 4235 | struct slave *slave, *tmp_slave; | ||
| 4329 | struct vlan_entry *vlan, *tmp; | 4236 | struct vlan_entry *vlan, *tmp; |
| 4330 | 4237 | ||
| 4331 | bond_netpoll_cleanup(bond_dev); | 4238 | bond_netpoll_cleanup(bond_dev); |
| 4332 | 4239 | ||
| 4333 | /* Release the bonded slaves */ | 4240 | /* Release the bonded slaves */ |
| 4334 | while (bond->first_slave != NULL) | 4241 | list_for_each_entry_safe(slave, tmp_slave, &bond->slave_list, list) |
| 4335 | __bond_release_one(bond_dev, bond->first_slave->dev, true); | 4242 | __bond_release_one(bond_dev, slave->dev, true); |
| 4336 | pr_info("%s: released all slaves\n", bond_dev->name); | 4243 | pr_info("%s: released all slaves\n", bond_dev->name); |
| 4337 | 4244 | ||
| 4338 | list_del(&bond->bond_list); | 4245 | list_del(&bond->bond_list); |
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c index 4060d41f0ee7..20a6ee25bb63 100644 --- a/drivers/net/bonding/bond_procfs.c +++ b/drivers/net/bonding/bond_procfs.c | |||
| @@ -12,7 +12,6 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) | |||
| 12 | struct bonding *bond = seq->private; | 12 | struct bonding *bond = seq->private; |
| 13 | loff_t off = 0; | 13 | loff_t off = 0; |
| 14 | struct slave *slave; | 14 | struct slave *slave; |
| 15 | int i; | ||
| 16 | 15 | ||
| 17 | /* make sure the bond won't be taken away */ | 16 | /* make sure the bond won't be taken away */ |
| 18 | rcu_read_lock(); | 17 | rcu_read_lock(); |
| @@ -21,10 +20,9 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) | |||
| 21 | if (*pos == 0) | 20 | if (*pos == 0) |
| 22 | return SEQ_START_TOKEN; | 21 | return SEQ_START_TOKEN; |
| 23 | 22 | ||
| 24 | bond_for_each_slave(bond, slave, i) { | 23 | bond_for_each_slave(bond, slave) |
| 25 | if (++off == *pos) | 24 | if (++off == *pos) |
| 26 | return slave; | 25 | return slave; |
| 27 | } | ||
| 28 | 26 | ||
| 29 | return NULL; | 27 | return NULL; |
| 30 | } | 28 | } |
| @@ -36,11 +34,13 @@ static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
| 36 | 34 | ||
| 37 | ++*pos; | 35 | ++*pos; |
| 38 | if (v == SEQ_START_TOKEN) | 36 | if (v == SEQ_START_TOKEN) |
| 39 | return bond->first_slave; | 37 | return bond_first_slave(bond); |
| 40 | 38 | ||
| 41 | slave = slave->next; | 39 | if (bond_is_last_slave(bond, slave)) |
| 40 | return NULL; | ||
| 41 | slave = bond_next_slave(bond, slave); | ||
| 42 | 42 | ||
| 43 | return (slave == bond->first_slave) ? NULL : slave; | 43 | return slave; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | static void bond_info_seq_stop(struct seq_file *seq, void *v) | 46 | 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 ae02c194c01b..0f539de640dc 100644 --- a/drivers/net/bonding/bond_sysfs.c +++ b/drivers/net/bonding/bond_sysfs.c | |||
| @@ -209,12 +209,12 @@ void bond_destroy_slave_symlinks(struct net_device *master, | |||
| 209 | static ssize_t bonding_show_slaves(struct device *d, | 209 | static ssize_t bonding_show_slaves(struct device *d, |
| 210 | struct device_attribute *attr, char *buf) | 210 | struct device_attribute *attr, char *buf) |
| 211 | { | 211 | { |
| 212 | struct slave *slave; | ||
| 213 | int i, res = 0; | ||
| 214 | struct bonding *bond = to_bond(d); | 212 | struct bonding *bond = to_bond(d); |
| 213 | struct slave *slave; | ||
| 214 | int res = 0; | ||
| 215 | 215 | ||
| 216 | read_lock(&bond->lock); | 216 | read_lock(&bond->lock); |
| 217 | bond_for_each_slave(bond, slave, i) { | 217 | bond_for_each_slave(bond, slave) { |
| 218 | if (res > (PAGE_SIZE - IFNAMSIZ)) { | 218 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 219 | /* not enough space for another interface name */ | 219 | /* not enough space for another interface name */ |
| 220 | if ((PAGE_SIZE - res) > 10) | 220 | if ((PAGE_SIZE - res) > 10) |
| @@ -227,6 +227,7 @@ static ssize_t bonding_show_slaves(struct device *d, | |||
| 227 | read_unlock(&bond->lock); | 227 | read_unlock(&bond->lock); |
| 228 | if (res) | 228 | if (res) |
| 229 | buf[res-1] = '\n'; /* eat the leftover space */ | 229 | buf[res-1] = '\n'; /* eat the leftover space */ |
| 230 | |||
| 230 | return res; | 231 | return res; |
| 231 | } | 232 | } |
| 232 | 233 | ||
| @@ -325,7 +326,7 @@ static ssize_t bonding_store_mode(struct device *d, | |||
| 325 | goto out; | 326 | goto out; |
| 326 | } | 327 | } |
| 327 | 328 | ||
| 328 | if (bond->slave_cnt > 0) { | 329 | if (!list_empty(&bond->slave_list)) { |
| 329 | pr_err("unable to update mode of %s because it has slaves.\n", | 330 | pr_err("unable to update mode of %s because it has slaves.\n", |
| 330 | bond->dev->name); | 331 | bond->dev->name); |
| 331 | ret = -EPERM; | 332 | ret = -EPERM; |
| @@ -507,7 +508,7 @@ static ssize_t bonding_store_fail_over_mac(struct device *d, | |||
| 507 | if (!rtnl_trylock()) | 508 | if (!rtnl_trylock()) |
| 508 | return restart_syscall(); | 509 | return restart_syscall(); |
| 509 | 510 | ||
| 510 | if (bond->slave_cnt != 0) { | 511 | if (!list_empty(&bond->slave_list)) { |
| 511 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", | 512 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", |
| 512 | bond->dev->name); | 513 | bond->dev->name); |
| 513 | ret = -EPERM; | 514 | ret = -EPERM; |
| @@ -668,7 +669,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, | |||
| 668 | &newtarget); | 669 | &newtarget); |
| 669 | /* not to race with bond_arp_rcv */ | 670 | /* not to race with bond_arp_rcv */ |
| 670 | write_lock_bh(&bond->lock); | 671 | write_lock_bh(&bond->lock); |
| 671 | bond_for_each_slave(bond, slave, i) | 672 | bond_for_each_slave(bond, slave) |
| 672 | slave->target_last_arp_rx[ind] = jiffies; | 673 | slave->target_last_arp_rx[ind] = jiffies; |
| 673 | targets[ind] = newtarget; | 674 | targets[ind] = newtarget; |
| 674 | write_unlock_bh(&bond->lock); | 675 | write_unlock_bh(&bond->lock); |
| @@ -694,7 +695,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, | |||
| 694 | &newtarget); | 695 | &newtarget); |
| 695 | 696 | ||
| 696 | write_lock_bh(&bond->lock); | 697 | write_lock_bh(&bond->lock); |
| 697 | bond_for_each_slave(bond, slave, i) { | 698 | bond_for_each_slave(bond, slave) { |
| 698 | targets_rx = slave->target_last_arp_rx; | 699 | targets_rx = slave->target_last_arp_rx; |
| 699 | j = ind; | 700 | j = ind; |
| 700 | for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++) | 701 | for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++) |
| @@ -1085,10 +1086,9 @@ static ssize_t bonding_store_primary(struct device *d, | |||
| 1085 | struct device_attribute *attr, | 1086 | struct device_attribute *attr, |
| 1086 | const char *buf, size_t count) | 1087 | const char *buf, size_t count) |
| 1087 | { | 1088 | { |
| 1088 | int i; | ||
| 1089 | struct slave *slave; | ||
| 1090 | struct bonding *bond = to_bond(d); | 1089 | struct bonding *bond = to_bond(d); |
| 1091 | char ifname[IFNAMSIZ]; | 1090 | char ifname[IFNAMSIZ]; |
| 1091 | struct slave *slave; | ||
| 1092 | 1092 | ||
| 1093 | if (!rtnl_trylock()) | 1093 | if (!rtnl_trylock()) |
| 1094 | return restart_syscall(); | 1094 | return restart_syscall(); |
| @@ -1114,7 +1114,7 @@ static ssize_t bonding_store_primary(struct device *d, | |||
| 1114 | goto out; | 1114 | goto out; |
| 1115 | } | 1115 | } |
| 1116 | 1116 | ||
| 1117 | bond_for_each_slave(bond, slave, i) { | 1117 | bond_for_each_slave(bond, slave) { |
| 1118 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | 1118 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 1119 | pr_info("%s: Setting %s as primary slave.\n", | 1119 | pr_info("%s: Setting %s as primary slave.\n", |
| 1120 | bond->dev->name, slave->dev->name); | 1120 | bond->dev->name, slave->dev->name); |
| @@ -1243,16 +1243,16 @@ static ssize_t bonding_show_active_slave(struct device *d, | |||
| 1243 | struct device_attribute *attr, | 1243 | struct device_attribute *attr, |
| 1244 | char *buf) | 1244 | char *buf) |
| 1245 | { | 1245 | { |
| 1246 | struct slave *curr; | ||
| 1247 | struct bonding *bond = to_bond(d); | 1246 | struct bonding *bond = to_bond(d); |
| 1247 | struct slave *curr; | ||
| 1248 | int count = 0; | 1248 | int count = 0; |
| 1249 | 1249 | ||
| 1250 | read_lock(&bond->curr_slave_lock); | 1250 | rcu_read_lock(); |
| 1251 | curr = bond->curr_active_slave; | 1251 | curr = rcu_dereference(bond->curr_active_slave); |
| 1252 | read_unlock(&bond->curr_slave_lock); | ||
| 1253 | |||
| 1254 | if (USES_PRIMARY(bond->params.mode) && curr) | 1252 | if (USES_PRIMARY(bond->params.mode) && curr) |
| 1255 | count = sprintf(buf, "%s\n", curr->dev->name); | 1253 | count = sprintf(buf, "%s\n", curr->dev->name); |
| 1254 | rcu_read_unlock(); | ||
| 1255 | |||
| 1256 | return count; | 1256 | return count; |
| 1257 | } | 1257 | } |
| 1258 | 1258 | ||
| @@ -1260,16 +1260,14 @@ static ssize_t bonding_store_active_slave(struct device *d, | |||
| 1260 | struct device_attribute *attr, | 1260 | struct device_attribute *attr, |
| 1261 | const char *buf, size_t count) | 1261 | const char *buf, size_t count) |
| 1262 | { | 1262 | { |
| 1263 | int i; | 1263 | struct slave *slave, *old_active, *new_active; |
| 1264 | struct slave *slave; | ||
| 1265 | struct slave *old_active = NULL; | ||
| 1266 | struct slave *new_active = NULL; | ||
| 1267 | struct bonding *bond = to_bond(d); | 1264 | struct bonding *bond = to_bond(d); |
| 1268 | char ifname[IFNAMSIZ]; | 1265 | char ifname[IFNAMSIZ]; |
| 1269 | 1266 | ||
| 1270 | if (!rtnl_trylock()) | 1267 | if (!rtnl_trylock()) |
| 1271 | return restart_syscall(); | 1268 | return restart_syscall(); |
| 1272 | 1269 | ||
| 1270 | old_active = new_active = NULL; | ||
| 1273 | block_netpoll_tx(); | 1271 | block_netpoll_tx(); |
| 1274 | read_lock(&bond->lock); | 1272 | read_lock(&bond->lock); |
| 1275 | write_lock_bh(&bond->curr_slave_lock); | 1273 | write_lock_bh(&bond->curr_slave_lock); |
| @@ -1286,12 +1284,12 @@ static ssize_t bonding_store_active_slave(struct device *d, | |||
| 1286 | if (!strlen(ifname) || buf[0] == '\n') { | 1284 | if (!strlen(ifname) || buf[0] == '\n') { |
| 1287 | pr_info("%s: Clearing current active slave.\n", | 1285 | pr_info("%s: Clearing current active slave.\n", |
| 1288 | bond->dev->name); | 1286 | bond->dev->name); |
| 1289 | bond->curr_active_slave = NULL; | 1287 | rcu_assign_pointer(bond->curr_active_slave, NULL); |
| 1290 | bond_select_active_slave(bond); | 1288 | bond_select_active_slave(bond); |
| 1291 | goto out; | 1289 | goto out; |
| 1292 | } | 1290 | } |
| 1293 | 1291 | ||
| 1294 | bond_for_each_slave(bond, slave, i) { | 1292 | bond_for_each_slave(bond, slave) { |
| 1295 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | 1293 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 1296 | old_active = bond->curr_active_slave; | 1294 | old_active = bond->curr_active_slave; |
| 1297 | new_active = slave; | 1295 | new_active = slave; |
| @@ -1349,14 +1347,9 @@ static ssize_t bonding_show_mii_status(struct device *d, | |||
| 1349 | struct device_attribute *attr, | 1347 | struct device_attribute *attr, |
| 1350 | char *buf) | 1348 | char *buf) |
| 1351 | { | 1349 | { |
| 1352 | struct slave *curr; | ||
| 1353 | struct bonding *bond = to_bond(d); | 1350 | struct bonding *bond = to_bond(d); |
| 1354 | 1351 | ||
| 1355 | read_lock(&bond->curr_slave_lock); | 1352 | return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down"); |
| 1356 | curr = bond->curr_active_slave; | ||
| 1357 | read_unlock(&bond->curr_slave_lock); | ||
| 1358 | |||
| 1359 | return sprintf(buf, "%s\n", curr ? "up" : "down"); | ||
| 1360 | } | 1353 | } |
| 1361 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); | 1354 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
| 1362 | 1355 | ||
| @@ -1475,15 +1468,15 @@ static ssize_t bonding_show_queue_id(struct device *d, | |||
| 1475 | struct device_attribute *attr, | 1468 | struct device_attribute *attr, |
| 1476 | char *buf) | 1469 | char *buf) |
| 1477 | { | 1470 | { |
| 1478 | struct slave *slave; | ||
| 1479 | int i, res = 0; | ||
| 1480 | struct bonding *bond = to_bond(d); | 1471 | struct bonding *bond = to_bond(d); |
| 1472 | struct slave *slave; | ||
| 1473 | int res = 0; | ||
| 1481 | 1474 | ||
| 1482 | if (!rtnl_trylock()) | 1475 | if (!rtnl_trylock()) |
| 1483 | return restart_syscall(); | 1476 | return restart_syscall(); |
| 1484 | 1477 | ||
| 1485 | read_lock(&bond->lock); | 1478 | read_lock(&bond->lock); |
| 1486 | bond_for_each_slave(bond, slave, i) { | 1479 | bond_for_each_slave(bond, slave) { |
| 1487 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { | 1480 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
| 1488 | /* not enough space for another interface_name:queue_id pair */ | 1481 | /* not enough space for another interface_name:queue_id pair */ |
| 1489 | if ((PAGE_SIZE - res) > 10) | 1482 | if ((PAGE_SIZE - res) > 10) |
| @@ -1498,6 +1491,7 @@ static ssize_t bonding_show_queue_id(struct device *d, | |||
| 1498 | if (res) | 1491 | if (res) |
| 1499 | buf[res-1] = '\n'; /* eat the leftover space */ | 1492 | buf[res-1] = '\n'; /* eat the leftover space */ |
| 1500 | rtnl_unlock(); | 1493 | rtnl_unlock(); |
| 1494 | |||
| 1501 | return res; | 1495 | return res; |
| 1502 | } | 1496 | } |
| 1503 | 1497 | ||
| @@ -1512,7 +1506,7 @@ static ssize_t bonding_store_queue_id(struct device *d, | |||
| 1512 | struct slave *slave, *update_slave; | 1506 | struct slave *slave, *update_slave; |
| 1513 | struct bonding *bond = to_bond(d); | 1507 | struct bonding *bond = to_bond(d); |
| 1514 | u16 qid; | 1508 | u16 qid; |
| 1515 | int i, ret = count; | 1509 | int ret = count; |
| 1516 | char *delim; | 1510 | char *delim; |
| 1517 | struct net_device *sdev = NULL; | 1511 | struct net_device *sdev = NULL; |
| 1518 | 1512 | ||
| @@ -1547,7 +1541,7 @@ static ssize_t bonding_store_queue_id(struct device *d, | |||
| 1547 | 1541 | ||
| 1548 | /* Search for thes slave and check for duplicate qids */ | 1542 | /* Search for thes slave and check for duplicate qids */ |
| 1549 | update_slave = NULL; | 1543 | update_slave = NULL; |
| 1550 | bond_for_each_slave(bond, slave, i) { | 1544 | bond_for_each_slave(bond, slave) { |
| 1551 | if (sdev == slave->dev) | 1545 | if (sdev == slave->dev) |
| 1552 | /* | 1546 | /* |
| 1553 | * We don't need to check the matching | 1547 | * We don't need to check the matching |
| @@ -1599,8 +1593,8 @@ static ssize_t bonding_store_slaves_active(struct device *d, | |||
| 1599 | struct device_attribute *attr, | 1593 | struct device_attribute *attr, |
| 1600 | const char *buf, size_t count) | 1594 | const char *buf, size_t count) |
| 1601 | { | 1595 | { |
| 1602 | int i, new_value, ret = count; | ||
| 1603 | struct bonding *bond = to_bond(d); | 1596 | struct bonding *bond = to_bond(d); |
| 1597 | int new_value, ret = count; | ||
| 1604 | struct slave *slave; | 1598 | struct slave *slave; |
| 1605 | 1599 | ||
| 1606 | if (sscanf(buf, "%d", &new_value) != 1) { | 1600 | if (sscanf(buf, "%d", &new_value) != 1) { |
| @@ -1623,7 +1617,7 @@ static ssize_t bonding_store_slaves_active(struct device *d, | |||
| 1623 | } | 1617 | } |
| 1624 | 1618 | ||
| 1625 | read_lock(&bond->lock); | 1619 | read_lock(&bond->lock); |
| 1626 | bond_for_each_slave(bond, slave, i) { | 1620 | bond_for_each_slave(bond, slave) { |
| 1627 | if (!bond_is_active_slave(slave)) { | 1621 | if (!bond_is_active_slave(slave)) { |
| 1628 | if (new_value) | 1622 | if (new_value) |
| 1629 | slave->inactive = 0; | 1623 | slave->inactive = 0; |
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h index 42d1c6599cba..4bf52d5f637e 100644 --- a/drivers/net/bonding/bonding.h +++ b/drivers/net/bonding/bonding.h | |||
| @@ -71,6 +71,28 @@ | |||
| 71 | set_fs(fs); \ | 71 | set_fs(fs); \ |
| 72 | res; }) | 72 | res; }) |
| 73 | 73 | ||
| 74 | /* slave list primitives */ | ||
| 75 | #define bond_to_slave(ptr) list_entry(ptr, struct slave, list) | ||
| 76 | |||
| 77 | /* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */ | ||
| 78 | #define bond_first_slave(bond) \ | ||
| 79 | list_first_entry_or_null(&(bond)->slave_list, struct slave, list) | ||
| 80 | #define bond_last_slave(bond) \ | ||
| 81 | (list_empty(&(bond)->slave_list) ? NULL : \ | ||
| 82 | bond_to_slave((bond)->slave_list.prev)) | ||
| 83 | |||
| 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 | |||
| 92 | #define bond_prev_slave(bond, pos) \ | ||
| 93 | (bond_is_first_slave(bond, pos) ? bond_last_slave(bond) : \ | ||
| 94 | bond_to_slave((pos)->list.prev)) | ||
| 95 | |||
| 74 | /** | 96 | /** |
| 75 | * bond_for_each_slave_from - iterate the slaves list from a starting point | 97 | * bond_for_each_slave_from - iterate the slaves list from a starting point |
| 76 | * @bond: the bond holding this list. | 98 | * @bond: the bond holding this list. |
| @@ -80,37 +102,33 @@ | |||
| 80 | * | 102 | * |
| 81 | * Caller must hold bond->lock | 103 | * Caller must hold bond->lock |
| 82 | */ | 104 | */ |
| 83 | #define bond_for_each_slave_from(bond, pos, cnt, start) \ | 105 | #define bond_for_each_slave_from(bond, pos, cnt, start) \ |
| 84 | for (cnt = 0, pos = start; \ | 106 | for (cnt = 0, pos = start; pos && cnt < (bond)->slave_cnt; \ |
| 85 | cnt < (bond)->slave_cnt; \ | 107 | cnt++, pos = bond_next_slave(bond, pos)) |
| 86 | cnt++, pos = (pos)->next) | ||
| 87 | 108 | ||
| 88 | /** | 109 | /** |
| 89 | * bond_for_each_slave_from_to - iterate the slaves list from start point to stop point | 110 | * bond_for_each_slave - iterate over all slaves |
| 90 | * @bond: the bond holding this list. | 111 | * @bond: the bond holding this list |
| 91 | * @pos: current slave. | 112 | * @pos: current slave |
| 92 | * @cnt: counter for number max of moves | ||
| 93 | * @start: start point. | ||
| 94 | * @stop: stop point. | ||
| 95 | * | 113 | * |
| 96 | * Caller must hold bond->lock | 114 | * Caller must hold bond->lock |
| 97 | */ | 115 | */ |
| 98 | #define bond_for_each_slave_from_to(bond, pos, cnt, start, stop) \ | 116 | #define bond_for_each_slave(bond, pos) \ |
| 99 | for (cnt = 0, pos = start; \ | 117 | list_for_each_entry(pos, &(bond)->slave_list, list) |
| 100 | ((cnt < (bond)->slave_cnt) && (pos != (stop)->next)); \ | 118 | |
| 101 | cnt++, pos = (pos)->next) | 119 | /* Caller must have rcu_read_lock */ |
| 120 | #define bond_for_each_slave_rcu(bond, pos) \ | ||
| 121 | list_for_each_entry_rcu(pos, &(bond)->slave_list, list) | ||
| 102 | 122 | ||
| 103 | /** | 123 | /** |
| 104 | * bond_for_each_slave - iterate the slaves list from head | 124 | * bond_for_each_slave_reverse - iterate in reverse from a given position |
| 105 | * @bond: the bond holding this list. | 125 | * @bond: the bond holding this list |
| 106 | * @pos: current slave. | 126 | * @pos: slave to continue from |
| 107 | * @cnt: counter for max number of moves | ||
| 108 | * | 127 | * |
| 109 | * Caller must hold bond->lock | 128 | * Caller must hold bond->lock |
| 110 | */ | 129 | */ |
| 111 | #define bond_for_each_slave(bond, pos, cnt) \ | 130 | #define bond_for_each_slave_continue_reverse(bond, pos) \ |
| 112 | bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave) | 131 | list_for_each_entry_continue_reverse(pos, &(bond)->slave_list, list) |
| 113 | |||
| 114 | 132 | ||
| 115 | #ifdef CONFIG_NET_POLL_CONTROLLER | 133 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 116 | extern atomic_t netpoll_block_tx; | 134 | extern atomic_t netpoll_block_tx; |
| @@ -174,8 +192,7 @@ struct vlan_entry { | |||
| 174 | 192 | ||
| 175 | struct slave { | 193 | struct slave { |
| 176 | struct net_device *dev; /* first - useful for panic debug */ | 194 | struct net_device *dev; /* first - useful for panic debug */ |
| 177 | struct slave *next; | 195 | struct list_head list; |
| 178 | struct slave *prev; | ||
| 179 | struct bonding *bond; /* our master */ | 196 | struct bonding *bond; /* our master */ |
| 180 | int delay; | 197 | int delay; |
| 181 | unsigned long jiffies; | 198 | unsigned long jiffies; |
| @@ -215,7 +232,7 @@ struct slave { | |||
| 215 | */ | 232 | */ |
| 216 | struct bonding { | 233 | struct bonding { |
| 217 | struct net_device *dev; /* first - useful for panic debug */ | 234 | struct net_device *dev; /* first - useful for panic debug */ |
| 218 | struct slave *first_slave; | 235 | struct list_head slave_list; |
| 219 | struct slave *curr_active_slave; | 236 | struct slave *curr_active_slave; |
| 220 | struct slave *current_arp_slave; | 237 | struct slave *current_arp_slave; |
| 221 | struct slave *primary_slave; | 238 | struct slave *primary_slave; |
| @@ -270,13 +287,10 @@ static inline struct slave *bond_get_slave_by_dev(struct bonding *bond, | |||
| 270 | struct net_device *slave_dev) | 287 | struct net_device *slave_dev) |
| 271 | { | 288 | { |
| 272 | struct slave *slave = NULL; | 289 | struct slave *slave = NULL; |
| 273 | int i; | ||
| 274 | 290 | ||
| 275 | bond_for_each_slave(bond, slave, i) { | 291 | bond_for_each_slave(bond, slave) |
| 276 | if (slave->dev == slave_dev) { | 292 | if (slave->dev == slave_dev) |
| 277 | return slave; | 293 | return slave; |
| 278 | } | ||
| 279 | } | ||
| 280 | 294 | ||
| 281 | return NULL; | 295 | return NULL; |
| 282 | } | 296 | } |
| @@ -416,10 +430,20 @@ static inline __be32 bond_confirm_addr(struct net_device *dev, __be32 dst, __be3 | |||
| 416 | return addr; | 430 | return addr; |
| 417 | } | 431 | } |
| 418 | 432 | ||
| 433 | static inline bool slave_can_tx(struct slave *slave) | ||
| 434 | { | ||
| 435 | if (IS_UP(slave->dev) && slave->link == BOND_LINK_UP && | ||
| 436 | bond_is_active_slave(slave)) | ||
| 437 | return true; | ||
| 438 | else | ||
| 439 | return false; | ||
| 440 | } | ||
| 441 | |||
| 419 | struct bond_net; | 442 | struct bond_net; |
| 420 | 443 | ||
| 421 | struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr); | 444 | struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr); |
| 422 | int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev); | 445 | int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev); |
| 446 | void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id); | ||
| 423 | int bond_create(struct net *net, const char *name); | 447 | int bond_create(struct net *net, const char *name); |
| 424 | int bond_create_sysfs(struct bond_net *net); | 448 | int bond_create_sysfs(struct bond_net *net); |
| 425 | void bond_destroy_sysfs(struct bond_net *net); | 449 | void bond_destroy_sysfs(struct bond_net *net); |
| @@ -477,10 +501,9 @@ static inline void bond_destroy_proc_dir(struct bond_net *bn) | |||
| 477 | static inline struct slave *bond_slave_has_mac(struct bonding *bond, | 501 | static inline struct slave *bond_slave_has_mac(struct bonding *bond, |
| 478 | const u8 *mac) | 502 | const u8 *mac) |
| 479 | { | 503 | { |
| 480 | int i = 0; | ||
| 481 | struct slave *tmp; | 504 | struct slave *tmp; |
| 482 | 505 | ||
| 483 | bond_for_each_slave(bond, tmp, i) | 506 | bond_for_each_slave(bond, tmp) |
| 484 | if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr)) | 507 | if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr)) |
| 485 | return tmp; | 508 | return tmp; |
| 486 | 509 | ||
