Skip to content

Commit b2e7ace

Browse files
dingtianhongdavem330
authored andcommitted
bonding: remove the no effect lock for bond_select_active_slave()
The bond slave list was no longer protected by bond lock and only protected by RTNL or RCU, so anywhere that use bond lock to protect slave list is meaningless. remove the release and acquire bond lock for bond_select_active_slave(). The curr_active_slave could only be changed in 3 place: 1. enslave slave. 2. release slave. 3. change_active_slave. all above place were holding bond lock, RTNL and curr_slave_lock together, it is tedious and meaningless, obviously bond lock is no need here, but RTNL or curr_slave_lock is needed, so if you want to access active slave, you have to choose one lock, RTNL or curr_slave_lock, if RTNL is exist, no need to add curr_slave_lock, otherwise curr_slave_lock is better, because of the performance. there are several place calling bond_select_active_slave() and bond_change_active_slave(), the next step I will clean these place and remove the no effect lock. there are some document changed together when update the function. Suggested-by: Jay Vosburgh <[email protected]> Suggested-by: Veaceslav Falico <[email protected]> Signed-off-by: Ding Tianhong <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e57a784 commit b2e7ace

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

drivers/net/bonding/bond_alb.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static void rlb_teach_disabled_mac_on_primary(struct bonding *bond, u8 addr[])
469469

470470
/* slave being removed should not be active at this point
471471
*
472-
* Caller must hold bond lock for read
472+
* Caller must hold rtnl.
473473
*/
474474
static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
475475
{
@@ -1679,14 +1679,11 @@ void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char
16791679
* If new_slave is NULL, caller must hold curr_slave_lock or
16801680
* bond->lock for write.
16811681
*
1682-
* If new_slave is not NULL, caller must hold RTNL, bond->lock for
1683-
* read and curr_slave_lock for write. Processing here may sleep, so
1684-
* no other locks may be held.
1682+
* If new_slave is not NULL, caller must hold RTNL, curr_slave_lock
1683+
* for write. Processing here may sleep, so no other locks may be held.
16851684
*/
16861685
void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave)
16871686
__releases(&bond->curr_slave_lock)
1688-
__releases(&bond->lock)
1689-
__acquires(&bond->lock)
16901687
__acquires(&bond->curr_slave_lock)
16911688
{
16921689
struct slave *swap_slave;
@@ -1722,7 +1719,6 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
17221719
tlb_clear_slave(bond, new_slave, 1);
17231720

17241721
write_unlock_bh(&bond->curr_slave_lock);
1725-
read_unlock(&bond->lock);
17261722

17271723
ASSERT_RTNL();
17281724

@@ -1748,11 +1744,9 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
17481744
/* swap mac address */
17491745
alb_swap_mac_addr(swap_slave, new_slave);
17501746
alb_fasten_mac_swap(bond, swap_slave, new_slave);
1751-
read_lock(&bond->lock);
17521747
} else {
17531748
/* set the new_slave to the bond mac address */
17541749
alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr);
1755-
read_lock(&bond->lock);
17561750
alb_send_learning_packets(new_slave, bond->dev->dev_addr);
17571751
}
17581752

drivers/net/bonding/bond_main.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,12 @@ static void bond_set_dev_addr(struct net_device *bond_dev,
697697
*
698698
* Perform special MAC address swapping for fail_over_mac settings
699699
*
700-
* Called with RTNL, bond->lock for read, curr_slave_lock for write_bh.
700+
* Called with RTNL, curr_slave_lock for write_bh.
701701
*/
702702
static void bond_do_fail_over_mac(struct bonding *bond,
703703
struct slave *new_active,
704704
struct slave *old_active)
705705
__releases(&bond->curr_slave_lock)
706-
__releases(&bond->lock)
707-
__acquires(&bond->lock)
708706
__acquires(&bond->curr_slave_lock)
709707
{
710708
u8 tmp_mac[ETH_ALEN];
@@ -715,9 +713,7 @@ static void bond_do_fail_over_mac(struct bonding *bond,
715713
case BOND_FOM_ACTIVE:
716714
if (new_active) {
717715
write_unlock_bh(&bond->curr_slave_lock);
718-
read_unlock(&bond->lock);
719716
bond_set_dev_addr(bond->dev, new_active->dev);
720-
read_lock(&bond->lock);
721717
write_lock_bh(&bond->curr_slave_lock);
722718
}
723719
break;
@@ -731,7 +727,6 @@ static void bond_do_fail_over_mac(struct bonding *bond,
731727
return;
732728

733729
write_unlock_bh(&bond->curr_slave_lock);
734-
read_unlock(&bond->lock);
735730

736731
if (old_active) {
737732
memcpy(tmp_mac, new_active->dev->dev_addr, ETH_ALEN);
@@ -761,7 +756,6 @@ static void bond_do_fail_over_mac(struct bonding *bond,
761756
pr_err("%s: Error %d setting MAC of slave %s\n",
762757
bond->dev->name, -rv, new_active->dev->name);
763758
out:
764-
read_lock(&bond->lock);
765759
write_lock_bh(&bond->curr_slave_lock);
766760
break;
767761
default:
@@ -846,8 +840,7 @@ static bool bond_should_notify_peers(struct bonding *bond)
846840
* because it is apparently the best available slave we have, even though its
847841
* updelay hasn't timed out yet.
848842
*
849-
* If new_active is not NULL, caller must hold bond->lock for read and
850-
* curr_slave_lock for write_bh.
843+
* If new_active is not NULL, caller must hold curr_slave_lock for write_bh.
851844
*/
852845
void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
853846
{
@@ -916,14 +909,12 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
916909
}
917910

918911
write_unlock_bh(&bond->curr_slave_lock);
919-
read_unlock(&bond->lock);
920912

921913
call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, bond->dev);
922914
if (should_notify_peers)
923915
call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
924916
bond->dev);
925917

926-
read_lock(&bond->lock);
927918
write_lock_bh(&bond->curr_slave_lock);
928919
}
929920
}
@@ -949,7 +940,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
949940
* - The primary_slave has got its link back.
950941
* - A slave has got its link back and there's no old curr_active_slave.
951942
*
952-
* Caller must hold bond->lock for read and curr_slave_lock for write_bh.
943+
* Caller must hold curr_slave_lock for write_bh.
953944
*/
954945
void bond_select_active_slave(struct bonding *bond)
955946
{

0 commit comments

Comments
 (0)