Whamcloud - gitweb
b=11694
[fs/lustre-release.git] / lustre / ptlrpc / connection.c
index 23acbd7..df65cf0 100644 (file)
@@ -103,6 +103,8 @@ struct ptlrpc_connection *ptlrpc_get_connection(lnet_process_id_t peer,
         atomic_set(&c->c_refcount, 1);
         c->c_peer = peer;
         c->c_self = self;
+        INIT_HLIST_NODE(&c->c_hash);
+        INIT_LIST_HEAD(&c->c_link);
         if (uuid != NULL)
                 obd_str2uuid(&c->c_remote_uuid, uuid->uuid);
 
@@ -114,12 +116,14 @@ struct ptlrpc_connection *ptlrpc_get_connection(lnet_process_id_t peer,
                 rc = lustre_hash_additem_unique(conn_hash_body, &peer, 
                                                 &c->c_hash);
                 if (rc != 0) {
+                        list_del(&c->c_link);
                         CERROR("Cannot add connection to conn_hash_body\n");
                         goto out_conn;
                 }
         }
-        
+
 out_conn:
+
         spin_unlock(&conn_lock);
 
         if (c2 == NULL && rc == 0)
@@ -127,15 +131,12 @@ out_conn:
 
         if (c != NULL) 
                 OBD_FREE(c, sizeof(*c));
-
-        c2 = rc != 0 ? NULL : c2;
         RETURN (c2);
 }
 
 int ptlrpc_put_connection(struct ptlrpc_connection *c)
 {
         int rc = 0;
-        lnet_process_id_t peer = c->c_peer;
         ENTRY;
 
         if (c == NULL) {
@@ -147,17 +148,19 @@ int ptlrpc_put_connection(struct ptlrpc_connection *c)
                 c, atomic_read(&c->c_refcount) - 1, 
                 libcfs_nid2str(c->c_peer.nid));
 
+        spin_lock(&conn_lock);
         LASSERT(!hlist_unhashed(&c->c_hash));
+        spin_unlock(&conn_lock);
 
         if (atomic_dec_return(&c->c_refcount) == 1) {
 
                 spin_lock(&conn_lock);
 
-                lustre_hash_delitem(conn_hash_body, &peer, &c->c_hash);
+                lustre_hash_delitem(conn_hash_body, &c->c_peer, &c->c_hash);
                 list_del(&c->c_link);
 
                 list_add(&c->c_link, &conn_unused_list);
-                rc = lustre_hash_additem_unique(conn_unused_hash_body, &peer, 
+                rc = lustre_hash_additem_unique(conn_unused_hash_body, &c->c_peer, 
                                                 &c->c_hash);
                 if (rc != 0) {
                         spin_unlock(&conn_lock);
@@ -191,7 +194,6 @@ struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *c)
 int ptlrpc_init_connection(void)
 {
         int rc = 0;
-
         CFS_INIT_LIST_HEAD(&conn_list);
         rc = lustre_hash_init(&conn_hash_body, "CONN_HASH", 
                               128, &conn_hash_operations);
@@ -205,7 +207,7 @@ int ptlrpc_init_connection(void)
                 GOTO(ret, rc);
 
         spin_lock_init(&conn_lock);
-ret :
+ret:
         if (rc) {
                 lustre_hash_exit(&conn_hash_body);
                 lustre_hash_exit(&conn_unused_hash_body);