Commit 9caff1e7 authored by Veaceslav Falico's avatar Veaceslav Falico Committed by David S. Miller

bonding: make bond_for_each_slave() use lower neighbour's private

It needs a list_head *iter, so add it wherever needed. Use both non-rcu and
rcu variants.

CC: Jay Vosburgh <fubar@us.ibm.com>
CC: Andy Gospodarek <andy@greyhouse.net>
CC: Dimitris Michailidis <dm@chelsio.com>
Signed-off-by: default avatarVeaceslav Falico <vfalico@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 81f23b13
...@@ -2419,6 +2419,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) ...@@ -2419,6 +2419,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
{ {
struct slave *slave, *start_at; struct slave *slave, *start_at;
struct bonding *bond = netdev_priv(dev); struct bonding *bond = netdev_priv(dev);
struct list_head *iter;
int slave_agg_no; int slave_agg_no;
int slaves_in_agg; int slaves_in_agg;
int agg_id; int agg_id;
...@@ -2444,7 +2445,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev) ...@@ -2444,7 +2445,7 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg); slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg);
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator;
if (agg && (agg->aggregator_identifier == agg_id)) { if (agg && (agg->aggregator_identifier == agg_id)) {
...@@ -2515,11 +2516,12 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond, ...@@ -2515,11 +2516,12 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
void bond_3ad_update_lacp_rate(struct bonding *bond) void bond_3ad_update_lacp_rate(struct bonding *bond)
{ {
struct port *port = NULL; struct port *port = NULL;
struct list_head *iter;
struct slave *slave; struct slave *slave;
int lacp_fast; int lacp_fast;
lacp_fast = bond->params.lacp_fast; lacp_fast = bond->params.lacp_fast;
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
port = &(SLAVE_AD_INFO(slave).port); port = &(SLAVE_AD_INFO(slave).port);
__get_state_machine_lock(port); __get_state_machine_lock(port);
if (lacp_fast) if (lacp_fast)
......
...@@ -223,13 +223,14 @@ static long long compute_gap(struct slave *slave) ...@@ -223,13 +223,14 @@ static long long compute_gap(struct slave *slave)
static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
{ {
struct slave *slave, *least_loaded; struct slave *slave, *least_loaded;
struct list_head *iter;
long long max_gap; long long max_gap;
least_loaded = NULL; least_loaded = NULL;
max_gap = LLONG_MIN; max_gap = LLONG_MIN;
/* Find the slave with the largest gap */ /* Find the slave with the largest gap */
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
if (SLAVE_IS_OK(slave)) { if (SLAVE_IS_OK(slave)) {
long long gap = compute_gap(slave); long long gap = compute_gap(slave);
...@@ -1172,8 +1173,9 @@ static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *sla ...@@ -1172,8 +1173,9 @@ static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *sla
*/ */
static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave) static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave)
{ {
struct slave *tmp_slave1, *free_mac_slave = NULL;
struct slave *has_bond_addr = bond->curr_active_slave; struct slave *has_bond_addr = bond->curr_active_slave;
struct slave *tmp_slave1, *free_mac_slave = NULL;
struct list_head *iter;
if (list_empty(&bond->slave_list)) { if (list_empty(&bond->slave_list)) {
/* this is the first slave */ /* this is the first slave */
...@@ -1196,7 +1198,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav ...@@ -1196,7 +1198,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
/* The slave's address is equal to the address of the bond. /* The slave's address is equal to the address of the bond.
* Search for a spare address in the bond for this slave. * Search for a spare address in the bond for this slave.
*/ */
bond_for_each_slave(bond, tmp_slave1) { bond_for_each_slave(bond, tmp_slave1, iter) {
if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) { if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) {
/* no slave has tmp_slave1's perm addr /* no slave has tmp_slave1's perm addr
* as its curr addr * as its curr addr
...@@ -1247,6 +1249,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav ...@@ -1247,6 +1249,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
static int alb_set_mac_address(struct bonding *bond, void *addr) static int alb_set_mac_address(struct bonding *bond, void *addr)
{ {
struct slave *slave, *rollback_slave; struct slave *slave, *rollback_slave;
struct list_head *iter;
struct sockaddr sa; struct sockaddr sa;
char tmp_addr[ETH_ALEN]; char tmp_addr[ETH_ALEN];
int res; int res;
...@@ -1254,7 +1257,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr) ...@@ -1254,7 +1257,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
if (bond->alb_info.rlb_enabled) if (bond->alb_info.rlb_enabled)
return 0; return 0;
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
/* save net_device's current hw address */ /* save net_device's current hw address */
memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN); memcpy(tmp_addr, slave->dev->dev_addr, ETH_ALEN);
...@@ -1274,7 +1277,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr) ...@@ -1274,7 +1277,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr)
sa.sa_family = bond->dev->type; sa.sa_family = bond->dev->type;
/* unwind from head to the slave that failed */ /* unwind from head to the slave that failed */
bond_for_each_slave(bond, rollback_slave) { bond_for_each_slave(bond, rollback_slave, iter) {
if (rollback_slave == slave) if (rollback_slave == slave)
break; break;
memcpy(tmp_addr, rollback_slave->dev->dev_addr, ETH_ALEN); memcpy(tmp_addr, rollback_slave->dev->dev_addr, ETH_ALEN);
...@@ -1460,6 +1463,7 @@ void bond_alb_monitor(struct work_struct *work) ...@@ -1460,6 +1463,7 @@ void bond_alb_monitor(struct work_struct *work)
struct bonding *bond = container_of(work, struct bonding, struct bonding *bond = container_of(work, struct bonding,
alb_work.work); alb_work.work);
struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
struct list_head *iter;
struct slave *slave; struct slave *slave;
read_lock(&bond->lock); read_lock(&bond->lock);
...@@ -1482,7 +1486,7 @@ void bond_alb_monitor(struct work_struct *work) ...@@ -1482,7 +1486,7 @@ void bond_alb_monitor(struct work_struct *work)
*/ */
read_lock(&bond->curr_slave_lock); read_lock(&bond->curr_slave_lock);
bond_for_each_slave(bond, slave) bond_for_each_slave(bond, slave, iter)
alb_send_learning_packets(slave, slave->dev->dev_addr); alb_send_learning_packets(slave, slave->dev->dev_addr);
read_unlock(&bond->curr_slave_lock); read_unlock(&bond->curr_slave_lock);
...@@ -1495,7 +1499,7 @@ void bond_alb_monitor(struct work_struct *work) ...@@ -1495,7 +1499,7 @@ void bond_alb_monitor(struct work_struct *work)
read_lock(&bond->curr_slave_lock); read_lock(&bond->curr_slave_lock);
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
tlb_clear_slave(bond, slave, 1); tlb_clear_slave(bond, slave, 1);
if (slave == bond->curr_active_slave) { if (slave == bond->curr_active_slave) {
SLAVE_TLB_INFO(slave).load = SLAVE_TLB_INFO(slave).load =
......
This diff is collapsed.
...@@ -10,8 +10,9 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -10,8 +10,9 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
__acquires(&bond->lock) __acquires(&bond->lock)
{ {
struct bonding *bond = seq->private; struct bonding *bond = seq->private;
loff_t off = 0; struct list_head *iter;
struct slave *slave; struct slave *slave;
loff_t off = 0;
/* make sure the bond won't be taken away */ /* make sure the bond won't be taken away */
rcu_read_lock(); rcu_read_lock();
...@@ -20,7 +21,7 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) ...@@ -20,7 +21,7 @@ static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos)
if (*pos == 0) if (*pos == 0)
return SEQ_START_TOKEN; return SEQ_START_TOKEN;
bond_for_each_slave(bond, slave) bond_for_each_slave(bond, slave, iter)
if (++off == *pos) if (++off == *pos)
return slave; return slave;
......
...@@ -210,11 +210,12 @@ static ssize_t bonding_show_slaves(struct device *d, ...@@ -210,11 +210,12 @@ static ssize_t bonding_show_slaves(struct device *d,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
struct list_head *iter;
struct slave *slave; struct slave *slave;
int res = 0; int res = 0;
read_lock(&bond->lock); read_lock(&bond->lock);
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
if (res > (PAGE_SIZE - IFNAMSIZ)) { if (res > (PAGE_SIZE - IFNAMSIZ)) {
/* not enough space for another interface name */ /* not enough space for another interface name */
if ((PAGE_SIZE - res) > 10) if ((PAGE_SIZE - res) > 10)
...@@ -656,6 +657,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, ...@@ -656,6 +657,7 @@ static ssize_t bonding_store_arp_targets(struct device *d,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
struct list_head *iter;
struct slave *slave; struct slave *slave;
__be32 newtarget, *targets; __be32 newtarget, *targets;
unsigned long *targets_rx; unsigned long *targets_rx;
...@@ -688,7 +690,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, ...@@ -688,7 +690,7 @@ static ssize_t bonding_store_arp_targets(struct device *d,
&newtarget); &newtarget);
/* not to race with bond_arp_rcv */ /* not to race with bond_arp_rcv */
write_lock_bh(&bond->lock); write_lock_bh(&bond->lock);
bond_for_each_slave(bond, slave) bond_for_each_slave(bond, slave, iter)
slave->target_last_arp_rx[ind] = jiffies; slave->target_last_arp_rx[ind] = jiffies;
targets[ind] = newtarget; targets[ind] = newtarget;
write_unlock_bh(&bond->lock); write_unlock_bh(&bond->lock);
...@@ -714,7 +716,7 @@ static ssize_t bonding_store_arp_targets(struct device *d, ...@@ -714,7 +716,7 @@ static ssize_t bonding_store_arp_targets(struct device *d,
&newtarget); &newtarget);
write_lock_bh(&bond->lock); write_lock_bh(&bond->lock);
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
targets_rx = slave->target_last_arp_rx; targets_rx = slave->target_last_arp_rx;
j = ind; j = ind;
for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++) for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++)
...@@ -1111,6 +1113,7 @@ static ssize_t bonding_store_primary(struct device *d, ...@@ -1111,6 +1113,7 @@ static ssize_t bonding_store_primary(struct device *d,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
struct list_head *iter;
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
struct slave *slave; struct slave *slave;
...@@ -1138,7 +1141,7 @@ static ssize_t bonding_store_primary(struct device *d, ...@@ -1138,7 +1141,7 @@ static ssize_t bonding_store_primary(struct device *d,
goto out; goto out;
} }
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
pr_info("%s: Setting %s as primary slave.\n", pr_info("%s: Setting %s as primary slave.\n",
bond->dev->name, slave->dev->name); bond->dev->name, slave->dev->name);
...@@ -1286,6 +1289,7 @@ static ssize_t bonding_store_active_slave(struct device *d, ...@@ -1286,6 +1289,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
{ {
struct slave *slave, *old_active, *new_active; struct slave *slave, *old_active, *new_active;
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
struct list_head *iter;
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
if (!rtnl_trylock()) if (!rtnl_trylock())
...@@ -1313,7 +1317,7 @@ static ssize_t bonding_store_active_slave(struct device *d, ...@@ -1313,7 +1317,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
goto out; goto out;
} }
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
old_active = bond->curr_active_slave; old_active = bond->curr_active_slave;
new_active = slave; new_active = slave;
...@@ -1493,6 +1497,7 @@ static ssize_t bonding_show_queue_id(struct device *d, ...@@ -1493,6 +1497,7 @@ static ssize_t bonding_show_queue_id(struct device *d,
char *buf) char *buf)
{ {
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
struct list_head *iter;
struct slave *slave; struct slave *slave;
int res = 0; int res = 0;
...@@ -1500,7 +1505,7 @@ static ssize_t bonding_show_queue_id(struct device *d, ...@@ -1500,7 +1505,7 @@ static ssize_t bonding_show_queue_id(struct device *d,
return restart_syscall(); return restart_syscall();
read_lock(&bond->lock); read_lock(&bond->lock);
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
/* not enough space for another interface_name:queue_id pair */ /* not enough space for another interface_name:queue_id pair */
if ((PAGE_SIZE - res) > 10) if ((PAGE_SIZE - res) > 10)
...@@ -1529,6 +1534,7 @@ static ssize_t bonding_store_queue_id(struct device *d, ...@@ -1529,6 +1534,7 @@ static ssize_t bonding_store_queue_id(struct device *d,
{ {
struct slave *slave, *update_slave; struct slave *slave, *update_slave;
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
struct list_head *iter;
u16 qid; u16 qid;
int ret = count; int ret = count;
char *delim; char *delim;
...@@ -1565,7 +1571,7 @@ static ssize_t bonding_store_queue_id(struct device *d, ...@@ -1565,7 +1571,7 @@ static ssize_t bonding_store_queue_id(struct device *d,
/* Search for thes slave and check for duplicate qids */ /* Search for thes slave and check for duplicate qids */
update_slave = NULL; update_slave = NULL;
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
if (sdev == slave->dev) if (sdev == slave->dev)
/* /*
* We don't need to check the matching * We don't need to check the matching
...@@ -1619,6 +1625,7 @@ static ssize_t bonding_store_slaves_active(struct device *d, ...@@ -1619,6 +1625,7 @@ static ssize_t bonding_store_slaves_active(struct device *d,
{ {
struct bonding *bond = to_bond(d); struct bonding *bond = to_bond(d);
int new_value, ret = count; int new_value, ret = count;
struct list_head *iter;
struct slave *slave; struct slave *slave;
if (sscanf(buf, "%d", &new_value) != 1) { if (sscanf(buf, "%d", &new_value) != 1) {
...@@ -1641,7 +1648,7 @@ static ssize_t bonding_store_slaves_active(struct device *d, ...@@ -1641,7 +1648,7 @@ static ssize_t bonding_store_slaves_active(struct device *d,
} }
read_lock(&bond->lock); read_lock(&bond->lock);
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
if (!bond_is_active_slave(slave)) { if (!bond_is_active_slave(slave)) {
if (new_value) if (new_value)
slave->inactive = 0; slave->inactive = 0;
......
...@@ -110,15 +110,16 @@ ...@@ -110,15 +110,16 @@
* bond_for_each_slave - iterate over all slaves * bond_for_each_slave - iterate over all slaves
* @bond: the bond holding this list * @bond: the bond holding this list
* @pos: current slave * @pos: current slave
* @iter: list_head * iterator
* *
* Caller must hold bond->lock * Caller must hold bond->lock
*/ */
#define bond_for_each_slave(bond, pos) \ #define bond_for_each_slave(bond, pos, iter) \
list_for_each_entry(pos, &(bond)->slave_list, list) netdev_for_each_lower_private((bond)->dev, pos, iter)
/* Caller must have rcu_read_lock */ /* Caller must have rcu_read_lock */
#define bond_for_each_slave_rcu(bond, pos) \ #define bond_for_each_slave_rcu(bond, pos, iter) \
list_for_each_entry_rcu(pos, &(bond)->slave_list, list) netdev_for_each_lower_private_rcu((bond)->dev, pos, iter)
#ifdef CONFIG_NET_POLL_CONTROLLER #ifdef CONFIG_NET_POLL_CONTROLLER
extern atomic_t netpoll_block_tx; extern atomic_t netpoll_block_tx;
...@@ -476,9 +477,10 @@ static inline void bond_destroy_proc_dir(struct bond_net *bn) ...@@ -476,9 +477,10 @@ static inline void bond_destroy_proc_dir(struct bond_net *bn)
static inline struct slave *bond_slave_has_mac(struct bonding *bond, static inline struct slave *bond_slave_has_mac(struct bonding *bond,
const u8 *mac) const u8 *mac)
{ {
struct list_head *iter;
struct slave *tmp; struct slave *tmp;
bond_for_each_slave(bond, tmp) bond_for_each_slave(bond, tmp, iter)
if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr)) if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
return tmp; return tmp;
......
...@@ -3983,6 +3983,7 @@ static int cxgb4_inet6addr_handler(struct notifier_block *this, ...@@ -3983,6 +3983,7 @@ static int cxgb4_inet6addr_handler(struct notifier_block *this,
struct net_device *event_dev; struct net_device *event_dev;
int ret = NOTIFY_DONE; int ret = NOTIFY_DONE;
struct bonding *bond = netdev_priv(ifa->idev->dev); struct bonding *bond = netdev_priv(ifa->idev->dev);
struct list_head *iter;
struct slave *slave; struct slave *slave;
struct pci_dev *first_pdev = NULL; struct pci_dev *first_pdev = NULL;
...@@ -3995,7 +3996,7 @@ static int cxgb4_inet6addr_handler(struct notifier_block *this, ...@@ -3995,7 +3996,7 @@ static int cxgb4_inet6addr_handler(struct notifier_block *this,
* in all of them only once. * in all of them only once.
*/ */
read_lock(&bond->lock); read_lock(&bond->lock);
bond_for_each_slave(bond, slave) { bond_for_each_slave(bond, slave, iter) {
if (!first_pdev) { if (!first_pdev) {
ret = clip_add(slave->dev, ifa, event); ret = clip_add(slave->dev, ifa, event);
/* If clip_add is success then only initialize /* If clip_add is success then only initialize
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment