netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/2] tipc: clean up components initialization code
@ 2014-02-20  3:32 Ying Xue
  2014-02-20  3:32 ` [PATCH net 1/2] tipc: remove all enabled flags from all tipc components Ying Xue
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ying Xue @ 2014-02-20  3:32 UTC (permalink / raw)
  To: davem
  Cc: jon.maloy, Paul.Gortmaker, erik.hugne, netdev, tipc-discussion,
	wangweidong1

In this series, we will fix a regression issue involved by commit
6e967adf7(tipc: relocate common functions from media to bearer)
But before the issue is fixed, we firstly adjust the process of
components initialization so as to remove all enabled flags from
necessary tipc components. Otherwise, without the change, we also
have to add an extra enabled flag into bearer layer indicating
whether bearer setup is finshed or not.

Ying Xue (2):
  tipc: remove all enabled flags from all tipc components
  tipc: make bearer set up in module insertion stage

 net/tipc/bearer.c     |    7 +++-
 net/tipc/config.c     |    2 +-
 net/tipc/core.c       |  109 ++++++++++++++++++++++++++-----------------------
 net/tipc/core.h       |    1 -
 net/tipc/name_table.c |    3 --
 net/tipc/netlink.c    |    8 ----
 net/tipc/ref.c        |    3 --
 net/tipc/server.c     |    5 ---
 net/tipc/server.h     |    2 -
 net/tipc/socket.c     |    8 ----
 10 files changed, 66 insertions(+), 82 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net 1/2] tipc: remove all enabled flags from all tipc components
  2014-02-20  3:32 [PATCH net 0/2] tipc: clean up components initialization code Ying Xue
@ 2014-02-20  3:32 ` Ying Xue
  2014-02-20  3:32 ` [PATCH net 2/2] tipc: make bearer set up in module insertion stage Ying Xue
  2014-02-22  5:01 ` [PATCH net 0/2] tipc: clean up components initialization code David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Ying Xue @ 2014-02-20  3:32 UTC (permalink / raw)
  To: davem
  Cc: jon.maloy, Paul.Gortmaker, erik.hugne, netdev, tipc-discussion,
	wangweidong1

When tipc module is inserted, many tipc components are initialized
one by one. During the initialization period, if one of them is
failed, tipc_core_stop() will be called to stop all components
whatever corresponding components are created or not. To avoid to
release uncreated ones, relevant components have to add necessary
enabled flags indicating whether they are created or not.

But in the initialization stage, if one component is unsuccessfully
created, we will just destroy successfully created components before
the failed component instead of all components. All enabled flags
defined in components, in turn, become redundant. Additionally it's
also unnecessary to identify whether table.types is NULL in
tipc_nametbl_stop() because name stable has been definitely created
successfully when tipc_nametbl_stop() is called.

Cc: Jon Maloy <jon.maloy@ericsson.com>
Cc: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 net/tipc/core.c       |   71 ++++++++++++++++++++++++++++++++++---------------
 net/tipc/name_table.c |    3 ---
 net/tipc/netlink.c    |    8 ------
 net/tipc/ref.c        |    3 ---
 net/tipc/server.c     |    5 ----
 net/tipc/server.h     |    2 --
 net/tipc/socket.c     |    8 ------
 7 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/net/tipc/core.c b/net/tipc/core.c
