Skip to content

Commit 669966b

Browse files
Eric Dumazetkuba-moo
authored andcommitted
bonding: use exit_batch_rtnl() method
exit_batch_rtnl() is called while RTNL is held, and devices to be unregistered can be queued in the dev_kill_list. This saves one rtnl_lock()/rtnl_unlock() pair, and one unregister_netdevice_many() call. v2: Added bond_net_pre_exit() method to make sure bond_destroy_sysfs() is called before we unregister the devices in bond_net_exit_batch_rtnl (Antoine Tenart : https://lore.kernel.org/netdev/170688415193.5216.10499830272732622816@kwain/) Signed-off-by: Eric Dumazet <[email protected]> Acked-by: Jay Vosburgh <[email protected]> Cc: Andy Gospodarek <[email protected]> Reviewed-by: Antoine Tenart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 422b5ae commit 669966b

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6416,28 +6416,41 @@ static int __net_init bond_net_init(struct net *net)
64166416
return 0;
64176417
}
64186418

6419-
static void __net_exit bond_net_exit_batch(struct list_head *net_list)
6419+
/* According to commit 69b0216ac255 ("bonding: fix bonding_masters
6420+
* race condition in bond unloading") we need to remove sysfs files
6421+
* before we remove our devices (done later in bond_net_exit_batch_rtnl())
6422+
*/
6423+
static void __net_exit bond_net_pre_exit(struct net *net)
6424+
{
6425+
struct bond_net *bn = net_generic(net, bond_net_id);
6426+
6427+
bond_destroy_sysfs(bn);
6428+
}
6429+
6430+
static void __net_exit bond_net_exit_batch_rtnl(struct list_head *net_list,
6431+
struct list_head *dev_kill_list)
64206432
{
64216433
struct bond_net *bn;
64226434
struct net *net;
6423-
LIST_HEAD(list);
6424-
6425-
list_for_each_entry(net, net_list, exit_list) {
6426-
bn = net_generic(net, bond_net_id);
6427-
bond_destroy_sysfs(bn);
6428-
}
64296435

64306436
/* Kill off any bonds created after unregistering bond rtnl ops */
6431-
rtnl_lock();
64326437
list_for_each_entry(net, net_list, exit_list) {
64336438
struct bonding *bond, *tmp_bond;
64346439

64356440
bn = net_generic(net, bond_net_id);
64366441
list_for_each_entry_safe(bond, tmp_bond, &bn->dev_list, bond_list)
6437-
unregister_netdevice_queue(bond->dev, &list);
6442+
unregister_netdevice_queue(bond->dev, dev_kill_list);
64386443
}
6439-
unregister_netdevice_many(&list);
6440-
rtnl_unlock();
6444+
}
6445+
6446+
/* According to commit 23fa5c2caae0 ("bonding: destroy proc directory
6447+
* only after all bonds are gone") bond_destroy_proc_dir() is called
6448+
* after bond_net_exit_batch_rtnl() has completed.
6449+
*/
6450+
static void __net_exit bond_net_exit_batch(struct list_head *net_list)
6451+
{
6452+
struct bond_net *bn;
6453+
struct net *net;
64416454

64426455
list_for_each_entry(net, net_list, exit_list) {
64436456
bn = net_generic(net, bond_net_id);
@@ -6447,6 +6460,8 @@ static void __net_exit bond_net_exit_batch(struct list_head *net_list)
64476460

64486461
static struct pernet_operations bond_net_ops = {
64496462
.init = bond_net_init,
6463+
.pre_exit = bond_net_pre_exit,
6464+
.exit_batch_rtnl = bond_net_exit_batch_rtnl,
64506465
.exit_batch = bond_net_exit_batch,
64516466
.id = &bond_net_id,
64526467
.size = sizeof(struct bond_net),

0 commit comments

Comments
 (0)