aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Pirko <jpirko@redhat.com>2011-03-11 22:14:35 -0500
committerDavid S. Miller <davem@davemloft.net>2011-03-16 15:51:19 -0400
commitf1c1775ac7e61950225925c949045406ffcb43de (patch)
treedff2fc348c566df3c18f023043fd308bb75662f7
parentc888385a0d61c4c6923ecc3b9dacfe8a1d8cb222 (diff)
bonding: register slave pointer for rx_handler
Register slave pointer as rx_handler data. That would eventually prevent need to loop over slave devices to find the right slave. Use synchronize_net to ensure that bond_handle_frame does not get slave structure freed when working with that. Signed-off-by: Jiri Pirko <jpirko@redhat.com> Reviewed-by: Nicolas de Pesloüan <nicolas.2p.debian@free.fr> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/bond_main.c17
-rw-r--r--drivers/net/bonding/bonding.h3
2 files changed, 14 insertions, 6 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 66c98e61f0b7..b047d75c28d4 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1482,21 +1482,22 @@ static bool bond_should_deliver_exact_match(struct sk_buff *skb,
1482 1482
1483static struct sk_buff *bond_handle_frame(struct sk_buff *skb) 1483static struct sk_buff *bond_handle_frame(struct sk_buff *skb)
1484{ 1484{
1485 struct net_device *slave_dev; 1485 struct slave *slave;
1486 struct net_device *bond_dev; 1486 struct net_device *bond_dev;
1487 1487
1488 skb = skb_share_check(skb, GFP_ATOMIC); 1488 skb = skb_share_check(skb, GFP_ATOMIC);
1489 if (unlikely(!skb)) 1489 if (unlikely(!skb))
1490 return NULL; 1490 return NULL;
1491 slave_dev = skb->dev; 1491
1492 bond_dev = ACCESS_ONCE(slave_dev->master); 1492 slave = bond_slave_get_rcu(skb->dev);
1493 bond_dev = ACCESS_ONCE(slave->dev->master);
1493 if (unlikely(!bond_dev)) 1494 if (unlikely(!bond_dev))
1494 return skb; 1495 return skb;
1495 1496
1496 if (bond_dev->priv_flags & IFF_MASTER_ARPMON) 1497 if (bond_dev->priv_flags & IFF_MASTER_ARPMON)
1497 slave_dev->last_rx = jiffies; 1498 slave->dev->last_rx = jiffies;
1498 1499
1499 if (bond_should_deliver_exact_match(skb, slave_dev, bond_dev)) { 1500 if (bond_should_deliver_exact_match(skb, slave->dev, bond_dev)) {
1500 skb->deliver_no_wcard = 1; 1501 skb->deliver_no_wcard = 1;
1501 return skb; 1502 return skb;
1502 } 1503 }
@@ -1694,7 +1695,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1694 pr_debug("Error %d calling netdev_set_bond_master\n", res); 1695 pr_debug("Error %d calling netdev_set_bond_master\n", res);
1695 goto err_restore_mac; 1696 goto err_restore_mac;
1696 } 1697 }
1697 res = netdev_rx_handler_register(slave_dev, bond_handle_frame, NULL); 1698 res = netdev_rx_handler_register(slave_dev, bond_handle_frame,
1699 new_slave);
1698 if (res) { 1700 if (res) {
1699 pr_debug("Error %d calling netdev_rx_handler_register\n", res); 1701 pr_debug("Error %d calling netdev_rx_handler_register\n", res);
1700 goto err_unset_master; 1702 goto err_unset_master;
@@ -1916,6 +1918,7 @@ err_close:
1916 1918
1917err_unreg_rxhandler: 1919err_unreg_rxhandler:
1918 netdev_rx_handler_unregister(slave_dev); 1920 netdev_rx_handler_unregister(slave_dev);
1921 synchronize_net();
1919 1922
1920err_unset_master: 1923err_unset_master:
1921 netdev_set_bond_master(slave_dev, NULL); 1924 netdev_set_bond_master(slave_dev, NULL);
@@ -2099,6 +2102,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
2099 } 2102 }
2100 2103
2101 netdev_rx_handler_unregister(slave_dev); 2104 netdev_rx_handler_unregister(slave_dev);
2105 synchronize_net();
2102 netdev_set_bond_master(slave_dev, NULL); 2106 netdev_set_bond_master(slave_dev, NULL);
2103 2107
2104 slave_disable_netpoll(slave); 2108 slave_disable_netpoll(slave);
@@ -2213,6 +2217,7 @@ static int bond_release_all(struct net_device *bond_dev)
2213 } 2217 }
2214 2218
2215 netdev_rx_handler_unregister(slave_dev); 2219 netdev_rx_handler_unregister(slave_dev);
2220 synchronize_net();
2216 netdev_set_bond_master(slave_dev, NULL); 2221 netdev_set_bond_master(slave_dev, NULL);
2217 2222
2218 slave_disable_netpoll(slave); 2223 slave_disable_netpoll(slave);
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index c4e2343bb0b7..ff9af31e8c5b 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -266,6 +266,9 @@ struct bonding {
266#endif /* CONFIG_DEBUG_FS */ 266#endif /* CONFIG_DEBUG_FS */
267}; 267};
268 268
269#define bond_slave_get_rcu(dev) \
270 ((struct slave *) rcu_dereference(dev->rx_handler_data))
271
269/** 272/**
270 * Returns NULL if the net_device does not belong to any of the bond's slaves 273 * Returns NULL if the net_device does not belong to any of the bond's slaves
271 * 274 *