index f9e88d8..cfd9cc1 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -122,30 +122,59 @@ static void tipc_core_stop(void)
  */
 static int tipc_core_start(void)
 {
-	int res;
+	int err;
 
 	get_random_bytes(&tipc_random, sizeof(tipc_random));
 
-	res = tipc_handler_start();
-	if (!res)
-		res = tipc_ref_table_init(tipc_max_ports, tipc_random);
-	if (!res)
-		res = tipc_nametbl_init();
-	if (!res)
-		res = tipc_netlink_start();
-	if (!res)
-		res = tipc_socket_init();
-	if (!res)
-		res = tipc_register_sysctl();
-	if (!res)
-		res = tipc_subscr_start();
-	if (!res)
-		res = tipc_cfg_init();
-	if (res) {
-		tipc_handler_stop();
-		tipc_core_stop();
-	}
-	return res;
+	err = tipc_handler_start();
+	if (err)
+		goto out_handler;
+
+	err = tipc_ref_table_init(tipc_max_ports, tipc_random);
+	if (err)
+		goto out_reftbl;
+
+	err = tipc_nametbl_init();
+	if (err)
+		goto out_nametbl;
+
+	err = tipc_netlink_start();
+	if (err)
+		goto out_netlink;
+
+	err = tipc_socket_init();
+	if (err)
+		goto out_socket;
+
+	err = tipc_register_sysctl();
+	if (err)
+		goto out_sysctl;
+
+	err = tipc_subscr_start();
+	if (err)
+		goto out_subscr;
+
+	err = tipc_cfg_init();
+	if (err)
+		goto out_cfg;
+
+	return 0;
+out_cfg:
+	tipc_subscr_stop();
+out_subscr:
+	tipc_unregister_sysctl();
+out_sysctl:
+	tipc_socket_stop();
+out_socket:
+	tipc_netlink_stop();
+out_netlink:
+	tipc_nametbl_stop();
+out_nametbl:
+	tipc_ref_table_stop();
+out_reftbl:
+	tipc_handler_stop();
+out_handler:
+	return err;
 }
 
 static int __init tipc_init(void)
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c
index 92a1533..48302be 100644
--- a/net/tipc/name_table.c
+++ b/net/tipc/name_table.c
@@ -945,9 +945,6 @@ void tipc_nametbl_stop(void)
 {
 	u32 i;
 
-	if (!table.types)
-		return;
-
 	/* Verify name table is empty, then release it */
 	write_lock_bh(&tipc_nametbl_lock);
 	for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index 9f72a63..3aaf73d 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -83,8 +83,6 @@ static struct genl_ops tipc_genl_ops[] = {
 	},
 };
 
-static int tipc_genl_family_registered;
-
 int tipc_netlink_start(void)
 {
 	int res;
@@ -94,16 +92,10 @@ int tipc_netlink_start(void)
 		pr_err("Failed to register netlink interface\n");
 		return res;
 	}
-
-	tipc_genl_family_registered = 1;
 	return 0;
 }
 
 void tipc_netlink_stop(void)
 {
-	if (!tipc_genl_family_registered)
-		return;
-
 	genl_unregister_family(&tipc_genl_family);
-	tipc_genl_family_registered = 0;
 }
diff --git a/net/tipc/ref.c b/net/tipc/ref.c
index 2a2a938..de3d593 100644
--- a/net/tipc/ref.c
+++ b/net/tipc/ref.c
@@ -126,9 +126,6 @@ int tipc_ref_table_init(u32 requested_size, u32 start)
  */
 void tipc_ref_table_stop(void)
 {
-	if (!tipc_ref_table.entries)
-		return;
-
 	vfree(tipc_ref_table.entries);
 	tipc_ref_table.entries = NULL;
 }
diff --git a/net/tipc/server.c b/net/tipc/server.c
index b635ca3..3739797 100644
--- a/net/tipc/server.c
+++ b/net/tipc/server.c
@@ -573,7 +573,6 @@ int tipc_server_start(struct tipc_server *s)
 		kmem_cache_destroy(s->rcvbuf_cache);
 		return ret;
 	}
-	s->enabled = 1;
 	return ret;
 }
 
@@ -583,10 +582,6 @@ void tipc_server_stop(struct tipc_server *s)
 	int total = 0;
 	int id;
 
