Skip to content

Commit

Permalink
tipc: remove all enabled flags from all tipc components
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Erik Hugne <[email protected]>
Signed-off-by: Ying Xue <[email protected]>
Reviewed-by: Paul Gortmaker <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ying-xue authored and davem330 committed Feb 22, 2014
1 parent 7cce3b7 commit 9fe7ed4
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
71 changes: 50 additions & 21 deletions net/tipc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions net/tipc/name_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
8 changes: 0 additions & 8 deletions net/tipc/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ static struct genl_ops tipc_genl_ops[] = {
},
};

static int tipc_genl_family_registered;

int tipc_netlink_start(void)
{
int res;
Expand All @@ -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;
}
3 changes: 0 additions & 3 deletions net/tipc/ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 0 additions & 5 deletions net/tipc/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions net/tipc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions net/tipc/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -2027,8 +2025,6 @@ int tipc_socket_init(void)
proto_unregister(&tipc_proto);
goto out;
}

sockets_enabled = 1;
out:
return res;
}
Expand All @@ -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);
}

0 comments on commit 9fe7ed4

Please sign in to comment.