aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeaceslav Falico <vfalico@redhat.com>2013-09-25 03:20:21 -0400
committerDavid S. Miller <davem@davemloft.net>2013-09-26 16:02:06 -0400
commit0965a1f3f8757a2c20a16a83bc18279009d79a26 (patch)
treedd7b1c154e8b5e01f31422ebdf3c27df8b583780
parentb386c58b85b23c3a73baa014d01d2943ca8260cd (diff)
bonding: add bond_has_slaves() and use it
Currently we verify if we have slaves by checking if bond->slave_list is empty. Create a define bond_has_slaves() and use it, a bit more readable and easier to change in the future. CC: Jay Vosburgh <fubar@us.ibm.com> CC: Andy Gospodarek <andy@greyhouse.net> Signed-off-by: Veaceslav Falico <vfalico@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/bond_3ad.c2
-rw-r--r--drivers/net/bonding/bond_alb.c8
-rw-r--r--drivers/net/bonding/bond_main.c32
-rw-r--r--drivers/net/bonding/bond_sysfs.c4
-rw-r--r--drivers/net/bonding/bonding.h2
5 files changed, 25 insertions, 23 deletions
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index c861ee7e65ff..1337eafe4311 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -2117,7 +2117,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
2117 read_lock(&bond->lock); 2117 read_lock(&bond->lock);
2118 2118
2119 //check if there are any slaves 2119 //check if there are any slaves
2120 if (list_empty(&bond->slave_list)) 2120 if (!bond_has_slaves(bond))
2121 goto re_arm; 2121 goto re_arm;
2122 2122
2123 // check if agg_select_timer timer after initialize is timed out 2123 // check if agg_select_timer timer after initialize is timed out
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index c5b85ad5554d..e96041816b5b 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -1178,7 +1178,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
1178 struct slave *tmp_slave1, *free_mac_slave = NULL; 1178 struct slave *tmp_slave1, *free_mac_slave = NULL;
1179 struct list_head *iter; 1179 struct list_head *iter;
1180 1180
1181 if (list_empty(&bond->slave_list)) { 1181 if (!bond_has_slaves(bond)) {
1182 /* this is the first slave */ 1182 /* this is the first slave */
1183 return 0; 1183 return 0;
1184 } 1184 }
@@ -1469,7 +1469,7 @@ void bond_alb_monitor(struct work_struct *work)
1469 1469
1470 read_lock(&bond->lock); 1470 read_lock(&bond->lock);
1471 1471
1472 if (list_empty(&bond->slave_list)) { 1472 if (!bond_has_slaves(bond)) {
1473 bond_info->tx_rebalance_counter = 0; 1473 bond_info->tx_rebalance_counter = 0;
1474 bond_info->lp_counter = 0; 1474 bond_info->lp_counter = 0;
1475 goto re_arm; 1475 goto re_arm;
@@ -1606,7 +1606,7 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
1606 */ 1606 */
1607void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave) 1607void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave)
1608{ 1608{
1609 if (!list_empty(&bond->slave_list)) 1609 if (bond_has_slaves(bond))
1610 alb_change_hw_addr_on_detach(bond, slave); 1610 alb_change_hw_addr_on_detach(bond, slave);
1611 1611
1612 tlb_clear_slave(bond, slave, 0); 1612 tlb_clear_slave(bond, slave, 0);
@@ -1676,7 +1676,7 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
1676 swap_slave = bond->curr_active_slave; 1676 swap_slave = bond->curr_active_slave;
1677 rcu_assign_pointer(bond->curr_active_slave, new_slave); 1677 rcu_assign_pointer(bond->curr_active_slave, new_slave);
1678 1678
1679 if (!new_slave || list_empty(&bond->slave_list)) 1679 if (!new_slave || !bond_has_slaves(bond))
1680 return; 1680 return;
1681 1681
1682 /* set the new curr_active_slave to the bonds mac address 1682 /* set the new curr_active_slave to the bonds mac address
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 3c96b1b10ba4..06ffc8ace54c 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -391,7 +391,7 @@ static int bond_set_carrier(struct bonding *bond)
391 struct list_head *iter; 391 struct list_head *iter;
392 struct slave *slave; 392 struct slave *slave;
393 393
394 if (list_empty(&bond->slave_list)) 394 if (!bond_has_slaves(bond))
395 goto down; 395 goto down;
396 396
397 if (bond->params.mode == BOND_MODE_8023AD) 397 if (bond->params.mode == BOND_MODE_8023AD)
@@ -1085,7 +1085,7 @@ static netdev_features_t bond_fix_features(struct net_device *dev,
1085 netdev_features_t mask; 1085 netdev_features_t mask;
1086 struct slave *slave; 1086 struct slave *slave;
1087 1087
1088 if (list_empty(&bond->slave_list)) { 1088 if (!bond_has_slaves(bond)) {
1089 /* Disable adding VLANs to empty bond. But why? --mq */ 1089 /* Disable adding VLANs to empty bond. But why? --mq */
1090 features |= NETIF_F_VLAN_CHALLENGED; 1090 features |= NETIF_F_VLAN_CHALLENGED;
1091 return features; 1091 return features;
@@ -1120,7 +1120,7 @@ static void bond_compute_features(struct bonding *bond)
1120 unsigned int gso_max_size = GSO_MAX_SIZE; 1120 unsigned int gso_max_size = GSO_MAX_SIZE;
1121 u16 gso_max_segs = GSO_MAX_SEGS; 1121 u16 gso_max_segs = GSO_MAX_SEGS;
1122 1122
1123 if (list_empty(&bond->slave_list)) 1123 if (!bond_has_slaves(bond))
1124 goto done; 1124 goto done;
1125 1125
1126 bond_for_each_slave(bond, slave, iter) { 1126 bond_for_each_slave(bond, slave, iter) {
@@ -1310,7 +1310,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1310 * bond ether type mutual exclusion - don't allow slaves of dissimilar 1310 * bond ether type mutual exclusion - don't allow slaves of dissimilar
1311 * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond 1311 * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond
1312 */ 1312 */
1313 if (list_empty(&bond->slave_list)) { 1313 if (!bond_has_slaves(bond)) {
1314 if (bond_dev->type != slave_dev->type) { 1314 if (bond_dev->type != slave_dev->type) {
1315 pr_debug("%s: change device type from %d to %d\n", 1315 pr_debug("%s: change device type from %d to %d\n",
1316 bond_dev->name, 1316 bond_dev->name,
@@ -1349,7 +1349,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1349 } 1349 }
1350 1350
1351 if (slave_ops->ndo_set_mac_address == NULL) { 1351 if (slave_ops->ndo_set_mac_address == NULL) {
1352 if (list_empty(&bond->slave_list)) { 1352 if (!bond_has_slaves(bond)) {
1353 pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.", 1353 pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.",
1354 bond_dev->name); 1354 bond_dev->name);
1355 bond->params.fail_over_mac = BOND_FOM_ACTIVE; 1355 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
@@ -1365,7 +1365,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1365 1365
1366 /* If this is the first slave, then we need to set the master's hardware 1366 /* If this is the first slave, then we need to set the master's hardware
1367 * address to be the same as the slave's. */ 1367 * address to be the same as the slave's. */
1368 if (list_empty(&bond->slave_list) && 1368 if (!bond_has_slaves(bond) &&
1369 bond->dev->addr_assign_type == NET_ADDR_RANDOM) 1369 bond->dev->addr_assign_type == NET_ADDR_RANDOM)
1370 bond_set_dev_addr(bond->dev, slave_dev); 1370 bond_set_dev_addr(bond->dev, slave_dev);
1371 1371
@@ -1696,7 +1696,7 @@ err_free:
1696err_undo_flags: 1696err_undo_flags:
1697 bond_compute_features(bond); 1697 bond_compute_features(bond);
1698 /* Enslave of first slave has failed and we need to fix master's mac */ 1698 /* Enslave of first slave has failed and we need to fix master's mac */
1699 if (list_empty(&bond->slave_list) && 1699 if (!bond_has_slaves(bond) &&
1700 ether_addr_equal(bond_dev->dev_addr, slave_dev->dev_addr)) 1700 ether_addr_equal(bond_dev->dev_addr, slave_dev->dev_addr))
1701 eth_hw_addr_random(bond_dev); 1701 eth_hw_addr_random(bond_dev);
1702 1702
@@ -1776,7 +1776,7 @@ static int __bond_release_one(struct net_device *bond_dev,
1776 1776
1777 if (!all && !bond->params.fail_over_mac) { 1777 if (!all && !bond->params.fail_over_mac) {
1778 if (ether_addr_equal(bond_dev->dev_addr, slave->perm_hwaddr) && 1778 if (ether_addr_equal(bond_dev->dev_addr, slave->perm_hwaddr) &&
1779 !list_empty(&bond->slave_list)) 1779 bond_has_slaves(bond))
1780 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", 1780 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",
1781 bond_dev->name, slave_dev->name, 1781 bond_dev->name, slave_dev->name,
1782 slave->perm_hwaddr, 1782 slave->perm_hwaddr,
@@ -1819,7 +1819,7 @@ static int __bond_release_one(struct net_device *bond_dev,
1819 write_lock_bh(&bond->lock); 1819 write_lock_bh(&bond->lock);
1820 } 1820 }
1821 1821
1822 if (list_empty(&bond->slave_list)) { 1822 if (!bond_has_slaves(bond)) {
1823 bond_set_carrier(bond); 1823 bond_set_carrier(bond);
1824 eth_hw_addr_random(bond_dev); 1824 eth_hw_addr_random(bond_dev);
1825 1825
@@ -1835,7 +1835,7 @@ static int __bond_release_one(struct net_device *bond_dev,
1835 unblock_netpoll_tx(); 1835 unblock_netpoll_tx();
1836 synchronize_rcu(); 1836 synchronize_rcu();
1837 1837
1838 if (list_empty(&bond->slave_list)) { 1838 if (!bond_has_slaves(bond)) {
1839 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev); 1839 call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
1840 call_netdevice_notifiers(NETDEV_RELEASE, bond->dev); 1840 call_netdevice_notifiers(NETDEV_RELEASE, bond->dev);
1841 } 1841 }
@@ -1904,7 +1904,7 @@ static int bond_release_and_destroy(struct net_device *bond_dev,
1904 int ret; 1904 int ret;
1905 1905
1906 ret = bond_release(bond_dev, slave_dev); 1906 ret = bond_release(bond_dev, slave_dev);
1907 if (ret == 0 && list_empty(&bond->slave_list)) { 1907 if (ret == 0 && !bond_has_slaves(bond)) {
1908 bond_dev->priv_flags |= IFF_DISABLE_NETPOLL; 1908 bond_dev->priv_flags |= IFF_DISABLE_NETPOLL;
1909 pr_info("%s: destroying bond %s.\n", 1909 pr_info("%s: destroying bond %s.\n",
1910 bond_dev->name, bond_dev->name); 1910 bond_dev->name, bond_dev->name);
@@ -2219,7 +2219,7 @@ void bond_mii_monitor(struct work_struct *work)
2219 2219
2220 delay = msecs_to_jiffies(bond->params.miimon); 2220 delay = msecs_to_jiffies(bond->params.miimon);
2221 2221
2222 if (list_empty(&bond->slave_list)) 2222 if (!bond_has_slaves(bond))
2223 goto re_arm; 2223 goto re_arm;
2224 2224
2225 should_notify_peers = bond_should_notify_peers(bond); 2225 should_notify_peers = bond_should_notify_peers(bond);
@@ -2513,7 +2513,7 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
2513 2513
2514 read_lock(&bond->lock); 2514 read_lock(&bond->lock);
2515 2515
2516 if (list_empty(&bond->slave_list)) 2516 if (!bond_has_slaves(bond))
2517 goto re_arm; 2517 goto re_arm;
2518 2518
2519 oldcurrent = bond->curr_active_slave; 2519 oldcurrent = bond->curr_active_slave;
@@ -2845,7 +2845,7 @@ void bond_activebackup_arp_mon(struct work_struct *work)
2845 2845
2846 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); 2846 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
2847 2847
2848 if (list_empty(&bond->slave_list)) 2848 if (!bond_has_slaves(bond))
2849 goto re_arm; 2849 goto re_arm;
2850 2850
2851 should_notify_peers = bond_should_notify_peers(bond); 2851 should_notify_peers = bond_should_notify_peers(bond);
@@ -3169,7 +3169,7 @@ static int bond_open(struct net_device *bond_dev)
3169 3169
3170 /* reset slave->backup and slave->inactive */ 3170 /* reset slave->backup and slave->inactive */
3171 read_lock(&bond->lock); 3171 read_lock(&bond->lock);
3172 if (!list_empty(&bond->slave_list)) { 3172 if (bond_has_slaves(bond)) {
3173 read_lock(&bond->curr_slave_lock); 3173 read_lock(&bond->curr_slave_lock);
3174 bond_for_each_slave(bond, slave, iter) { 3174 bond_for_each_slave(bond, slave, iter) {
3175 if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP) 3175 if ((bond->params.mode == BOND_MODE_ACTIVEBACKUP)
@@ -3892,7 +3892,7 @@ static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
3892 return NETDEV_TX_BUSY; 3892 return NETDEV_TX_BUSY;
3893 3893
3894 rcu_read_lock(); 3894 rcu_read_lock();
3895 if (!list_empty(&bond->slave_list)) 3895 if (bond_has_slaves(bond))
3896 ret = __bond_start_xmit(skb, dev); 3896 ret = __bond_start_xmit(skb, dev);
3897 else 3897 else
3898 kfree_skb(skb); 3898 kfree_skb(skb);
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index e747415b5cb0..04d95d6f6c63 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -327,7 +327,7 @@ static ssize_t bonding_store_mode(struct device *d,
327 goto out; 327 goto out;
328 } 328 }
329 329
330 if (!list_empty(&bond->slave_list)) { 330 if (bond_has_slaves(bond)) {
331 pr_err("unable to update mode of %s because it has slaves.\n", 331 pr_err("unable to update mode of %s because it has slaves.\n",
332 bond->dev->name); 332 bond->dev->name);
333 ret = -EPERM; 333 ret = -EPERM;
@@ -523,7 +523,7 @@ static ssize_t bonding_store_fail_over_mac(struct device *d,
523 if (!rtnl_trylock()) 523 if (!rtnl_trylock())
524 return restart_syscall(); 524 return restart_syscall();
525 525
526 if (!list_empty(&bond->slave_list)) { 526 if (bond_has_slaves(bond)) {
527 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", 527 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
528 bond->dev->name); 528 bond->dev->name);
529 ret = -EPERM; 529 ret = -EPERM;
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 7c8a4b128f65..bcef15ec3459 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -72,6 +72,8 @@
72 res; }) 72 res; })
73 73
74/* slave list primitives */ 74/* slave list primitives */
75#define bond_has_slaves(bond) !list_empty(&(bond)->slave_list)
76
75#define bond_to_slave(ptr) list_entry(ptr, struct slave, list) 77#define bond_to_slave(ptr) list_entry(ptr, struct slave, list)
76 78
77/* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */ 79/* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */