Skip to content

Commit bdf5bd7

Browse files
sowminivdavem330
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]>
1 parent 692ec06 commit bdf5bd7

File tree

1 file changed

+23
-70
lines changed

1 file changed

+23
-70
lines changed

net/rds/tcp.c

Lines changed: 23 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -485,40 +485,6 @@ static __net_init int rds_tcp_init_net(struct net *net)
485485
return err;
486486
}
487487

488-
static void __net_exit rds_tcp_exit_net(struct net *net)
489-
{
490-
struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
491-
492-
if (rtn->rds_tcp_sysctl)
493-
unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
494-
495-
if (net != &init_net && rtn->ctl_table)
496-
kfree(rtn->ctl_table);
497-
498-
/* If rds_tcp_exit_net() is called as a result of netns deletion,
499-
* the rds_tcp_kill_sock() device notifier would already have cleaned
500-
* up the listen socket, thus there is no work to do in this function.
501-
*
502-
* If rds_tcp_exit_net() is called as a result of module unload,
503-
* i.e., due to rds_tcp_exit() -> unregister_pernet_subsys(), then
504-
* we do need to clean up the listen socket here.
505-
*/
506-
if (rtn->rds_tcp_listen_sock) {
507-
struct socket *lsock = rtn->rds_tcp_listen_sock;
508-
509-
rtn->rds_tcp_listen_sock = NULL;
510-
rds_tcp_listen_stop(lsock, &rtn->rds_tcp_accept_w);
511-
}
512-
}
513-
514-
static struct pernet_operations rds_tcp_net_ops = {
515-
.init = rds_tcp_init_net,
516-
.exit = rds_tcp_exit_net,
517-
.id = &rds_tcp_netid,
518-
.size = sizeof(struct rds_tcp_net),
519-
.async = true,
520-
};
521-
522488
static void rds_tcp_kill_sock(struct net *net)
523489
{
524490
struct rds_tcp_connection *tc, *_tc;
@@ -546,40 +512,38 @@ static void rds_tcp_kill_sock(struct net *net)
546512
rds_conn_destroy(tc->t_cpath->cp_conn);
547513
}
548514

549-
void *rds_tcp_listen_sock_def_readable(struct net *net)
515+
static void __net_exit rds_tcp_exit_net(struct net *net)
550516
{
551517
struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
552-
struct socket *lsock = rtn->rds_tcp_listen_sock;
553518

554-
if (!lsock)
555-
return NULL;
519+
rds_tcp_kill_sock(net);
556520

557-
return lsock->sk->sk_user_data;
521+
if (rtn->rds_tcp_sysctl)
522+
unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
523+
524+
if (net != &init_net && rtn->ctl_table)
525+
kfree(rtn->ctl_table);
558526
}
559527

560-
static int rds_tcp_dev_event(struct notifier_block *this,
561-
unsigned long event, void *ptr)
528+
static struct pernet_operations rds_tcp_net_ops = {
529+
.init = rds_tcp_init_net,
530+
.exit = rds_tcp_exit_net,
531+
.id = &rds_tcp_netid,
532+
.size = sizeof(struct rds_tcp_net),
533+
.async = true,
534+
};
535+
536+
void *rds_tcp_listen_sock_def_readable(struct net *net)
562537
{
563-
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
538+
struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
539+
struct socket *lsock = rtn->rds_tcp_listen_sock;
564540

565-
/* rds-tcp registers as a pernet subys, so the ->exit will only
566-
* get invoked after network acitivity has quiesced. We need to
567-
* clean up all sockets to quiesce network activity, and use
568-
* the unregistration of the per-net loopback device as a trigger
569-
* to start that cleanup.
570-
*/
571-
if (event == NETDEV_UNREGISTER_FINAL &&
572-
dev->ifindex == LOOPBACK_IFINDEX)
573-
rds_tcp_kill_sock(dev_net(dev));
541+
if (!lsock)
542+
return NULL;
574543

575-
return NOTIFY_DONE;
544+
return lsock->sk->sk_user_data;
576545
}
577546

578-
static struct notifier_block rds_tcp_dev_notifier = {
579-
.notifier_call = rds_tcp_dev_event,
580-
.priority = -10, /* must be called after other network notifiers */
581-
};
582-
583547
/* when sysctl is used to modify some kernel socket parameters,this
584548
* function resets the RDS connections in that netns so that we can
585549
* restart with new parameters. The assumption is that such reset
@@ -625,9 +589,7 @@ static void rds_tcp_exit(void)
625589
rds_tcp_set_unloading();
626590
synchronize_rcu();
627591
rds_info_deregister_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
628-
unregister_pernet_subsys(&rds_tcp_net_ops);
629-
if (unregister_netdevice_notifier(&rds_tcp_dev_notifier))
630-
pr_warn("could not unregister rds_tcp_dev_notifier\n");
592+
unregister_pernet_device(&rds_tcp_net_ops);
631593
rds_tcp_destroy_conns();
632594
rds_trans_unregister(&rds_tcp_transport);
633595
rds_tcp_recv_exit();
@@ -651,24 +613,15 @@ static int rds_tcp_init(void)
651613
if (ret)
652614
goto out_slab;
653615

654-
ret = register_pernet_subsys(&rds_tcp_net_ops);
616+
ret = register_pernet_device(&rds_tcp_net_ops);
655617
if (ret)
656618
goto out_recv;
657619

658-
ret = register_netdevice_notifier(&rds_tcp_dev_notifier);
659-
if (ret) {
660-
pr_warn("could not register rds_tcp_dev_notifier\n");
661-
goto out_pernet;
662-
}
663-
664620
rds_trans_register(&rds_tcp_transport);
665621

666622
rds_info_register_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
667623

668624
goto out;
669-
670-
out_pernet:
671-
unregister_pernet_subsys(&rds_tcp_net_ops);
672625
out_recv:
673626
rds_tcp_recv_exit();
674627
out_slab:

0 commit comments

Comments
 (0)