Skip to content

Commit

Permalink
bonding: consolidate the two rlb_next_rx_slave functions into one
Browse files Browse the repository at this point in the history
__rlb_next_rx_slave() is a copy of rlb_next_rx_slave() with the
difference that it uses rcu primitives to walk the slave list. We don't
need the two functions and can make rlb_next_rx_slave() a wrapper for
callers which hold RTNL.
So add a comment and ASSERT_RTNL() to make sure what is intended.

Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Nikolay Aleksandrov authored and David S. Miller committed Sep 15, 2014
1 parent 4370240 commit 56924c3
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions drivers/net/bonding/bond_alb.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,15 @@ static int rlb_arp_recv(const struct sk_buff *skb, struct bonding *bond,
return RX_HANDLER_ANOTHER;
}

static struct slave *rlb_next_rx_slave(struct bonding *bond)
/* Caller must hold rcu_read_lock() */
static struct slave *__rlb_next_rx_slave(struct bonding *bond)
{
struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
struct slave *before = NULL, *rx_slave = NULL, *slave;
struct list_head *iter;
bool found = false;

bond_for_each_slave(bond, slave, iter) {
bond_for_each_slave_rcu(bond, slave, iter) {
if (!bond_slave_can_tx(slave))
continue;
if (!found) {
Expand All @@ -366,35 +367,16 @@ static struct slave *rlb_next_rx_slave(struct bonding *bond)
return rx_slave;
}

/* Caller must hold rcu_read_lock() */
static struct slave *__rlb_next_rx_slave(struct bonding *bond)
/* Caller must hold RTNL, rcu_read_lock is obtained only to silence checkers */
static struct slave *rlb_next_rx_slave(struct bonding *bond)
{
struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
struct slave *before = NULL, *rx_slave = NULL, *slave;
struct list_head *iter;
bool found = false;
struct slave *rx_slave;

bond_for_each_slave_rcu(bond, slave, iter) {
if (!bond_slave_can_tx(slave))
continue;
if (!found) {
if (!before || before->speed < slave->speed)
before = slave;
} else {
if (!rx_slave || rx_slave->speed < slave->speed)
rx_slave = slave;
}
if (slave == bond_info->rx_slave)
found = true;
}
/* we didn't find anything after the current or we have something
* better before and up to the current slave
*/
if (!rx_slave || (before && rx_slave->speed < before->speed))
rx_slave = before;
ASSERT_RTNL();

if (rx_slave)
bond_info->rx_slave = rx_slave;
rcu_read_lock();
rx_slave = __rlb_next_rx_slave(bond);
rcu_read_unlock();

return rx_slave;
}
Expand Down

0 comments on commit 56924c3

Please sign in to comment.