@@ -223,13 +223,14 @@ static long long compute_gap(struct slave *slave)
223223static struct slave * tlb_get_least_loaded_slave (struct bonding * bond )
224224{
225225 struct slave * slave , * least_loaded ;
226+ struct list_head * iter ;
226227 long long max_gap ;
227228
228229 least_loaded = NULL ;
229230 max_gap = LLONG_MIN ;
230231
231232 /* Find the slave with the largest gap */
232- bond_for_each_slave (bond , slave ) {
233+ bond_for_each_slave (bond , slave , iter ) {
233234 if (SLAVE_IS_OK (slave )) {
234235 long long gap = compute_gap (slave );
235236
@@ -382,30 +383,31 @@ static int rlb_arp_recv(const struct sk_buff *skb, struct bonding *bond,
382383static struct slave * rlb_next_rx_slave (struct bonding * bond )
383384{
384385 struct alb_bond_info * bond_info = & (BOND_ALB_INFO (bond ));
385- struct slave * rx_slave , * slave , * start_at ;
386- int i = 0 ;
387-
388- if (bond_info -> next_rx_slave )
389- start_at = bond_info -> next_rx_slave ;
390- else
391- start_at = bond_first_slave (bond );
392-
393- rx_slave = NULL ;
386+ struct slave * before = NULL , * rx_slave = NULL , * slave ;
387+ struct list_head * iter ;
388+ bool found = false;
394389
395- bond_for_each_slave_from (bond , slave , i , start_at ) {
396- if (SLAVE_IS_OK (slave )) {
397- if (!rx_slave ) {
398- rx_slave = slave ;
399- } else if (slave -> speed > rx_slave -> speed ) {
390+ bond_for_each_slave (bond , slave , iter ) {
391+ if (!SLAVE_IS_OK (slave ))
392+ continue ;
393+ if (!found ) {
394+ if (!before || before -> speed < slave -> speed )
395+ before = slave ;
396+ } else {
397+ if (!rx_slave || rx_slave -> speed < slave -> speed )
400398 rx_slave = slave ;
401- }
402399 }
400+ if (slave == bond_info -> rx_slave )
401+ found = true;
403402 }
403+ /* we didn't find anything after the current or we have something
404+ * better before and up to the current slave
405+ */
406+ if (!rx_slave || (before && rx_slave -> speed < before -> speed ))
407+ rx_slave = before ;
404408
405- if (rx_slave ) {
406- slave = bond_next_slave (bond , rx_slave );
407- bond_info -> next_rx_slave = slave ;
408- }
409+ if (rx_slave )
410+ bond_info -> rx_slave = rx_slave ;
409411
410412 return rx_slave ;
411413}
@@ -1019,7 +1021,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
10191021
10201022 /* loop through vlans and send one packet for each */
10211023 rcu_read_lock ();
1022- netdev_for_each_upper_dev_rcu (bond -> dev , upper , iter ) {
1024+ netdev_for_each_all_upper_dev_rcu (bond -> dev , upper , iter ) {
10231025 if (upper -> priv_flags & IFF_802_1Q_VLAN )
10241026 alb_send_lp_vid (slave , mac_addr ,
10251027 vlan_dev_vlan_id (upper ));
@@ -1172,10 +1174,11 @@ static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *sla
11721174 */
11731175static int alb_handle_addr_collision_on_attach (struct bonding * bond , struct slave * slave )
11741176{
1175- struct slave * tmp_slave1 , * free_mac_slave = NULL ;
11761177 struct slave * has_bond_addr = bond -> curr_active_slave ;
1178+ struct slave * tmp_slave1 , * free_mac_slave = NULL ;
1179+ struct list_head * iter ;
11771180
1178- if (list_empty ( & bond -> slave_list )) {
1181+ if (! bond_has_slaves ( bond )) {
11791182 /* this is the first slave */
11801183 return 0 ;
11811184 }
@@ -1196,7 +1199,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
11961199 /* The slave's address is equal to the address of the bond.
11971200 * Search for a spare address in the bond for this slave.
11981201 */
1199- bond_for_each_slave (bond , tmp_slave1 ) {
1202+ bond_for_each_slave (bond , tmp_slave1 , iter ) {
12001203 if (!bond_slave_has_mac (bond , tmp_slave1 -> perm_hwaddr )) {
12011204 /* no slave has tmp_slave1's perm addr
12021205 * as its curr addr
@@ -1246,15 +1249,16 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
12461249 */
12471250static int alb_set_mac_address (struct bonding * bond , void * addr )
12481251{
1249- char tmp_addr [ ETH_ALEN ] ;
1250- struct slave * slave ;
1252+ struct slave * slave , * rollback_slave ;
1253+ struct list_head * iter ;
12511254 struct sockaddr sa ;
1255+ char tmp_addr [ETH_ALEN ];
12521256 int res ;
12531257
12541258 if (bond -> alb_info .rlb_enabled )
12551259 return 0 ;
12561260
1257- bond_for_each_slave (bond , slave ) {
1261+ bond_for_each_slave (bond , slave , iter ) {
12581262 /* save net_device's current hw address */
12591263 memcpy (tmp_addr , slave -> dev -> dev_addr , ETH_ALEN );
12601264
@@ -1274,10 +1278,12 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
12741278 sa .sa_family = bond -> dev -> type ;
12751279
12761280 /* unwind from head to the slave that failed */
1277- bond_for_each_slave_continue_reverse (bond , slave ) {
1278- memcpy (tmp_addr , slave -> dev -> dev_addr , ETH_ALEN );
1279- dev_set_mac_address (slave -> dev , & sa );
1280- memcpy (slave -> dev -> dev_addr , tmp_addr , ETH_ALEN );
1281+ bond_for_each_slave (bond , rollback_slave , iter ) {
1282+ if (rollback_slave == slave )
1283+ break ;
1284+ memcpy (tmp_addr , rollback_slave -> dev -> dev_addr , ETH_ALEN );
1285+ dev_set_mac_address (rollback_slave -> dev , & sa );
1286+ memcpy (rollback_slave -> dev -> dev_addr , tmp_addr , ETH_ALEN );
12811287 }
12821288
12831289 return res ;
@@ -1458,11 +1464,12 @@ void bond_alb_monitor(struct work_struct *work)
14581464 struct bonding * bond = container_of (work , struct bonding ,
14591465 alb_work .work );
14601466 struct alb_bond_info * bond_info = & (BOND_ALB_INFO (bond ));
1467+ struct list_head * iter ;
14611468 struct slave * slave ;
14621469
14631470 read_lock (& bond -> lock );
14641471
1465- if (list_empty ( & bond -> slave_list )) {
1472+ if (! bond_has_slaves ( bond )) {
14661473 bond_info -> tx_rebalance_counter = 0 ;
14671474 bond_info -> lp_counter = 0 ;
14681475 goto re_arm ;
@@ -1480,7 +1487,7 @@ void bond_alb_monitor(struct work_struct *work)
14801487 */
14811488 read_lock (& bond -> curr_slave_lock );
14821489
1483- bond_for_each_slave (bond , slave )
1490+ bond_for_each_slave (bond , slave , iter )
14841491 alb_send_learning_packets (slave , slave -> dev -> dev_addr );
14851492
14861493 read_unlock (& bond -> curr_slave_lock );
@@ -1493,7 +1500,7 @@ void bond_alb_monitor(struct work_struct *work)
14931500
14941501 read_lock (& bond -> curr_slave_lock );
14951502
1496- bond_for_each_slave (bond , slave ) {
1503+ bond_for_each_slave (bond , slave , iter ) {
14971504 tlb_clear_slave (bond , slave , 1 );
14981505 if (slave == bond -> curr_active_slave ) {
14991506 SLAVE_TLB_INFO (slave ).load =
@@ -1599,13 +1606,13 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
15991606 */
16001607void bond_alb_deinit_slave (struct bonding * bond , struct slave * slave )
16011608{
1602- if (! list_empty ( & bond -> slave_list ))
1609+ if (bond_has_slaves ( bond ))
16031610 alb_change_hw_addr_on_detach (bond , slave );
16041611
16051612 tlb_clear_slave (bond , slave , 0 );
16061613
16071614 if (bond -> alb_info .rlb_enabled ) {
1608- bond -> alb_info .next_rx_slave = NULL ;
1615+ bond -> alb_info .rx_slave = NULL ;
16091616 rlb_clear_slave (bond , slave );
16101617 }
16111618}
@@ -1669,7 +1676,7 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
16691676 swap_slave = bond -> curr_active_slave ;
16701677 rcu_assign_pointer (bond -> curr_active_slave , new_slave );
16711678
1672- if (!new_slave || list_empty ( & bond -> slave_list ))
1679+ if (!new_slave || ! bond_has_slaves ( bond ))
16731680 return ;
16741681
16751682 /* set the new curr_active_slave to the bonds mac address
0 commit comments