diff options
author | dingtianhong <dingtianhong@huawei.com> | 2013-10-23 23:09:03 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-10-27 16:36:28 -0400 |
commit | 6b6c526147bb00b5788a2f48463481dd30c29b71 (patch) | |
tree | 7332c6151f274a5178699974ffde90122d8a183e /drivers/net/bonding | |
parent | a00f6fcc7d0c62a91768d9c4ccba4c7d64fbbce3 (diff) |
bonding: remove bond read lock for bond_mii_monitor()
The bond slave list may change when the monitor is running, the slave list is no longer
protected by bond->lock, only protected by rtnl lock(), so we have 3 ways to modify it:
1.add bond_master_upper_dev_link() and bond_upper_dev_unlink() in bond->lock, but it is unsafe
to call call_netdevice_notifiers() in write lock.
2.remove unused bond->lock for monitor function, only use the existing rtnl lock().
3.use rcu_read_lock() to protect it, of course, it will transform bond_for_each_slave to
bond_for_each_slave_rcu() and performance is better, but in slow path, it is ignored.
so I remove the bond->lock and move the rtnl lock to protect the whole monitor function.
Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/bonding')
-rw-r--r-- | drivers/net/bonding/bond_main.c | 44 |
1 files changed, 12 insertions, 32 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index a141f406cb98..0a7e32578540 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c | |||
@@ -2118,49 +2118,29 @@ void bond_mii_monitor(struct work_struct *work) | |||
2118 | struct bonding *bond = container_of(work, struct bonding, | 2118 | struct bonding *bond = container_of(work, struct bonding, |
2119 | mii_work.work); | 2119 | mii_work.work); |
2120 | bool should_notify_peers = false; | 2120 | bool should_notify_peers = false; |
2121 | unsigned long delay; | ||
2122 | 2121 | ||
2123 | read_lock(&bond->lock); | 2122 | if (!rtnl_trylock()) |
2124 | 2123 | goto re_arm; | |
2125 | delay = msecs_to_jiffies(bond->params.miimon); | ||
2126 | 2124 | ||
2127 | if (!bond_has_slaves(bond)) | 2125 | if (!bond_has_slaves(bond)) { |
2126 | rtnl_unlock(); | ||
2128 | goto re_arm; | 2127 | goto re_arm; |
2128 | } | ||
2129 | 2129 | ||
2130 | should_notify_peers = bond_should_notify_peers(bond); | 2130 | should_notify_peers = bond_should_notify_peers(bond); |
2131 | 2131 | ||
2132 | if (bond_miimon_inspect(bond)) { | 2132 | if (bond_miimon_inspect(bond)) |
2133 | read_unlock(&bond->lock); | ||
2134 | |||
2135 | /* Race avoidance with bond_close cancel of workqueue */ | ||
2136 | if (!rtnl_trylock()) { | ||
2137 | read_lock(&bond->lock); | ||
2138 | delay = 1; | ||
2139 | should_notify_peers = false; | ||
2140 | goto re_arm; | ||
2141 | } | ||
2142 | |||
2143 | read_lock(&bond->lock); | ||
2144 | |||
2145 | bond_miimon_commit(bond); | 2133 | bond_miimon_commit(bond); |
2146 | 2134 | ||
2147 | read_unlock(&bond->lock); | 2135 | if (should_notify_peers) |
2148 | rtnl_unlock(); /* might sleep, hold no other locks */ | 2136 | call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev); |
2149 | read_lock(&bond->lock); | 2137 | |
2150 | } | 2138 | rtnl_unlock(); |
2151 | 2139 | ||
2152 | re_arm: | 2140 | re_arm: |
2153 | if (bond->params.miimon) | 2141 | if (bond->params.miimon) |
2154 | queue_delayed_work(bond->wq, &bond->mii_work, delay); | 2142 | queue_delayed_work(bond->wq, &bond->mii_work, |
2155 | 2143 | msecs_to_jiffies(bond->params.miimon)); | |
2156 | read_unlock(&bond->lock); | ||
2157 | |||
2158 | if (should_notify_peers) { | ||
2159 | if (!rtnl_trylock()) | ||
2160 | return; | ||
2161 | call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev); | ||
2162 | rtnl_unlock(); | ||
2163 | } | ||
2164 | } | 2144 | } |
2165 | 2145 | ||
2166 | static bool bond_has_this_ip(struct bonding *bond, __be32 ip) | 2146 | static bool bond_has_this_ip(struct bonding *bond, __be32 ip) |