Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ec0865a9 authored by Veaceslav Falico's avatar Veaceslav Falico Committed by David S. Miller
Browse files

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: default avatarVeaceslav Falico <vfalico@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 267bed77
Loading
Loading
Loading
Loading
+19 −19
Original line number Original line Diff line number Diff line
@@ -497,7 +497,7 @@ static int bond_set_promiscuity(struct bonding *bond, int inc)
	struct list_head *iter;
	struct list_head *iter;
	int err = 0;
	int err = 0;


	if (USES_PRIMARY(bond->params.mode)) {
	if (bond_uses_primary(bond)) {
		/* write lock already acquired */
		/* write lock already acquired */
		if (bond->curr_active_slave) {
		if (bond->curr_active_slave) {
			err = dev_set_promiscuity(bond->curr_active_slave->dev,
			err = dev_set_promiscuity(bond->curr_active_slave->dev,
@@ -523,7 +523,7 @@ static int bond_set_allmulti(struct bonding *bond, int inc)
	struct list_head *iter;
	struct list_head *iter;
	int err = 0;
	int err = 0;


	if (USES_PRIMARY(bond->params.mode)) {
	if (bond_uses_primary(bond)) {
		/* write lock already acquired */
		/* write lock already acquired */
		if (bond->curr_active_slave) {
		if (bond->curr_active_slave) {
			err = dev_set_allmulti(bond->curr_active_slave->dev,
			err = dev_set_allmulti(bond->curr_active_slave->dev,
@@ -585,8 +585,8 @@ static void bond_hw_addr_flush(struct net_device *bond_dev,
/*--------------------------- Active slave change ---------------------------*/
/*--------------------------- Active slave change ---------------------------*/


/* Update the hardware address list and promisc/allmulti for the new and
/* Update the hardware address list and promisc/allmulti for the new and
 * old active slaves (if any).  Modes that are !USES_PRIMARY keep all
 * old active slaves (if any).  Modes that are not using primary keep all
 * slaves up date at all times; only the USES_PRIMARY modes need to call
 * slaves up date at all times; only the modes that use primary need to call
 * this function to swap these settings during a failover.
 * this function to swap these settings during a failover.
 */
 */
static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
static 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)
		new_active->last_link_up = jiffies;
		new_active->last_link_up = jiffies;


		if (new_active->link == BOND_LINK_BACK) {
		if (new_active->link == BOND_LINK_BACK) {
			if (USES_PRIMARY(bond->params.mode)) {
			if (bond_uses_primary(bond)) {
				pr_info("%s: making interface %s the new active one %d ms earlier\n",
				pr_info("%s: making interface %s the new active one %d ms earlier\n",
					bond->dev->name, new_active->dev->name,
					bond->dev->name, new_active->dev->name,
					(bond->params.updelay - new_active->delay) * bond->params.miimon);
					(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)
			if (bond_is_lb(bond))
			if (bond_is_lb(bond))
				bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
				bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
		} else {
		} else {
			if (USES_PRIMARY(bond->params.mode)) {
			if (bond_uses_primary(bond)) {
				pr_info("%s: making interface %s the new active one\n",
				pr_info("%s: making interface %s the new active one\n",
					bond->dev->name, new_active->dev->name);
					bond->dev->name, new_active->dev->name);
			}
			}
		}
		}
	}
	}


	if (USES_PRIMARY(bond->params.mode))
	if (bond_uses_primary(bond))
		bond_hw_addr_swap(bond, new_active, old_active);
		bond_hw_addr_swap(bond, new_active, old_active);


	if (bond_is_lb(bond)) {
	if (bond_is_lb(bond)) {
@@ -876,7 +876,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
	 * resend only if bond is brought up with the affected
	 * resend only if bond is brought up with the affected
	 * bonding modes and the retransmission is enabled */
	 * bonding modes and the retransmission is enabled */
	if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) &&
	if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) &&
	    ((USES_PRIMARY(bond->params.mode) && new_active) ||
	    ((bond_uses_primary(bond) && new_active) ||
	     bond->params.mode == BOND_MODE_ROUNDROBIN)) {
	     bond->params.mode == BOND_MODE_ROUNDROBIN)) {
		bond->igmp_retrans = bond->params.resend_igmp;
		bond->igmp_retrans = bond->params.resend_igmp;
		queue_delayed_work(bond->wq, &bond->mcast_work, 1);
		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)
			goto err_close;
			goto err_close;
	}
	}


	/* If the mode USES_PRIMARY, then the following is handled by
	/* If the mode uses primary, then the following is handled by
	 * bond_change_active_slave().
	 * bond_change_active_slave().
	 */
	 */
	if (!USES_PRIMARY(bond->params.mode)) {
	if (!bond_uses_primary(bond)) {
		/* set promiscuity level to new slave */
		/* set promiscuity level to new slave */
		if (bond_dev->flags & IFF_PROMISC) {
		if (bond_dev->flags & IFF_PROMISC) {
			res = dev_set_promiscuity(slave_dev, 1);
			res = dev_set_promiscuity(slave_dev, 1);
@@ -1480,7 +1480,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
		 new_slave->link == BOND_LINK_DOWN ? "DOWN" :
		 new_slave->link == BOND_LINK_DOWN ? "DOWN" :
		 (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));
		 (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));


	if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) {
	if (bond_uses_primary(bond) && bond->params.primary[0]) {
		/* if there is a primary slave, remember it */
		/* if there is a primary slave, remember it */
		if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
		if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
			bond->primary_slave = new_slave;
			bond->primary_slave = new_slave;
@@ -1569,7 +1569,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
	bond_compute_features(bond);
	bond_compute_features(bond);
	bond_set_carrier(bond);
	bond_set_carrier(bond);


	if (USES_PRIMARY(bond->params.mode)) {
	if (bond_uses_primary(bond)) {
		block_netpoll_tx();
		block_netpoll_tx();
		write_lock_bh(&bond->curr_slave_lock);
		write_lock_bh(&bond->curr_slave_lock);
		bond_select_active_slave(bond);
		bond_select_active_slave(bond);
@@ -1593,7 +1593,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
	netdev_rx_handler_unregister(slave_dev);
	netdev_rx_handler_unregister(slave_dev);


err_detach:
err_detach:
	if (!USES_PRIMARY(bond->params.mode))
	if (!bond_uses_primary(bond))
		bond_hw_addr_flush(bond_dev, slave_dev);
		bond_hw_addr_flush(bond_dev, slave_dev);


	vlan_vids_del_by_dev(slave_dev, bond_dev);
	vlan_vids_del_by_dev(slave_dev, bond_dev);
@@ -1778,10 +1778,10 @@ static int __bond_release_one(struct net_device *bond_dev,
	/* must do this from outside any spinlocks */
	/* must do this from outside any spinlocks */
	vlan_vids_del_by_dev(slave_dev, bond_dev);
	vlan_vids_del_by_dev(slave_dev, bond_dev);


	/* If the mode USES_PRIMARY, then this cases was handled above by
	/* If the mode uses primary, then this cases was handled above by
	 * bond_change_active_slave(..., NULL)
	 * bond_change_active_slave(..., NULL)
	 */
	 */
	if (!USES_PRIMARY(bond->params.mode)) {
	if (!bond_uses_primary(bond)) {
		/* unset promiscuity level from slave
		/* unset promiscuity level from slave
		 * NOTE: The NETDEV_CHANGEADDR call above may change the value
		 * NOTE: The NETDEV_CHANGEADDR call above may change the value
		 * of the IFF_PROMISC flag in the bond_dev, but we need the
		 * 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,
		break;
		break;
	case NETDEV_CHANGENAME:
	case NETDEV_CHANGENAME:
		/* we don't care if we don't have primary set */
		/* we don't care if we don't have primary set */
		if (!USES_PRIMARY(bond->params.mode) ||
		if (!bond_uses_primary(bond) ||
		    !bond->params.primary[0])
		    !bond->params.primary[0])
			break;
			break;


@@ -3105,7 +3105,7 @@ static int bond_open(struct net_device *bond_dev)
	if (bond_has_slaves(bond)) {
	if (bond_has_slaves(bond)) {
		read_lock(&bond->curr_slave_lock);
		read_lock(&bond->curr_slave_lock);
		bond_for_each_slave(bond, slave, iter) {
		bond_for_each_slave(bond, slave, iter) {
			if (USES_PRIMARY(bond->params.mode)
			if (bond_uses_primary(bond)
				&& (slave != bond->curr_active_slave)) {
				&& (slave != bond->curr_active_slave)) {
				bond_set_slave_inactive_flags(slave,
				bond_set_slave_inactive_flags(slave,
							      BOND_SLAVE_NOTIFY_NOW);
							      BOND_SLAVE_NOTIFY_NOW);
@@ -3343,7 +3343,7 @@ static void bond_set_rx_mode(struct net_device *bond_dev)




	rcu_read_lock();
	rcu_read_lock();
	if (USES_PRIMARY(bond->params.mode)) {
	if (bond_uses_primary(bond)) {
		slave = rcu_dereference(bond->curr_active_slave);
		slave = rcu_dereference(bond->curr_active_slave);
		if (slave) {
		if (slave) {
			dev_uc_sync(slave->dev, bond_dev);
			dev_uc_sync(slave->dev, bond_dev);
@@ -4268,7 +4268,7 @@ static int bond_check_params(struct bond_params *params)
		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");
		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");
	}
	}


	if (primary && !USES_PRIMARY(bond_mode)) {
	if (primary && !bond_mode_uses_primary(bond_mode)) {
		/* currently, using a primary only makes sense
		/* currently, using a primary only makes sense
		 * in active backup, TLB or ALB modes
		 * in active backup, TLB or ALB modes
		 */
		 */
+1 −1
Original line number Original line Diff line number Diff line
@@ -693,7 +693,7 @@ int bond_option_mode_set(struct bonding *bond, const struct bond_opt_value *newv
static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
							 struct slave *slave)
							 struct slave *slave)
{
{
	return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
	return bond_uses_primary(bond) && slave ? slave->dev : NULL;
}
}


struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
+1 −1
Original line number Original line Diff line number Diff line
@@ -91,7 +91,7 @@ static void bond_info_show_master(struct seq_file *seq)
			   optval->string, bond->params.xmit_policy);
			   optval->string, bond->params.xmit_policy);
	}
	}


	if (USES_PRIMARY(bond->params.mode)) {
	if (bond_uses_primary(bond)) {
		seq_printf(seq, "Primary Slave: %s",
		seq_printf(seq, "Primary Slave: %s",
			   (bond->primary_slave) ?
			   (bond->primary_slave) ?
			   bond->primary_slave->dev->name : "None");
			   bond->primary_slave->dev->name : "None");
+11 −6
Original line number Original line Diff line number Diff line
@@ -54,12 +54,6 @@
		     ((slave)->link == BOND_LINK_UP) && \
		     ((slave)->link == BOND_LINK_UP) && \
		     bond_is_active_slave(slave))
		     bond_is_active_slave(slave))



#define USES_PRIMARY(mode)				\
		(((mode) == BOND_MODE_ACTIVEBACKUP) ||	\
		 ((mode) == BOND_MODE_TLB)          ||	\
		 ((mode) == BOND_MODE_ALB))

#define IS_IP_TARGET_UNUSABLE_ADDRESS(a)	\
#define IS_IP_TARGET_UNUSABLE_ADDRESS(a)	\
	((htonl(INADDR_BROADCAST) == a) ||	\
	((htonl(INADDR_BROADCAST) == a) ||	\
	 ipv4_is_zeronet(a))
	 ipv4_is_zeronet(a))
@@ -293,6 +287,17 @@ static inline bool bond_mode_uses_arp(int mode)
	       mode != BOND_MODE_ALB;
	       mode != BOND_MODE_ALB;
}
}


static inline bool bond_mode_uses_primary(int mode)
{
	return mode == BOND_MODE_ACTIVEBACKUP || mode == BOND_MODE_TLB ||
	       mode == BOND_MODE_ALB;
}

static inline bool bond_uses_primary(struct bonding *bond)
{
	return bond_mode_uses_primary(bond->params.mode);
}

static inline void bond_set_active_slave(struct slave *slave)
static inline void bond_set_active_slave(struct slave *slave)
{
{
	if (slave->backup) {
	if (slave->backup) {