aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVeaceslav Falico <vfalico@gmail.com>2014-05-15 15:39:54 -0400
committerDavid S. Miller <davem@davemloft.net>2014-05-16 16:34:32 -0400
commitec0865a94991d1819d4f99866a2492af8df5c882 (patch)
tree8b2e1a5987776e063e8a7dc1431e65394a7eef76
parent267bed777a5f8a8f5acd50a9134c7341fc46d822 (diff)
bonding: make USES_PRIMARY inline functions
Change the name a bit to better reflect its scope, and update some comments. Two functions added - one which takes bond as a param and the other which takes the mode. CC: Jay Vosburgh <j.vosburgh@gmail.com> CC: Andy Gospodarek <andy@greyhouse.net> Signed-off-by: Veaceslav Falico <vfalico@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/bonding/bond_main.c38
-rw-r--r--drivers/net/bonding/bond_options.c2
-rw-r--r--drivers/net/bonding/bond_procfs.c2
-rw-r--r--drivers/net/bonding/bonding.h17
4 files changed, 32 insertions, 27 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 2448e28f38bc..48bea62fb4d0 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -497,7 +497,7 @@ static int bond_set_promiscuity(struct bonding *bond, int inc)
497 struct list_head *iter; 497 struct list_head *iter;
498 int err = 0; 498 int err = 0;
499 499
500 if (USES_PRIMARY(bond->params.mode)) { 500 if (bond_uses_primary(bond)) {
501 /* write lock already acquired */ 501 /* write lock already acquired */
502 if (bond->curr_active_slave) { 502 if (bond->curr_active_slave) {
503 err = dev_set_promiscuity(bond->curr_active_slave->dev, 503 err = dev_set_promiscuity(bond->curr_active_slave->dev,
@@ -523,7 +523,7 @@ static int bond_set_allmulti(struct bonding *bond, int inc)
523 struct list_head *iter; 523 struct list_head *iter;
524 int err = 0; 524 int err = 0;
525 525
526 if (USES_PRIMARY(bond->params.mode)) { 526 if (bond_uses_primary(bond)) {
527 /* write lock already acquired */ 527 /* write lock already acquired */
528 if (bond->curr_active_slave) { 528 if (bond->curr_active_slave) {
529 err = dev_set_allmulti(bond->curr_active_slave->dev, 529 err = dev_set_allmulti(bond->curr_active_slave->dev,
@@ -585,8 +585,8 @@ static void bond_hw_addr_flush(struct net_device *bond_dev,
585/*--------------------------- Active slave change ---------------------------*/ 585/*--------------------------- Active slave change ---------------------------*/
586 586
587/* Update the hardware address list and promisc/allmulti for the new and 587/* Update the hardware address list and promisc/allmulti for the new and
588 * old active slaves (if any). Modes that are !USES_PRIMARY keep all 588 * old active slaves (if any). Modes that are not using primary keep all
589 * slaves up date at all times; only the USES_PRIMARY modes need to call 589 * slaves up date at all times; only the modes that use primary need to call
590 * this function to swap these settings during a failover. 590 * this function to swap these settings during a failover.
591 */ 591 */
592static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active, 592static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
@@ -801,7 +801,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
801 new_active->last_link_up = jiffies; 801 new_active->last_link_up = jiffies;
802 802
803 if (new_active->link == BOND_LINK_BACK) { 803 if (new_active->link == BOND_LINK_BACK) {
804 if (USES_PRIMARY(bond->params.mode)) { 804 if (bond_uses_primary(bond)) {
805 pr_info("%s: making interface %s the new active one %d ms earlier\n", 805 pr_info("%s: making interface %s the new active one %d ms earlier\n",
806 bond->dev->name, new_active->dev->name, 806 bond->dev->name, new_active->dev->name,
807 (bond->params.updelay - new_active->delay) * bond->params.miimon); 807 (bond->params.updelay - new_active->delay) * bond->params.miimon);
@@ -816,14 +816,14 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
816 if (bond_is_lb(bond)) 816 if (bond_is_lb(bond))
817 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP); 817 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
818 } else { 818 } else {
819 if (USES_PRIMARY(bond->params.mode)) { 819 if (bond_uses_primary(bond)) {
820 pr_info("%s: making interface %s the new active one\n", 820 pr_info("%s: making interface %s the new active one\n",
821 bond->dev->name, new_active->dev->name); 821 bond->dev->name, new_active->dev->name);
822 } 822 }
823 } 823 }
824 } 824 }
825 825
826 if (USES_PRIMARY(bond->params.mode)) 826 if (bond_uses_primary(bond))
827 bond_hw_addr_swap(bond, new_active, old_active); 827 bond_hw_addr_swap(bond, new_active, old_active);
828 828
829 if (bond_is_lb(bond)) { 829 if (bond_is_lb(bond)) {
@@ -876,7 +876,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
876 * resend only if bond is brought up with the affected 876 * resend only if bond is brought up with the affected
877 * bonding modes and the retransmission is enabled */ 877 * bonding modes and the retransmission is enabled */
878 if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) && 878 if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) &&
879 ((USES_PRIMARY(bond->params.mode) && new_active) || 879 ((bond_uses_primary(bond) && new_active) ||
880 bond->params.mode == BOND_MODE_ROUNDROBIN)) { 880 bond->params.mode == BOND_MODE_ROUNDROBIN)) {
881 bond->igmp_retrans = bond->params.resend_igmp; 881 bond->igmp_retrans = bond->params.resend_igmp;
882 queue_delayed_work(bond->wq, &bond->mcast_work, 1); 882 queue_delayed_work(bond->wq, &bond->mcast_work, 1);
@@ -1381,10 +1381,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1381 goto err_close; 1381 goto err_close;
1382 } 1382 }
1383 1383
1384 /* If the mode USES_PRIMARY, then the following is handled by 1384 /* If the mode uses primary, then the following is handled by
1385 * bond_change_active_slave(). 1385 * bond_change_active_slave().
1386 */ 1386 */
1387 if (!USES_PRIMARY(bond->params.mode)) { 1387 if (!bond_uses_primary(bond)) {
1388 /* set promiscuity level to new slave */ 1388 /* set promiscuity level to new slave */
1389 if (bond_dev->flags & IFF_PROMISC) { 1389 if (bond_dev->flags & IFF_PROMISC) {
1390 res = dev_set_promiscuity(slave_dev, 1); 1390 res = dev_set_promiscuity(slave_dev, 1);
@@ -1480,7 +1480,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1480 new_slave->link == BOND_LINK_DOWN ? "DOWN" : 1480 new_slave->link == BOND_LINK_DOWN ? "DOWN" :
1481 (new_slave->link == BOND_LINK_UP ? "UP" : "BACK")); 1481 (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));
1482 1482
1483 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) { 1483 if (bond_uses_primary(bond) && bond->params.primary[0]) {
1484 /* if there is a primary slave, remember it */ 1484 /* if there is a primary slave, remember it */
1485 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) { 1485 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
1486 bond->primary_slave = new_slave; 1486 bond->primary_slave = new_slave;
@@ -1569,7 +1569,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1569 bond_compute_features(bond); 1569 bond_compute_features(bond);
1570 bond_set_carrier(bond); 1570 bond_set_carrier(bond);
1571 1571
1572 if (USES_PRIMARY(bond->params.mode)) { 1572 if (bond_uses_primary(bond)) {
1573 block_netpoll_tx(); 1573 block_netpoll_tx();
1574 write_lock_bh(&bond->curr_slave_lock); 1574 write_lock_bh(&bond->curr_slave_lock);
1575 bond_select_active_slave(bond); 1575 bond_select_active_slave(bond);
@@ -1593,7 +1593,7 @@ err_unregister:
1593 netdev_rx_handler_unregister(slave_dev); 1593 netdev_rx_handler_unregister(slave_dev);
1594 1594
1595err_detach: 1595err_detach:
1596 if (!USES_PRIMARY(bond->params.mode)) 1596 if (!bond_uses_primary(bond))
1597 bond_hw_addr_flush(bond_dev, slave_dev); 1597 bond_hw_addr_flush(bond_dev, slave_dev);
1598 1598
1599 vlan_vids_del_by_dev(slave_dev, bond_dev); 1599 vlan_vids_del_by_dev(slave_dev, bond_dev);
@@ -1778,10 +1778,10 @@ static int __bond_release_one(struct net_device *bond_dev,
1778 /* must do this from outside any spinlocks */ 1778 /* must do this from outside any spinlocks */
1779 vlan_vids_del_by_dev(slave_dev, bond_dev); 1779 vlan_vids_del_by_dev(slave_dev, bond_dev);
1780 1780
1781 /* If the mode USES_PRIMARY, then this cases was handled above by 1781 /* If the mode uses primary, then this cases was handled above by
1782 * bond_change_active_slave(..., NULL) 1782 * bond_change_active_slave(..., NULL)
1783 */ 1783 */
1784 if (!USES_PRIMARY(bond->params.mode)) { 1784 if (!bond_uses_primary(bond)) {
1785 /* unset promiscuity level from slave 1785 /* unset promiscuity level from slave
1786 * NOTE: The NETDEV_CHANGEADDR call above may change the value 1786 * NOTE: The NETDEV_CHANGEADDR call above may change the value
1787 * of the IFF_PROMISC flag in the bond_dev, but we need the 1787 * of the IFF_PROMISC flag in the bond_dev, but we need the
@@ -2915,7 +2915,7 @@ static int bond_slave_netdev_event(unsigned long event,
2915 break; 2915 break;
2916 case NETDEV_CHANGENAME: 2916 case NETDEV_CHANGENAME:
2917 /* we don't care if we don't have primary set */ 2917 /* we don't care if we don't have primary set */
2918 if (!USES_PRIMARY(bond->params.mode) || 2918 if (!bond_uses_primary(bond) ||
2919 !bond->params.primary[0]) 2919 !bond->params.primary[0])
2920 break; 2920 break;
2921 2921
@@ -3105,7 +3105,7 @@ static int bond_open(struct net_device *bond_dev)
3105 if (bond_has_slaves(bond)) { 3105 if (bond_has_slaves(bond)) {
3106 read_lock(&bond->curr_slave_lock); 3106 read_lock(&bond->curr_slave_lock);
3107 bond_for_each_slave(bond, slave, iter) { 3107 bond_for_each_slave(bond, slave, iter) {
3108 if (USES_PRIMARY(bond->params.mode) 3108 if (bond_uses_primary(bond)
3109 && (slave != bond->curr_active_slave)) { 3109 && (slave != bond->curr_active_slave)) {
3110 bond_set_slave_inactive_flags(slave, 3110 bond_set_slave_inactive_flags(slave,
3111 BOND_SLAVE_NOTIFY_NOW); 3111 BOND_SLAVE_NOTIFY_NOW);
@@ -3343,7 +3343,7 @@ static void bond_set_rx_mode(struct net_device *bond_dev)
3343 3343
3344 3344
3345 rcu_read_lock(); 3345 rcu_read_lock();
3346 if (USES_PRIMARY(bond->params.mode)) { 3346 if (bond_uses_primary(bond)) {
3347 slave = rcu_dereference(bond->curr_active_slave); 3347 slave = rcu_dereference(bond->curr_active_slave);
3348 if (slave) { 3348 if (slave) {
3349 dev_uc_sync(slave->dev, bond_dev); 3349 dev_uc_sync(slave->dev, bond_dev);
@@ -4268,7 +4268,7 @@ static int bond_check_params(struct bond_params *params)
4268 pr_debug("Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified, otherwise bonding will not detect link failures! see bonding.txt for details\n"); 4268 pr_debug("Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified, otherwise bonding will not detect link failures! see bonding.txt for details\n");
4269 } 4269 }
4270 4270
4271 if (primary && !USES_PRIMARY(bond_mode)) { 4271 if (primary && !bond_mode_uses_primary(bond_mode)) {
4272 /* currently, using a primary only makes sense 4272 /* currently, using a primary only makes sense
4273 * in active backup, TLB or ALB modes 4273 * in active backup, TLB or ALB modes
4274 */ 4274 */
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 98c8801ddb67..dd7292fa4665 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -693,7 +693,7 @@ int bond_option_mode_set(struct bonding *bond, const struct bond_opt_value *newv
693static struct net_device *__bond_option_active_slave_get(struct bonding *bond, 693static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
694 struct slave *slave) 694 struct slave *slave)
695{ 695{
696 return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL; 696 return bond_uses_primary(bond) && slave ? slave->dev : NULL;
697} 697}
698 698
699struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond) 699struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c
index 6a261c85fd5d..63a4a6f5ab14 100644
--- a/drivers/net/bonding/bond_procfs.c
+++ b/drivers/net/bonding/bond_procfs.c
@@ -91,7 +91,7 @@ static void bond_info_show_master(struct seq_file *seq)
91 optval->string, bond->params.xmit_policy); 91 optval->string, bond->params.xmit_policy);
92 } 92 }
93 93
94 if (USES_PRIMARY(bond->params.mode)) { 94 if (bond_uses_primary(bond)) {
95 seq_printf(seq, "Primary Slave: %s", 95 seq_printf(seq, "Primary Slave: %s",
96 (bond->primary_slave) ? 96 (bond->primary_slave) ?
97 bond->primary_slave->dev->name : "None"); 97 bond->primary_slave->dev->name : "None");
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 105c552f96d8..1a27c18be21c 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -54,12 +54,6 @@
54 ((slave)->link == BOND_LINK_UP) && \ 54 ((slave)->link == BOND_LINK_UP) && \
55 bond_is_active_slave(slave)) 55 bond_is_active_slave(slave))
56 56
57
58#define USES_PRIMARY(mode) \
59 (((mode) == BOND_MODE_ACTIVEBACKUP) || \
60 ((mode) == BOND_MODE_TLB) || \
61 ((mode) == BOND_MODE_ALB))
62
63#define IS_IP_TARGET_UNUSABLE_ADDRESS(a) \ 57#define IS_IP_TARGET_UNUSABLE_ADDRESS(a) \
64 ((htonl(INADDR_BROADCAST) == a) || \ 58 ((htonl(INADDR_BROADCAST) == a) || \
65 ipv4_is_zeronet(a)) 59 ipv4_is_zeronet(a))
@@ -293,6 +287,17 @@ static inline bool bond_mode_uses_arp(int mode)
293 mode != BOND_MODE_ALB; 287 mode != BOND_MODE_ALB;
294} 288}
295 289
290static inline bool bond_mode_uses_primary(int mode)
291{
292 return mode == BOND_MODE_ACTIVEBACKUP || mode == BOND_MODE_TLB ||
293 mode == BOND_MODE_ALB;
294}
295
296static inline bool bond_uses_primary(struct bonding *bond)
297{
298 return bond_mode_uses_primary(bond->params.mode);
299}
300
296static inline void bond_set_active_slave(struct slave *slave) 301static inline void bond_set_active_slave(struct slave *slave)
297{ 302{
298 if (slave->backup) { 303 if (slave->backup) {