tipc: fix modprobe tipc failed after switch order of device registration
Subsystems (3)
PATCH v4 1/1 tipc: fix modprobe tipc failed after switch order of device registration
From: Junwei Hu <[email protected]>
Error message printed:
modprobe: ERROR: could not insert 'tipc': Address family not supported by protocol.
when modprobe tipc after the following patch: switch order of device registration, commit 7e27e8d6130c
("tipc: switch order of device registration to fix a crash")
Because sock_create_kern(net, AF_TIPC, ...) called by tipc_topsrv_create_listener() in the initialization process
of tipc_init_net(), so tipc_socket_init() must be execute before that. Meanwhile, tipc_net_id need to be initialized when sock_create() called, and tipc_socket_init() is no need to be called for each namespace.
I add a variable tipc_topsrv_net_ops, and split the register_pernet_subsys() of tipc into two parts, and split tipc_socket_init() with initialization of pernet params.
By the way, I fixed resources rollback error when tipc_bcast_init() failed in tipc_init_net().
---V1->V2:
- split the register_pernet_subsys() of tipc into two parts V2->V3:
- update Reported-byV2->V4:
- update Fixes tag
--- net/tipc/core.c | 18 ++++++++++++------ net/tipc/subscr.h | 5 +++-- net/tipc/topsrv.c | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 10 deletions(-)
net/tipc/core.c +12 -6
@@ -77,9 +77,6 @@ static int __net_init tipc_init_net(struct net *net) goto out_nametbl;INIT_LIST_HEAD (&tn->dist_queue); - err =tipc_topsrv_start (net); -if (err) - goto out_subscr; err =tipc_bcast_init (net);if (err)
@@ -88,8 +85,6 @@ static int __net_init tipc_init_net(struct net *net)return 0 ; out_bclink: -tipc_bcast_stop (net); -out_subscr:tipc_nametbl_stop (net); out_nametbl:tipc_sk_rht_destroy (net);
@@ -99,7 +94,6 @@ static int __net_init tipc_init_net(struct net *net) static void __net_exit tipc_exit_net(struct net *net) { -tipc_topsrv_stop (net);tipc_net_stop (net);tipc_bcast_stop (net);tipc_nametbl_stop (net);
@@ -113,6 +107,11 @@ static struct pernet_operations tipc_net_ops = { .size = sizeof(struct tipc_net), }; +static struct pernet_operations tipc_topsrv_net_ops = { + .init = tipc_topsrv_init_net, + .exit = tipc_topsrv_exit_net, +}; +static int __init tipc_init (void ) {int err;
@@ -143,6 +142,10 @@ static int __init tipc_init(void)if (err) goto out_socket; + err =register_pernet_subsys (&tipc_topsrv_net_ops); +if (err) + goto out_pernet_topsrv; + err =tipc_bearer_setup ();if (err) goto out_bearer;
@@ -150,6 +153,8 @@ static int __init tipc_init(void)pr_info ("Started in single node mode\n" );return 0 ; out_bearer: +unregister_pernet_subsys (&tipc_topsrv_net_ops); +out_pernet_topsrv:tipc_socket_stop (); out_socket:unregister_pernet_subsys (&tipc_net_ops);
@@ -167,6 +172,7 @@ static int __init tipc_init(void) static void __exit tipc_exit(void) {tipc_bearer_cleanup (); +unregister_pernet_subsys (&tipc_topsrv_net_ops);tipc_socket_stop ();unregister_pernet_subsys (&tipc_net_ops);tipc_netlink_stop ();
net/tipc/subscr.h +3 -2
@@ -77,8 +77,9 @@ void tipc_sub_report_overlap(struct tipc_subscription *sub, u32 found_lower, u32 found_upper, u32 event, u32 port, u32 node, u32 scope, int must); -int tipc_topsrv_start (struct net *net); -void tipc_topsrv_stop (struct net *net); + +int __net_init tipc_topsrv_init_net (struct net *net); +void __net_exit tipc_topsrv_exit_net(struct net *net);void tipc_sub_put (struct tipc_subscription *subscription);void tipc_sub_get (struct tipc_subscription *subscription);
net/tipc/topsrv.c +12 -2
@@ -635,7 +635,7 @@ static void tipc_topsrv_work_stop(struct tipc_topsrv *s)destroy_workqueue (s->send_wq); } -int tipc_topsrv_start (struct net *net) +static int tipc_topsrv_start (struct net *net) {struct tipc_net *tn =tipc_net (net);const char name[] ="topology_server" ;
@@ -668,7 +668,7 @@ int tipc_topsrv_start(struct net *net)return ret; } -void tipc_topsrv_stop (struct net *net) +static void tipc_topsrv_stop (struct net *net) {struct tipc_topsrv *srv =tipc_topsrv (net);struct socket *lsock = srv->listener;
@@ -693,3 +693,13 @@ void tipc_topsrv_stop(struct net *net)idr_destroy (&srv->conn_idr);kfree (srv); } + +int __net_init tipc_topsrv_init_net (struct net *net) +{ +return tipc_topsrv_start (net); +} + +void __net_exit tipc_topsrv_exit_net(struct net *net) +{ +tipc_topsrv_stop (net); +}
Signature · 1 line
2.21.GIT
From: hujunwei <[email protected]>
Date: Mon, 20 May 2019 14:43:59 +0800
Quoted 22 lines
From: Junwei Hu <[email protected]>
Error message printed:
modprobe: ERROR: could not insert 'tipc': Address family not supported by protocol.
when modprobe tipc after the following patch: switch order of device registration, commit7e27e8d6130c
("tipc: switch order of device registration to fix a crash")Because
sock_create_kern(net, AF_TIPC, ...)called bytipc_topsrv_create_listener()in the initialization process
oftipc_init_net(), sotipc_socket_init()must be execute before that. Meanwhile,tipc_net_idneed to be initialized whensock_create()called, andtipc_socket_init()is no need to be called for each namespace.I add a variable
tipc_topsrv_net_ops, and split theregister_pernet_subsys()of tipc into two parts, and splittipc_socket_init()with initialization of pernet params.By the way, I fixed resources rollback error when
tipc_bcast_init()failed intipc_init_net().
Quoted 6 lines
Fixes 7e27e8d6130c ("tipc: switch order of device registration to fix a crash")Signed-off-by Junwei Hu <[email protected]>Reported-by Wang Wang <[email protected]>Reported-by [email protected]Reviewed-by Kang Zhou <[email protected]>Reviewed-by Suanming Mou <[email protected]>
Applied.
Jon Maloy
Reviewed-byReviewed and tested. I found no problems with this.
Quoted 46 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of David Miller
Sent: 20-May-19 13:46
To: [email protected]
Cc: Jon Maloy <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH v4] tipc: fix modprobe tipc failed after switch order of device registrationFrom: hujunwei <[email protected]>
Date: Mon, 20 May 2019 14:43:59 +0800Quoted 22 lines
From: Junwei Hu <[email protected]>
Error message printed:
modprobe: ERROR: could not insert 'tipc': Address family not supported by protocol.
when modprobe tipc after the following patch: switch order of device registration, commit7e27e8d6130c
("tipc: switch order of device registration to fix a crash")Because
sock_create_kern(net, AF_TIPC, ...)called bytipc_topsrv_create_listener()in the initialization process oftipc_init_net(), sotipc_socket_init()must be execute before that. Meanwhile,tipc_net_idneed to be initialized whensock_create()called, andtipc_socket_init()is no need to be called for each namespace.I add a variable
tipc_topsrv_net_ops, and split theregister_pernet_subsys()of tipc into two parts, and splittipc_socket_init()with initialization of pernet params.By the way, I fixed resources rollback error when
tipc_bcast_init()failed intipc_init_net().Quoted 7 lines
Fixes 7e27e8d6130c ("tipc: switch order of device registration to fixa crash")
Signed-off-by Junwei Hu <[email protected]>Reported-by Wang Wang <[email protected]>Reported-by [email protected]Reviewed-by Kang Zhou <[email protected]>Reviewed-by Suanming Mou <[email protected]>Applied.