Skip to content

Commit 4ca6db7

Browse files
kcp-gitjfvogel
authored andcommitted
rds: tcp: remove register_netdevice_notifier infrastructure.
The netns deletion path does not need to wait for all net_devices to be unregistered before dismantling rds_tcp state for the netns (we are able to dismantle this state on module unload even when all net_devices are active so there is no dependency here). This patch removes code related to netdevice notifiers and refactors all the code needed to dismantle rds_tcp state into a ->exit callback for the pernet_operations used with register_pernet_device(). Signed-off-by: Sowmini Varadhan <[email protected]> Reviewed-by: Kirill Tkhai <[email protected]> Signed-off-by: David S. Miller <[email protected]> Orabug: 28737841 (cherry picked from commit bdf5bd7) cherry-pick-repo=git/davem/net-next.git Signed-off-by: Ka-Cheong Poon <[email protected]> Reviewed-by: Sowmini Varadhan <[email protected]>
1 parent 4899f3b commit 4ca6db7

File tree

1 file changed

+22
-68
lines changed

1 file changed

+22
-68
lines changed

net/rds/tcp.c

Lines changed: 22 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -558,39 +558,6 @@ static __net_init int rds_tcp_init_net(struct net *net)
558558
return err;
559559
}
560560

561-
static void __net_exit rds_tcp_exit_net(struct net *net)
562-
{
563-
struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
564-
565-
if (rtn->rds_tcp_sysctl)
566-
unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
567-
568-
if (net != &init_net && rtn->ctl_table)
569-
kfree(rtn->ctl_table);
570-
571-
/* If rds_tcp_exit_net() is called as a result of netns deletion,
572-
* the rds_tcp_kill_sock() device notifier would already have cleaned
573-
* up the listen socket, thus there is no work to do in this function.
574-
*
575-
* If rds_tcp_exit_net() is called as a result of module unload,
576-
* i.e., due to rds_tcp_exit() -> unregister_pernet_subsys(), then
577-
* we do need to clean up the listen socket here.
578-
*/
579-
if (rtn->rds_tcp_listen_sock) {
580-
struct socket *lsock = rtn->rds_tcp_listen_sock;
581-
582-
rtn->rds_tcp_listen_sock = NULL;
583-
rds_tcp_listen_stop(lsock, &rtn->rds_tcp_accept_w);
584-
}
585-
}
586-
587-
static struct pernet_operations rds_tcp_net_ops = {
588-
.init = rds_tcp_init_net,
589-
.exit = rds_tcp_exit_net,
590-
.id = &rds_tcp_netid,
591-
.size = sizeof(struct rds_tcp_net),
592-
};
593-
594561
/* explicitly send a RST on each socket, thereby releasing any socket refcnts
595562
* that may otherwise hold up netns deletion.
596563
*/
@@ -637,40 +604,37 @@ static void rds_tcp_kill_sock(struct net *net)
637604
}
638605
}
639606

640-
void *rds_tcp_listen_sock_def_readable(struct net *net)
607+
static void __net_exit rds_tcp_exit_net(struct net *net)
641608
{
642609
struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
643-
struct socket *lsock = rtn->rds_tcp_listen_sock;
644610

645-
if (!lsock)
646-
return NULL;
611+
rds_tcp_kill_sock(net);
647612

648-
return lsock->sk->sk_user_data;
613+
if (rtn->rds_tcp_sysctl)
614+
unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
615+
616+
if (net != &init_net && rtn->ctl_table)
617+
kfree(rtn->ctl_table);
649618
}
650619

651-
static int rds_tcp_dev_event(struct notifier_block *this,
652-
unsigned long event, void *ptr)
620+
static struct pernet_operations rds_tcp_net_ops = {
621+
.init = rds_tcp_init_net,
622+
.exit = rds_tcp_exit_net,
623+
.id = &rds_tcp_netid,
624+
.size = sizeof(struct rds_tcp_net),
625+
};
626+
627+
void *rds_tcp_listen_sock_def_readable(struct net *net)
653628
{
654-
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
629+
struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
630+
struct socket *lsock = rtn->rds_tcp_listen_sock;
655631

656-
/* rds-tcp registers as a pernet subys, so the ->exit will only
657-
* get invoked after network acitivity has quiesced. We need to
658-
* clean up all sockets to quiesce network activity, and use
659-
* the unregistration of the per-net loopback device as a trigger
660-
* to start that cleanup.
661-
*/
662-
if (event == NETDEV_UNREGISTER_FINAL &&
663-
dev->ifindex == LOOPBACK_IFINDEX)
664-
rds_tcp_kill_sock(dev_net(dev));
632+
if (!lsock)
633+
return NULL;
665634

666-
return NOTIFY_DONE;
635+
return lsock->sk->sk_user_data;
667636
}
668637

669-
static struct notifier_block rds_tcp_dev_notifier = {
670-
.notifier_call = rds_tcp_dev_event,
671-
.priority = -10, /* must be called after other network notifiers */
672-
};
673-
674638
/* when sysctl is used to modify some kernel socket parameters,this
675639
* function resets the RDS connections in that netns so that we can
676640
* restart with new parameters. The assumption is that such reset
@@ -717,9 +681,7 @@ static void __exit rds_tcp_exit(void)
717681
#if IS_ENABLED(CONFIG_IPV6)
718682
rds_info_deregister_func(RDS6_INFO_TCP_SOCKETS, rds6_tcp_tc_info);
719683
#endif
720-
unregister_pernet_subsys(&rds_tcp_net_ops);
721-
if (unregister_netdevice_notifier(&rds_tcp_dev_notifier))
722-
pr_warn("could not unregister rds_tcp_dev_notifier\n");
684+
unregister_pernet_device(&rds_tcp_net_ops);
723685
rds_tcp_destroy_conns();
724686
rds_trans_unregister(&rds_tcp_transport);
725687
rds_tcp_recv_exit();
@@ -743,16 +705,10 @@ static int __init rds_tcp_init(void)
743705
if (ret)
744706
goto out_slab;
745707

746-
ret = register_pernet_subsys(&rds_tcp_net_ops);
708+
ret = register_pernet_device(&rds_tcp_net_ops);
747709
if (ret)
748710
goto out_recv;
749711

750-
ret = register_netdevice_notifier(&rds_tcp_dev_notifier);
751-
if (ret) {
752-
pr_warn("could not register rds_tcp_dev_notifier\n");
753-
goto out_pernet;
754-
}
755-
756712
ret = rds_trans_register(&rds_tcp_transport);
757713

758714
rds_info_register_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
@@ -762,8 +718,6 @@ static int __init rds_tcp_init(void)
762718

763719
goto out;
764720

765-
out_pernet:
766-
unregister_pernet_subsys(&rds_tcp_net_ops);
767721
out_recv:
768722
rds_tcp_recv_exit();
769723
out_slab:

0 commit comments

Comments
 (0)