]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
tipc: Fix problem with missing link in "tipc-config -l" output
authorAllan Stephens <Allan.Stephens@windriver.com>
Thu, 24 Feb 2011 18:20:20 +0000 (13:20 -0500)
committerPaul Gortmaker <paul.gortmaker@windriver.com>
Sun, 13 Mar 2011 20:35:16 +0000 (16:35 -0400)
Removes a race condition that could cause TIPC's internal counter
of the number of links it has to neighboring nodes to have the
incorrect value if two independent threads of control simultaneously
create new link endpoints connecting to two different nodes using two
different bearers. Such under counting would result in TIPC failing to
list the final link(s) in its response to a configuration request to
list all of the node's links. The counter is now updated atomically
to ensure that simultaneous increments do not interfere with each
other.

Thanks go to Peter Butler <pbutler@pt.com> for his assistance in
diagnosing and fixing this problem.

Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
net/tipc/net.c
net/tipc/net.h
net/tipc/node.c

index 9bacfd00b91eff6f2ac4dcb1c2fa0dbd479f9258..dd78d869829f8737d23261e8672b418854b8c018 100644 (file)
@@ -2,7 +2,7 @@
  * net/tipc/net.c: TIPC network routing code
  *
  * Copyright (c) 1995-2006, Ericsson AB
- * Copyright (c) 2005, Wind River Systems
+ * Copyright (c) 2005, 2010-2011, Wind River Systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -115,6 +115,7 @@ static int net_start(void)
        tipc_net.nodes = kcalloc(tipc_max_nodes + 1,
                                 sizeof(*tipc_net.nodes), GFP_ATOMIC);
        tipc_net.highest_node = 0;
+       atomic_set(&tipc_net.links, 0);
 
        return tipc_net.nodes ? 0 : -ENOMEM;
 }
index 4ae59ad048938e74f46f198dd41ce41b719562d6..aa431ef8b7bfd2ec783a7847aef86287593744f2 100644 (file)
@@ -2,7 +2,7 @@
  * net/tipc/net.h: Include file for TIPC network routing code
  *
  * Copyright (c) 1995-2006, Ericsson AB
- * Copyright (c) 2005, Wind River Systems
+ * Copyright (c) 2005, 2010-2011, Wind River Systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -49,7 +49,7 @@ struct tipc_node;
 struct network {
        struct tipc_node **nodes;
        u32 highest_node;
-       u32 links;
+       atomic_t links;
 };
 
 
index 713ab5d7c54f256b3f04992a4d2e7b8860f58a8f..a24fad32345eec280900edb67268c08b6adc9398 100644 (file)
@@ -233,7 +233,7 @@ struct tipc_node *tipc_node_attach_link(struct link *l_ptr)
 
                if (!n_ptr->links[bearer_id]) {
                        n_ptr->links[bearer_id] = l_ptr;
-                       tipc_net.links++;
+                       atomic_inc(&tipc_net.links);
                        n_ptr->link_cnt++;
                        return n_ptr;
                }
@@ -247,7 +247,7 @@ struct tipc_node *tipc_node_attach_link(struct link *l_ptr)
 void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr)
 {
        n_ptr->links[l_ptr->b_ptr->identity] = NULL;
-       tipc_net.links--;
+       atomic_dec(&tipc_net.links);
        n_ptr->link_cnt--;
 }
 
@@ -450,7 +450,8 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
 
        /* Get space for all unicast links + multicast link */
 
-       payload_size = TLV_SPACE(sizeof(link_info)) * (tipc_net.links + 1);
+       payload_size = TLV_SPACE(sizeof(link_info)) *
+               (atomic_read(&tipc_net.links) + 1);
        if (payload_size > 32768u) {
                read_unlock_bh(&tipc_net_lock);
                return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED