Skip to content

Commit 6b447e7

Browse files
Maor GottliebSaeed Mahameed
authored andcommitted
bonding: Add array of all slaves
Keep all slaves in array so it could be used to get the xmit slave assume all the slaves are active. The logic to add slave to the array is like the usable slaves, except that we also add slaves that currently can't transmit - not up or active. Signed-off-by: Maor Gottlieb <maorg@mellanox.com> Reviewed-by: Jiri Pirko <jiri@mellanox.com> Reviewed-by: Jay Vosburgh <jay.vosburgh@canonical.com> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
1 parent 5a19f1c commit 6b447e7

2 files changed

Lines changed: 61 additions & 20 deletions

File tree

‎drivers/net/bonding/bond_main.c‎

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,6 +4120,38 @@ static void bond_skip_slave(struct bond_up_slave *slaves,
41204120
}
41214121
}
41224122

4123+
static void bond_set_slave_arr(struct bonding *bond,
4124+
struct bond_up_slave *usable_slaves,
4125+
struct bond_up_slave *all_slaves)
4126+
{
4127+
struct bond_up_slave *usable, *all;
4128+
4129+
usable = rtnl_dereference(bond->usable_slaves);
4130+
rcu_assign_pointer(bond->usable_slaves, usable_slaves);
4131+
kfree_rcu(usable, rcu);
4132+
4133+
all = rtnl_dereference(bond->all_slaves);
4134+
rcu_assign_pointer(bond->all_slaves, all_slaves);
4135+
kfree_rcu(all, rcu);
4136+
}
4137+
4138+
static void bond_reset_slave_arr(struct bonding *bond)
4139+
{
4140+
struct bond_up_slave *usable, *all;
4141+
4142+
usable = rtnl_dereference(bond->usable_slaves);
4143+
if (usable) {
4144+
RCU_INIT_POINTER(bond->usable_slaves, NULL);
4145+
kfree_rcu(usable, rcu);
4146+
}
4147+
4148+
all = rtnl_dereference(bond->all_slaves);
4149+
if (all) {
4150+
RCU_INIT_POINTER(bond->all_slaves, NULL);
4151+
kfree_rcu(all, rcu);
4152+
}
4153+
}
4154+
41234155
/* Build the usable slaves array in control path for modes that use xmit-hash
41244156
* to determine the slave interface -
41254157
* (a) BOND_MODE_8023AD
@@ -4130,7 +4162,7 @@ static void bond_skip_slave(struct bond_up_slave *slaves,
41304162
*/
41314163
int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
41324164
{
4133-
struct bond_up_slave *usable_slaves, *old_usable_slaves;
4165+
struct bond_up_slave *usable_slaves = NULL, *all_slaves = NULL;
41344166
struct slave *slave;
41354167
struct list_head *iter;
41364168
int agg_id = 0;
@@ -4142,7 +4174,9 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
41424174

41434175
usable_slaves = kzalloc(struct_size(usable_slaves, arr,
41444176
bond->slave_cnt), GFP_KERNEL);
4145-
if (!usable_slaves) {
4177+
all_slaves = kzalloc(struct_size(all_slaves, arr,
4178+
bond->slave_cnt), GFP_KERNEL);
4179+
if (!usable_slaves || !all_slaves) {
41464180
ret = -ENOMEM;
41474181
goto out;
41484182
}
@@ -4151,20 +4185,19 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
41514185

41524186
if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
41534187
pr_debug("bond_3ad_get_active_agg_info failed\n");
4154-
kfree_rcu(usable_slaves, rcu);
41554188
/* No active aggragator means it's not safe to use
41564189
* the previous array.
41574190
*/
4158-
old_usable_slaves = rtnl_dereference(bond->usable_slaves);
4159-
if (old_usable_slaves) {
4160-
RCU_INIT_POINTER(bond->usable_slaves, NULL);
4161-
kfree_rcu(old_usable_slaves, rcu);
4162-
}
4191+
bond_reset_slave_arr(bond);
41634192
goto out;
41644193
}
41654194
agg_id = ad_info.aggregator_id;
41664195
}
41674196
bond_for_each_slave(bond, slave, iter) {
4197+
if (skipslave == slave)
4198+
continue;
4199+
4200+
all_slaves->arr[all_slaves->count++] = slave;
41684201
if (BOND_MODE(bond) == BOND_MODE_8023AD) {
41694202
struct aggregator *agg;
41704203

@@ -4174,23 +4207,24 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
41744207
}
41754208
if (!bond_slave_can_tx(slave))
41764209
continue;
4177-
if (skipslave == slave)
4178-
continue;
41794210

41804211
slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
41814212
usable_slaves->count);
41824213

41834214
usable_slaves->arr[usable_slaves->count++] = slave;
41844215
}
41854216

4186-
old_usable_slaves = rtnl_dereference(bond->usable_slaves);
4187-
rcu_assign_pointer(bond->usable_slaves, usable_slaves);
4188-
if (old_usable_slaves)
4189-
kfree_rcu(old_usable_slaves, rcu);
4217+
bond_set_slave_arr(bond, usable_slaves, all_slaves);
4218+
return ret;
41904219
out:
4191-
if (ret != 0 && skipslave)
4220+
if (ret != 0 && skipslave) {
4221+
bond_skip_slave(rtnl_dereference(bond->all_slaves),
4222+
skipslave);
41924223
bond_skip_slave(rtnl_dereference(bond->usable_slaves),
41934224
skipslave);
4225+
}
4226+
kfree_rcu(all_slaves, rcu);
4227+
kfree_rcu(usable_slaves, rcu);
41944228

41954229
return ret;
41964230
}
@@ -4501,9 +4535,9 @@ void bond_setup(struct net_device *bond_dev)
45014535
static void bond_uninit(struct net_device *bond_dev)
45024536
{
45034537
struct bonding *bond = netdev_priv(bond_dev);
4538+
struct bond_up_slave *usable, *all;
45044539
struct list_head *iter;
45054540
struct slave *slave;
4506-
struct bond_up_slave *arr;
45074541

45084542
bond_netpoll_cleanup(bond_dev);
45094543

@@ -4512,10 +4546,16 @@ static void bond_uninit(struct net_device *bond_dev)
45124546
__bond_release_one(bond_dev, slave->dev, true, true);
45134547
netdev_info(bond_dev, "Released all slaves\n");
45144548

4515-
arr = rtnl_dereference(bond->usable_slaves);
4516-
if (arr) {
4549+
usable = rtnl_dereference(bond->usable_slaves);
4550+
if (usable) {
45174551
RCU_INIT_POINTER(bond->usable_slaves, NULL);
4518-
kfree_rcu(arr, rcu);
4552+
kfree_rcu(usable, rcu);
4553+
}
4554+
4555+
all = rtnl_dereference(bond->all_slaves);
4556+
if (all) {
4557+
RCU_INIT_POINTER(bond->all_slaves, NULL);
4558+
kfree_rcu(all, rcu);
45194559
}
45204560

45214561
list_del(&bond->bond_list);

‎include/net/bonding.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ struct bonding {
200200
struct slave __rcu *curr_active_slave;
201201
struct slave __rcu *current_arp_slave;
202202
struct slave __rcu *primary_slave;
203-
struct bond_up_slave __rcu *usable_slaves; /* Array of usable slaves */
203+
struct bond_up_slave __rcu *usable_slaves;
204+
struct bond_up_slave __rcu *all_slaves;
204205
bool force_primary;
205206
s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
206207
int (*recv_probe)(const struct sk_buff *, struct bonding *,

0 commit comments

Comments
 (0)