-	if (!s->enabled)
-		return;
-
-	s->enabled = 0;
 	spin_lock_bh(&s->idr_lock);
 	for (id = 0; total < s->idr_in_use; id++) {
 		con = idr_find(&s->conn_idr, id);
diff --git a/net/tipc/server.h b/net/tipc/server.h
index 98b23f2..be817b0 100644
--- a/net/tipc/server.h
+++ b/net/tipc/server.h
@@ -56,7 +56,6 @@
  * @name: server name
  * @imp: message importance
  * @type: socket type
- * @enabled: identify whether server is launched or not
  */
 struct tipc_server {
 	struct idr conn_idr;
@@ -74,7 +73,6 @@ struct tipc_server {
 	const char name[TIPC_SERVER_NAME_LEN];
 	int imp;
 	int type;
-	int enabled;
 };
 
 int tipc_conn_sendmsg(struct tipc_server *s, int conid,
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index aab4948..a4cf274 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -70,8 +70,6 @@ static const struct proto_ops msg_ops;
 static struct proto tipc_proto;
 static struct proto tipc_proto_kern;
 
-static int sockets_enabled;
-
 /*
  * Revised TIPC socket locking policy:
  *
@@ -2027,8 +2025,6 @@ int tipc_socket_init(void)
 		proto_unregister(&tipc_proto);
 		goto out;
 	}
-
-	sockets_enabled = 1;
  out:
 	return res;
 }
@@ -2038,10 +2034,6 @@ int tipc_socket_init(void)
  */
 void tipc_socket_stop(void)
 {
-	if (!sockets_enabled)
-		return;
-
-	sockets_enabled = 0;
 	sock_unregister(tipc_family_ops.family);
 	proto_unregister(&tipc_proto);
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net 2/2] tipc: make bearer set up in module insertion stage
  2014-02-20  3:32 [PATCH net 0/2] tipc: clean up components initialization code Ying Xue
  2014-02-20  3:32 ` [PATCH net 1/2] tipc: remove all enabled flags from all tipc components Ying Xue
@ 2014-02-20  3:32 ` Ying Xue
  2014-02-22  5:01 ` [PATCH net 0/2] tipc: clean up components initialization code David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Ying Xue @ 2014-02-20  3:32 UTC (permalink / raw)
  To: davem
  Cc: jon.maloy, Paul.Gortmaker, erik.hugne, netdev, tipc-discussion,
	wangweidong1

Accidentally a side effect is involved by commit 6e967adf7(tipc:
relocate common functions from media to bearer). Now tipc stack
handler of receiving packets from netdevices as well as netdevice
notification handler are registered when bearer is enabled rather
than tipc module initialization stage, but the two handlers are
both unregistered in tipc module exit phase. If tipc module is
inserted and then immediately removed, the following warning
message will appear:

"dev_remove_pack: ffffffffa0380940 not found"

This is because in module insertion stage tipc stack packet handler
is not registered at all, but in module exit phase dev_remove_pack()
needs to remove it. Of course, dev_remove_pack() cannot find tipc
protocol handler from the kernel protocol handler list so that the
warning message is printed out.

But if registering the two handlers is adjusted from enabling bearer
phase into inserting module stage, the warning message will be
eliminated. Due to this change, tipc_core_start_net() and
tipc_core_stop_net() can be deleted as well.

Reported-by: Wang Weidong <wangweidong1@huawei.com>
Cc: Jon Maloy <jon.maloy@ericsson.com>
Cc: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 net/tipc/bearer.c |    7 ++++++-
 net/tipc/config.c |    2 +-
 net/tipc/core.c   |   38 +++++++++-----------------------------
 net/tipc/core.h   |    1 -
 4 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index a38c899..574b861 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -610,8 +610,13 @@ static struct notifier_block notifier = {
 
 int tipc_bearer_setup(void)
 {
+	int err;
+
+	err = register_netdevice_notifier(&notifier);
+	if (err)
+		return err;
 	dev_add_pack(&tipc_packet_type);
-	return register_netdevice_notifier(&notifier);
+	return 0;
 }
 
 void tipc_bearer_cleanup(void)
diff --git a/net/tipc/config.c b/net/tipc/config.c
index c301a9a..e74eef2 100644
--- a/net/tipc/config.c
+++ b/net/tipc/config.c
@@ -181,7 +181,7 @@ static struct sk_buff *cfg_set_own_addr(void)
 	if (tipc_own_addr)
 		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
 						   " (cannot change node address once assigned)");
-	tipc_core_start_net(addr);
+	tipc_net_start(addr);
 	return tipc_cfg_reply_none();
 }
 
diff --git a/net/tipc/core.c b/net/tipc/core.c
index cfd9cc1..80c2064 100644
--- a/net/tipc/core.c
+++ b/net/tipc/core.c
@@ -77,37 +77,13 @@ struct sk_buff *tipc_buf_acquire(u32 size)
 }
 
 /**
- * tipc_core_stop_net - shut down TIPC networking sub-systems
- */
-static void tipc_core_stop_net(void)
-{
-	tipc_net_stop();
-	tipc_bearer_cleanup();
-}
-
-/**
- * start_net - start TIPC networking sub-systems
- */
-int tipc_core_start_net(unsigned long addr)
-{
-	int res;
-
-	tipc_net_start(addr);
-	res = tipc_bearer_setup();
-	if (res < 0)
-		goto err;
-	return res;
-
-err:
-	tipc_core_stop_net();
-	return res;
-}
-
-/**
  * tipc_core_stop - switch TIPC from SINGLE NODE to NOT RUNNING mode
  */
 static void tipc_core_stop(void)
 {
+	tipc_handler_stop();
+	tipc_net_stop();
+	tipc_bearer_cleanup();
 	tipc_netlink_stop();
 	tipc_cfg_stop();
 	tipc_subscr_stop();
@@ -158,7 +134,13 @@ static int tipc_core_start(void)
 	if (err)
 		goto out_cfg;
 
+	err = tipc_bearer_setup();
+	if (err)
+		goto out_bearer;
+
 	return 0;
+out_bearer:
+	tipc_cfg_stop();
 out_cfg:
 	tipc_subscr_stop();
 out_subscr:
@@ -203,8 +185,6 @@ static int __init tipc_init(void)
 
 static void __exit tipc_exit(void)
 {
-	tipc_handler_stop();
-	tipc_core_stop_net();
 	tipc_core_stop();
 	pr_info("Deactivated\n");
 }
diff --git a/net/tipc/core.h b/net/tipc/core.h
index 5569d96..4dfe137 100644
--- a/net/tipc/core.h
+++ b/net/tipc/core.h
@@ -90,7 +90,6 @@ extern int tipc_random __read_mostly;
 /*
  * Routines available to privileged subsystems
  */
-int tipc_core_start_net(unsigned long);
 int tipc_handler_start(void);
 void tipc_handler_stop(void);
 int tipc_netlink_start(void);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net 0/2] tipc: clean up components initialization code
  2014-02-20  3:32 [PATCH net 0/2] tipc: clean up components initialization code Ying Xue
  2014-02-20  3:32 ` [PATCH net 1/2] tipc: remove all enabled flags from all tipc components Ying Xue
  2014-02-20  3:32 ` [PATCH net 2/2] tipc: make bearer set up in module insertion stage Ying Xue
@ 2014-02-22  5:01 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2014-02-22  5:01 UTC (permalink / raw)
  To: ying.xue
  Cc: jon.maloy, Paul.Gortmaker, erik.hugne, netdev, tipc-discussion,
	wangweidong1

From: Ying Xue <ying.xue@windriver.com>
Date: Thu, 20 Feb 2014 11:32:48 +0800

> In this series, we will fix a regression issue involved by commit
> 6e967adf7(tipc: relocate common functions from media to bearer)
> But before the issue is fixed, we firstly adjust the process of
> components initialization so as to remove all enabled flags from
> necessary tipc components. Otherwise, without the change, we also
> have to add an extra enabled flag into bearer layer indicating
> whether bearer setup is finshed or not.
> 
> Ying Xue (2):
>   tipc: remove all enabled flags from all tipc components
>   tipc: make bearer set up in module insertion stage

Series applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-02-22  5:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-20  3:32 [PATCH net 0/2] tipc: clean up components initialization code Ying Xue
2014-02-20  3:32 ` [PATCH net 1/2] tipc: remove all enabled flags from all tipc components Ying Xue
2014-02-20  3:32 ` [PATCH net 2/2] tipc: make bearer set up in module insertion stage Ying Xue
2014-02-22  5:01 ` [PATCH net 0/2] tipc: clean up components initialization code David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).